Beispiel #1
0
def _aqt_rebase() -> BasePass:
    # CX replacement
    c_cx = Circuit(2)
    c_cx.Ry(0.5, 0)
    c_cx.add_gate(OpType.XXPhase, 0.5, [0, 1])
    c_cx.Ry(1.0, 0).Rx(-0.5, 0).Ry(0.5, 0)
    c_cx.Rx(-0.5, 1)

    # TK1 replacement
    c_tk1 = lambda a, b, c: Circuit(1).Rx(-0.5, 0).Ry(a, 0).Rx(b, 0).Ry(
        c, 0).Rx(0.5, 0)

    return RebaseCustom({OpType.XXPhase}, c_cx, {OpType.Rx, OpType.Ry}, c_tk1)
Beispiel #2
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
Beispiel #3
0
def random_sparse_ansatz(n_qubits, n_layers, p, rng_seed=None):
    seed(rng_seed)
    circ = Circuit(n_qubits)
    for q in range(n_qubits):
        if random() < p:
            circ.Ry(0.1 * randrange(20), q)
    for l in range(n_layers):
        for q in range(0, n_qubits - 1, 2):
            circ.CX(q, q + 1)
        for q in range(2 * (n_qubits // 2)):
            if random() < p:
                circ.Ry(0.1 * randrange(20), q)
        for q in range(1, n_qubits - 1, 2):
            circ.CX(q, q + 1)
        for q in range(2 * ((n_qubits - 1) // 2)):
            if random() < p:
                circ.Ry(0.1 * randrange(20), q + 1)
    circ.measure_all()
    return circ
Beispiel #4
0
def test_from_tket() -> None:
    c = Circuit(4, 2)
    c.X(0)
    c.H(1)
    c.S(1)
    c.CX(2, 0)
    c.Ry(0.5, 3)
    c.Measure(3, 0)
    c.Measure(1, 1)
    p = tk_to_pyquil(c)
    assert (
        len(p.instructions) == 8
    )  # 5 gates, 2 measures, and an initial declaration of classical register
def h2_1q_circ(theta: float) -> Circuit:
    circ = Circuit(1)
    circ.Ry(-2 / np.pi * -theta, 0)
    return circ