def test_get_state(): q = Qubits(2) q.set_state('11') assert np.allclose( q.get_state(), np.array([0, 0, 0, 1]) ) q.set_state('01') assert np.allclose( q.get_state(flatten=False), np.array([[0, 1], [0, 0]]) )
#print("HS {}".format(i)) q.gate(operator.S, target=targ) q.gate(operator.H, target=targ) #print("CNOT({}, {})".format(i, target)) q.gate(operator.X, control=targ, target=cnot_target) q.gate(operator.rz(2 * theta), target=cnot_target) for target in target_list[:-1]: targ = int(target) q.gate(operator.X, control=targ, target=cnot_target) if op[targ] == "X": q.gate(operator.H, target=targ) elif op[targ] == "Y": q.gate(operator.H, target=targ) q.gate(operator.Sdag, target=targ) if op[cnot_target] == "X": q.gate(operator.H, target=cnot_target) elif op[cnot_target] == "Y": q.gate(operator.H, target=cnot_target) q.gate(operator.Sdag, target=cnot_target) if __name__ == '__main__': from qupy.qubit import Qubits q_ins = Qubits(2) q_ins.gate(operator.H, target=1) q_ins.gate(operator.H, target=0) th = np.pi / 2 paulistr = "ZY" expm_pauli(q_ins, th, paulistr) print(q_ins.get_state())