Esempio n. 1
0
def test_mirror_circuit_seeding(seed):
    nlayers = 5
    two_qubit_gate_prob = 0.4
    connectivity_graph = nx.complete_graph(5)
    circuit, _ = mirror_circuits.generate_mirror_circuit(nlayers,
                                                         two_qubit_gate_prob,
                                                         connectivity_graph,
                                                         seed=seed)
    for _ in range(5):
        circ, _ = mirror_circuits.generate_mirror_circuit(nlayers,
                                                          two_qubit_gate_prob,
                                                          connectivity_graph,
                                                          seed=seed)
        assert _equal(
            circuit,
            circ,
            require_qubit_equality=True,
            require_measurement_equality=True,
        )
Esempio n. 2
0
def test_mirror_circuits_conversions(return_type):
    nlayers = 5
    two_qubit_gate_prob = 0.4
    connectivity_graph = nx.complete_graph(5)
    circuit, _ = mirror_circuits.generate_mirror_circuit(
        nlayers,
        two_qubit_gate_prob,
        connectivity_graph,
        return_type=return_type,
    )
    assert return_type in circuit.__module__
Esempio n. 3
0
def test_two_qubit_gate(twoq_name_and_gate):
    twoq_name, twoq_gate = twoq_name_and_gate
    circuit, _ = mirror_circuits.generate_mirror_circuit(
        nlayers=2,
        two_qubit_gate_prob=1.0,
        connectivity_graph=nx.complete_graph(5),
        two_qubit_gate_name=twoq_name,
    )
    two_qubit_gates = {
        op.gate
        for op in circuit.all_operations() if len(op.qubits) == 2
    }
    assert two_qubit_gates == {twoq_gate}
Esempio n. 4
0
def test_deterministic_correct_bitstrings():
    """For a fixed seed, correct bitstrings should be deterministic."""
    expected_correct_bitstrings = (
        [[0, 0], [1, 1], [0, 0], [0, 1], [0, 0], [0, 0], [0, 0], [0, 0]] +
        [[0, 0], [1, 1], [1, 1], [0, 1], [0, 1], [0, 1], [1, 0], [0, 1]] +
        [[1, 1], [1, 0], [1, 0], [1, 0], [0, 0], [1, 1], [0, 0], [0, 1]])
    for j, expected in enumerate(expected_correct_bitstrings):
        _, bitstring = mirror_circuits.generate_mirror_circuit(
            nlayers=1,
            two_qubit_gate_prob=1.0,
            connectivity_graph=nx.complete_graph(2),
            seed=j,
        )
        assert bitstring == expected
Esempio n. 5
0
def test_generate_mirror_circuit(depth_twoqprob_graph):
    depth, xi, connectivity_graph = depth_twoqprob_graph
    n = connectivity_graph.number_of_nodes()
    circ, _ = mirror_circuits.generate_mirror_circuit(depth, xi,
                                                      connectivity_graph)
    assert isinstance(circ, cirq.Circuit)
    assert len(circ.all_qubits()) == n
    assert set(op.gate for op in circ.all_operations()).issubset(all_gates)
    circ.append(cirq.measure(*cirq.LineQubit.range(n)))
    result = (cirq.Simulator().run(
        circ, repetitions=1_000).multi_measurement_histogram(
            keys=circ.all_measurement_keys()))
    assert (len(result.keys()) == 1
            )  # checks that the circuit only outputs one bitstring
Esempio n. 6
0
def test_two_qubit_gate_unsupported():
    with pytest.raises(ValueError, match="Supported two-qubit gate names are"):
        mirror_circuits.generate_mirror_circuit(
            1, 1.0, nx.complete_graph(2), two_qubit_gate_name="bad_gate_name")