def test_aer_expanded_gates() -> None:
    c = Circuit(3).CX(0, 1)
    c.add_gate(OpType.ZZPhase, 0.1, [0, 1])
    c.add_gate(OpType.CY, [0, 1])
    c.add_gate(OpType.CCX, [0, 1, 2])

    backend = AerBackend()
    assert backend.valid_circuit(c)
def test_process_characterisation_no_noise_model() -> None:
    my_noise_model = NoiseModel()
    back = AerBackend(my_noise_model)
    assert back.characterisation is None

    c = Circuit(4).CX(0, 1).H(2).CX(2, 1).H(3).CX(0, 3).H(1).X(0)
    back.compile_circuit(c)
    assert back.valid_circuit(c)
def test_process_characterisation_incomplete_noise_model() -> None:

    my_noise_model = NoiseModel()

    my_noise_model.add_quantum_error(depolarizing_error(0.6, 2), ["cx"],
                                     [0, 1])
    my_noise_model.add_quantum_error(depolarizing_error(0.5, 1), ["u3"], [1])
    my_noise_model.add_quantum_error(depolarizing_error(0.1, 1), ["u3"], [3])
    my_noise_model.add_quantum_error(pauli_error([("X", 0.35), ("Z", 0.65)]),
                                     ["u2"], [0])
    my_noise_model.add_quantum_error(pauli_error([("X", 0.35), ("Y", 0.65)]),
                                     ["u1"], [2])

    back = AerBackend(my_noise_model)
    char = cast(Dict[str, Any], back.characterisation)

    c = Circuit(4).CX(0, 1).H(2).CX(2, 1).H(3).CX(0, 3).H(1).X(0).measure_all()
    back.compile_circuit(c)
    assert back.valid_circuit(c)

    dev = Device(
        char.get("NodeErrors", {}),
        char.get("EdgeErrors", {}),
        char.get("Architecture", Architecture([])),
    )
    nodes = dev.nodes
    assert set(dev.architecture.coupling) == set([
        (nodes[0], nodes[1]),
        (nodes[0], nodes[2]),
        (nodes[0], nodes[3]),
        (nodes[1], nodes[2]),
        (nodes[1], nodes[3]),
        (nodes[2], nodes[0]),
        (nodes[2], nodes[1]),
        (nodes[2], nodes[3]),
        (nodes[3], nodes[0]),
        (nodes[3], nodes[1]),
        (nodes[3], nodes[2]),
    ])
def test_circuit_compilation_complete_noise_model() -> None:
    my_noise_model = NoiseModel()
    my_noise_model.add_quantum_error(depolarizing_error(0.6, 2), ["cx"],
                                     [0, 1])
    my_noise_model.add_quantum_error(depolarizing_error(0.6, 2), ["cx"],
                                     [0, 2])
    my_noise_model.add_quantum_error(depolarizing_error(0.6, 2), ["cx"],
                                     [0, 3])
    my_noise_model.add_quantum_error(depolarizing_error(0.6, 2), ["cx"],
                                     [1, 2])
    my_noise_model.add_quantum_error(depolarizing_error(0.6, 2), ["cx"],
                                     [1, 3])
    my_noise_model.add_quantum_error(depolarizing_error(0.6, 2), ["cx"],
                                     [2, 3])
    my_noise_model.add_quantum_error(depolarizing_error(0.5, 1), ["u3"], [0])
    my_noise_model.add_quantum_error(depolarizing_error(0.5, 1), ["u3"], [1])
    my_noise_model.add_quantum_error(depolarizing_error(0.5, 1), ["u3"], [2])
    my_noise_model.add_quantum_error(depolarizing_error(0.5, 1), ["u3"], [3])

    back = AerBackend(my_noise_model)

    c = Circuit(4).CX(0, 1).H(2).CX(2, 1).H(3).CX(0, 3).H(1).X(0).measure_all()
    back.compile_circuit(c)
    assert back.valid_circuit(c)
Beispiel #5
0
# The preconditions and postconditions of all the elementary predicates are documented in their string representations:

PauliSimp()

# ## Backends and default passes

# A `pytket` `Backend` may have a default compilation pass, which will guarantee that the circuit can run on it. This is given by the `default_compilation_pass` property. For example, the default pass for Qiskit's `AerBackend` just converts all gates to U1, U2, U3 and CX:

from pytket.extensions.qiskit import AerBackend

b = AerBackend()
b.default_compilation_pass

# To compile a circuit using the default pass of a `Backend` we can simply use the `compile_circuit()` method:

circ = Circuit(2).X(0).Y(1).CRz(0.5, 1, 0)
circ1 = circ.copy()
b.compile_circuit(circ1)
print(tk_to_qiskit(circ1))

# Every `Backend` will have a certain set of requirements that must be met by any circuit in order to run. These are exposed via the `required_predicates` property:

b.required_predicates

# We can test whether a given circuit satisfies these requirements using the `valid_circuit()` method:

b.valid_circuit(circ)

b.valid_circuit(circ1)