def test_probability() -> None: state = qf.w_state(3) qf.print_state(state) prob = state.probabilities() qf.print_probabilities(state) assert np.isclose(prob.sum(), 1)
def test_inverse(): # Random circuit circ = qf.Circuit() circ += qf.TY(1 / 2, 0) circ += qf.H(0) circ += qf.TY(1 / 2, 1) circ += qf.TX(1.23123, 1) circ += qf.CNOT(0, 1) circ += qf.TX(-1 / 2, 1) circ += qf.TY(4.71572463191 / pi, 1) circ += qf.CNOT(0, 1) circ += qf.TX(-2 * 2.74973750579 / pi, 0) circ += qf.TX(-2 * 2.74973750579 / pi, 1) circ_inv = circ.H ket = circ.run() qf.print_state(ket) ket = circ_inv.run(ket) qf.print_state(ket) print(ket.qubits) print(true_ket().qubits) assert qf.states_close(ket, qf.zero_state(2)) ket = qf.zero_state(2) circ.extend(circ_inv) ket = circ.run(ket) assert qf.states_close(ket, qf.zero_state(2))
def test_probability(): state = qf.w_state(3) qf.print_state(state) prob = state.probabilities() qf.print_probabilities(state) assert qf.asarray(prob).sum() == ALMOST_ONE
def test_xgate(): prog = qf.Program() prog += qf.Call('X', params=[], qubits=[0]) ket = prog.run() assert ket.qubits == (0, ) # assert prog.cbits == [] qf.print_state(ket)
def test_defgate_param(): prog = qf.parse_quil(CP) # ket0 = prog.compile() # qf.print_state(ket0) ket1 = prog.run() qf.print_state(ket1) ket = qf.zero_state(2) ket = qf.X(0).run(ket) ket = qf.X(1).run(ket) ket = qf.CPHASE(1.0, 0, 1).run(ket) qf.print_state(ket) assert qf.states_close(ket1, ket)
def test_defgate(): prog = qf.parse_quil(HADAMARD) ket = prog.run() qf.print_state(ket) assert qf.states_close(ket, qf.ghz_state(1))
def test_print_state() -> None: f = io.StringIO() state = qf.w_state(5) qf.print_state(state, file=f)
def test_print_state(): f = io.StringIO() state = qf.w_state(5) qf.print_state(state, file=f) print(f.getvalue())
def main(): """CLI""" print(prepare_w4.__doc__) print('states amplitudes') ket = prepare_w4() qf.print_state(ket)