Esempio n. 1
0
def test_estimates() -> None:
    """
    Check that the resource estimator gives reasonable results.
    """
    b = QsharpEstimatorBackend()
    c = Circuit(3)
    c.H(0)
    c.CX(0, 1)
    c.CCX(0, 1, 2)
    c.Rx(0.3, 1)
    c.Ry(0.4, 2)
    c.Rz(1.1, 0)
    c.S(1)
    c.SWAP(0, 2)
    c.T(1)
    c.X(0)
    c.Y(1)
    c.Z(2)
    pbox = PauliExpBox([Pauli.X, Pauli.I, Pauli.Z], 0.25)
    c.add_pauliexpbox(pbox, [2, 0, 1])
    b.compile_circuit(c, 0)
    resources = b.get_resources(c)
    assert resources["CNOT"] >= 1
    assert resources["QubitClifford"] >= 1
    assert resources["R"] >= 1
    assert resources["T"] >= 1
    assert resources["Depth"] >= 1
    assert resources["Width"] == 3
    assert resources["BorrowedWidth"] == 0
Esempio n. 2
0
def test_handles() -> None:
    b = QsharpToffoliSimulatorBackend()
    c = Circuit(4)
    c.CX(0, 1)
    c.CCX(0, 1, 2)
    c.add_gate(OpType.CnX, [0, 1, 2, 3])
    c.add_gate(OpType.noop, [2])
    c.X(3)
    c.SWAP(1, 2)
    c.measure_all()
    b.compile_circuit(c)
    shots = b.get_shots(c, n_shots=2)
    assert all(shots[0] == shots[1])
Esempio n. 3
0
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
Esempio n. 4
0
def test_default_pass() -> None:
    b = QsharpToffoliSimulatorBackend()
    for ol in range(3):
        comp_pass = b.default_compilation_pass(ol)
        c = Circuit(4, 4)
        c.CX(0, 1)
        c.CCX(0, 1, 2)
        c.add_gate(OpType.CnX, [0, 1, 2, 3])
        c.add_gate(OpType.noop, [2])
        c.X(3)
        c.SWAP(1, 2)
        c.measure_all()
        comp_pass.apply(c)
        for pred in b.required_predicates:
            assert pred.verify(c)
Esempio n. 5
0
def test_compile() -> None:
    """
    Compile a circuit containing SWAPs and noops down to CnX's
    """
    b = QsharpToffoliSimulatorBackend()
    c = Circuit(4)
    c.CX(0, 1)
    c.CCX(0, 1, 2)
    c.add_gate(OpType.CnX, [0, 1, 2, 3])
    c.add_gate(OpType.noop, [2])
    c.X(3)
    c.SWAP(1, 2)
    c.measure_all()
    b.compile_circuit(c)
    shots = b.get_shots(c, 2)
    assert all(shots[0] == shots[1])