def test_swaps_basisorder() -> None: # Check that implicit swaps can be corrected irrespective of BasisOrder b = AerStateBackend() c = Circuit(4) c.X(0) c.CX(0, 1) c.CX(1, 0) c.CX(1, 3) c.CX(3, 1) c.X(2) cu = CompilationUnit(c) CliffordSimp(True).apply(cu) c1 = cu.circuit assert c1.n_gates_of_type(OpType.CX) == 2 b.compile_circuit(c) b.compile_circuit(c1) handles = b.process_circuits([c, c1]) s_ilo = b.get_state(c1, basis=BasisOrder.ilo) correct_ilo = b.get_state(c, basis=BasisOrder.ilo) assert np.allclose(s_ilo, correct_ilo) s_dlo = b.get_state(c1, basis=BasisOrder.dlo) correct_dlo = b.get_state(c, basis=BasisOrder.dlo) assert np.allclose(s_dlo, correct_dlo) qbs = c.qubits for result in b.get_results(handles): assert (result.get_state([qbs[1], qbs[2], qbs[3], qbs[0]]).real.tolist().index(1.0) == 6) assert (result.get_state([qbs[2], qbs[1], qbs[0], qbs[3]]).real.tolist().index(1.0) == 9) assert (result.get_state([qbs[2], qbs[3], qbs[0], qbs[1]]).real.tolist().index(1.0) == 12) bu = AerUnitaryBackend() u_ilo = bu.get_unitary(c1, basis=BasisOrder.ilo) correct_ilo = bu.get_unitary(c, basis=BasisOrder.ilo) assert np.allclose(u_ilo, correct_ilo) u_dlo = bu.get_unitary(c1, basis=BasisOrder.dlo) correct_dlo = bu.get_unitary(c, basis=BasisOrder.dlo) assert np.allclose(u_dlo, correct_dlo)
def test_statevector() -> None: b = AerStateBackend() circ = Circuit(3, name="test") circ.H(2) circ.X(0) circ.H(0) circ.CX(0, 1) circ.CZ(1, 2) circ.Sdg(0) circ.Tdg(1) circ.Z(1) circ.T(2) circ.Rx(0.3333, 1) circ.Rz(0.3333, 1) zxcirc = tk_to_pyzx(circ) assert zxcirc.name == circ.name b.compile_circuit(circ) state = b.get_state(circ) circ2 = pyzx_to_tk(zxcirc) assert circ2.name == circ.name b.compile_circuit(circ2) state2 = b.get_state(circ2) assert np.allclose(state, state2, atol=1e-10)