def test_ibmq_emulator() -> None: b_emu = IBMQEmulatorBackend("ibmq_santiago", hub="ibm-q", group="open", project="main") assert b_emu._noise_model is not None b_ibm = b_emu._ibmq b_aer = AerBackend() for ol in range(3): comp_pass = b_emu.default_compilation_pass(ol) c = Circuit(3, 3) c.H(0) c.CX(0, 1) c.CSWAP(1, 0, 2) c.ZZPhase(0.84, 2, 0) c_cop = c.copy() comp_pass.apply(c_cop) c.measure_all() for bac in (b_emu, b_ibm): assert all(pred.verify(c_cop) for pred in bac.required_predicates) c_cop_2 = c.copy() b_aer.compile_circuit(c_cop_2, ol) if ol == 0: assert not all( pred.verify(c_cop_2) for pred in b_emu.required_predicates) circ = Circuit(2, 2).H(0).CX(0, 1).measure_all() b_emu.compile_circuit(circ) b_noi = AerBackend(noise_model=b_emu._noise_model) emu_shots = b_emu.get_shots(circ, 10, seed=10) aer_shots = b_noi.get_shots(circ, 10, seed=10) assert np.array_equal(emu_shots, aer_shots)
def test_honeywell() -> None: token = os.getenv("HQS_AUTH") backend = HoneywellBackend( device_name="HQS-LT-1.0-APIVAL", machine_debug=skip_remote_tests ) c = Circuit(4, 4, "test 1") c.H(0) c.CX(0, 1) c.Rz(0.3, 2) c.CSWAP(0, 1, 2) c.CRz(0.4, 2, 3) c.CY(1, 3) c.ZZPhase(0.1, 2, 0) c.Tdg(3) c.measure_all() backend.compile_circuit(c) n_shots = 4 handle = backend.process_circuits([c], n_shots)[0] correct_shots = np.zeros((4, 4)) correct_counts = {(0, 0, 0, 0): 4} res = backend.get_result(handle, timeout=49) shots = res.get_shots() counts = res.get_counts() assert backend.circuit_status(handle).status is StatusEnum.COMPLETED assert np.all(shots == correct_shots) assert counts == correct_counts newshots = backend.get_shots(c, 4, timeout=49) assert np.all(newshots == correct_shots) newcounts = backend.get_counts(c, 4) assert newcounts == correct_counts if token is None: assert backend.device is None
def test_default_pass() -> None: b = ProjectQBackend() for ol in range(3): comp_pass = b.default_compilation_pass(ol) c = Circuit(3, 3) c.H(0) c.CX(0, 1) c.CSWAP(1, 0, 2) c.ZZPhase(0.84, 2, 0) comp_pass.apply(c) for pred in b.required_predicates: assert pred.verify(c)
def test_default_pass() -> None: b = AQTBackend("invalid", device_name="sim/noise-model-1") for ol in range(3): comp_pass = b.default_compilation_pass(ol) c = Circuit(3, 3) c.H(0) c.CX(0, 1) c.CSWAP(1, 0, 2) c.ZZPhase(0.84, 2, 0) c.measure_all() comp_pass.apply(c) for pred in b.required_predicates: assert pred.verify(c)
def test_default_pass() -> None: b = HoneywellBackend(device_name="HQS-LT-1.0-APIVAL") for ol in range(3): comp_pass = b.default_compilation_pass(ol) c = Circuit(3, 3) c.H(0) c.CX(0, 1) c.CSWAP(1, 0, 2) c.ZZPhase(0.84, 2, 0) c.measure_all() comp_pass.apply(c) for pred in b.required_predicates: assert pred.verify(c)
def test_default_pass() -> None: b = QsharpSimulatorBackend() for ol in range(3): comp_pass = b.default_compilation_pass(ol) c = Circuit(4, 4) c.H(0) c.CX(0, 1) c.CSWAP(1, 0, 2) c.ZZPhase(0.84, 2, 0) c.measure_all() comp_pass.apply(c) for pred in b.required_predicates: assert pred.verify(c)
def test_default_pass() -> None: b = IBMQBackend("ibmq_santiago", hub="ibm-q", group="open", project="main") for ol in range(3): comp_pass = b.default_compilation_pass(ol) c = Circuit(3, 3) c.H(0) c.CX(0, 1) c.CSWAP(1, 0, 2) c.ZZPhase(0.84, 2, 0) c.measure_all() comp_pass.apply(c) for pred in b.required_predicates: assert pred.verify(c)
def test_default_pass() -> None: b = ForestBackend("9q-square") for ol in range(3): comp_pass = b.default_compilation_pass(ol) c = Circuit(3, 3) c.H(0) c.CX(0, 1) c.CSWAP(1, 0, 2) c.ZZPhase(0.84, 2, 0) c.measure_all() comp_pass.apply(c) for pred in b.required_predicates: assert pred.verify(c)
def test_big_circuit_ionq() -> None: token = cast(str, os.getenv("IONQ_AUTH")) backend = IonQBackend(api_key=token, device_name="simulator", label="test 2") circ = Circuit(4) circ.X(0).Y(0).Z(0).H(1).S(1).Sdg(1).H(1).T(2).Tdg(2).V(3).Vdg(3) circ.SWAP(0, 1) circ.CX(3, 2) circ.ZZPhase(1.2, 0, 1) circ.measure_all() counts = backend.get_counts(circ, n_shots=100) assert counts[(0, 0, 0, 0)] == 100
def test_convert() -> None: circ = Circuit(4, 4) circ.H(0).CX(0, 1) circ.add_gate(OpType.noop, [1]) circ.CRz(0.5, 1, 2) circ.add_barrier([2]) circ.ZZPhase(0.3, 2, 3).CX(3, 0).Tdg(1) circ.Measure(0, 0) circ.Measure(1, 2) circ.Measure(2, 3) circ.Measure(3, 1) circ_aqt = tk_to_aqt(circ) assert json.loads(circ_aqt[1]) == [0, 3, 1, 2] assert all(gate[0] in ["X", "Y", "MS"] for gate in circ_aqt[0])
def test_convert() -> None: circ = Circuit(4) circ.H(0).CX(0, 1) circ.add_gate(OpType.noop, [1]) circ.CRz(0.5, 1, 2) circ.add_barrier([2]) circ.ZZPhase(0.3, 2, 3).CX(3, 0).Tdg(1) circ.measure_all() RebaseHQS().apply(circ) circ_hqs = circuit_to_qasm_str(circ, header="hqslib1") qasm_str = circ_hqs.split("\n")[6:-1] test = True for com in qasm_str: test &= any( com.startswith(gate) for gate in ("rz", "U1q", "ZZ", "measure", "barrier")) assert test
def test_aer_default_pass() -> None: with open(os.path.join(sys.path[0], "ibmqx2_properties.pickle"), "rb") as f: properties = pickle.load(f) noise_model = NoiseModel.from_backend(properties) for nm in [None, noise_model]: b = AerBackend(nm) for ol in range(3): comp_pass = b.default_compilation_pass(ol) c = Circuit(3, 3) c.H(0) c.CX(0, 1) c.CSWAP(1, 0, 2) c.ZZPhase(0.84, 2, 0) c.add_gate(OpType.TK1, [0.2, 0.3, 0.4], [0]) comp_pass.apply(c) c.measure_all() for pred in b.required_predicates: assert pred.verify(c)
def test_aqt() -> None: # Run a circuit on the noisy simulator. token = cast(str, os.getenv("AQT_AUTH")) b = AQTBackend(token, device_name="sim/noise-model-1", label="test 1") c = Circuit(4, 4) c.H(0) c.CX(0, 1) c.Rz(0.3, 2) c.CSWAP(0, 1, 2) c.CRz(0.4, 2, 3) c.CY(1, 3) c.add_barrier([0, 1]) c.ZZPhase(0.1, 2, 0) c.Tdg(3) c.measure_all() b.compile_circuit(c) n_shots = 10 shots = b.get_shots(c, n_shots, seed=1, timeout=30) counts = b.get_counts(c, n_shots) assert len(shots) == n_shots assert sum(counts.values()) == n_shots