def test_join_states() -> None: q0 = qf.zero_state([0]) q1 = qf.zero_state([1, 2]) q2 = qf.join_states(q0, q1) assert q2.qubit_nb == 3 assert q2.tensor[0, 0, 0] == 1 q3 = qf.zero_state([3, 4, 5]) q3 = qf.X(4).run(q3) q4 = qf.join_states(qf.join_states(q0, q1), q3) assert q4.qubit_nb == 6 assert q4.tensor[0, 0, 0, 0, 1, 0] == 1
def test_swap_test(): import examples.swaptest as ex ket0 = qf.zero_state([0]) ket1 = qf.random_state([1]) ket2 = qf.random_state([2]) ket = qf.join_states(ket0, ket1) ket = qf.join_states(ket, ket2) fid = qf.state_fidelity(ket1, ket2.relabel([1])) st_fid = ex.swap_test(ket, 0, 1, 2) assert qf.asarray(fid) / qf.asarray(st_fid) == ALMOST_ONE
def test_swap_test(): import examples.swaptest as ex ket0 = qf.zero_state([0]) ket1 = qf.random_state([1]) ket2 = qf.random_state([2]) ket = qf.join_states(ket0, ket1) ket = qf.join_states(ket, ket2) fid = qf.state_fidelity(ket1, ket2.on(1)) st_fid = ex.swap_test(ket, 0, 1, 2) assert np.isclose(fid, st_fid)
def test_join_states(): q0 = qf.zero_state([0]) q1 = qf.zero_state([1, 2]) q2 = qf.join_states(q0, q1) assert q2.qubit_nb == 3 assert q2.vec.asarray()[0, 0, 0] == ALMOST_ONE q3 = qf.zero_state([3, 4, 5]) q3 = qf.X(4).run(q3) print(q0) print(q1) print(q3) q4 = qf.join_states(qf.join_states(q0, q1), q3) assert q4.qubit_nb == 6 assert q4.vec.asarray()[0, 0, 0, 0, 1, 0] == ALMOST_ONE
def main(): """CLI""" print(swap_test.__doc__) print("Randomly generating two 1-qubit states...") ket0 = qf.zero_state([0]) ket1 = qf.random_state([1]) ket2 = qf.random_state([2]) ket = qf.join_states(ket0, ket1) ket = qf.join_states(ket, ket2) fid = qf.state_fidelity(ket1, ket2.on(1)) st_fid = swap_test(ket, 0, 1, 2) print("Fidelity: ", fid) print("Fidelity from swap test:", st_fid)
def main(): """CLI""" print(swap_test.__doc__) print('Randomly generating two 1-qubit states...') ket0 = qf.zero_state([0]) ket1 = qf.random_state([1]) ket2 = qf.random_state([2]) ket = qf.join_states(ket0, ket1, ket2) fid = qf.state_fidelity(ket1, ket2.relabel([1])) st_fid = swap_test(ket, 0, 1, 2) print('Fidelity: ', qf.asarray(fid)) print('Fidelity from swap test:', qf.asarray(st_fid))