예제 #1
0
    def test_apply_iswap(self, tol, input, shots):
        """Tests that applying the iSWAP gate yields the expected output."""
        device = SimulatorDevice(2, shots=shots)

        iswap_mat = np.array([[1, 0, 0, 0], [0, 0, 1j, 0], [0, 1j, 0, 0],
                              [0, 0, 0, 1]])

        expected = iswap_mat @ input

        device.reset()
        device._initial_state = np.array(input, dtype=np.complex64)
        device.apply([ops.ISWAP(wires=[0, 1])])

        assert np.allclose(device.state, expected, **tol)
예제 #2
0
def circuit(seed=42, return_probs=False):
    np.random.seed(seed)
    gate_idx = generate_single_qubit_gate_list()

    # m full cycles - single-qubit gates & two-qubit gate
    for i, gs in enumerate(gate_sequence):
        for w in range(wires):
            single_qubit_gates[gate_idx[i][w]](wires=w)

        for qb_1, qb_2 in gate_order[gs]:
            ops.ISWAP(wires=(qb_1, qb_2))
            ops.CPhase(-np.pi/6, wires=(qb_1, qb_2))

    # one half-cycle - single-qubit gates only
    for w in range(wires):
        single_qubit_gates[gate_idx[-1][w]](wires=w)

    if return_probs:
        return qml.probs(wires=range(wires))
    else:
        return [qml.sample(qml.PauliZ(i)) for i in range(wires)]