def test_hqp_equality():
    hqp = cg.HardcodedQubitPlacer(
        {cirq.LineTopology(5): dict(enumerate(cirq.LineQubit.range(5)))})
    hqp2 = cg.HardcodedQubitPlacer(
        {cirq.LineTopology(5): dict(enumerate(cirq.LineQubit.range(5)))})
    assert hqp == hqp2
    cirq.testing.assert_equivalent_repr(hqp, global_vals={'cirq_google': cg})

    hqp3 = cg.HardcodedQubitPlacer({
        cirq.LineTopology(5):
        dict(enumerate(cirq.LineQubit.range(1, 5 + 1)))
    })
    assert hqp != hqp3
def _get_quantum_executables():
    qubits = cirq.GridQubit.rect(1, 5, 5, 0)
    return [
        QuantumExecutable(
            spec=_get_example_spec(name=f'example-program-{i}'),
            problem_topology=cirq.LineTopology(5),
            circuit=_get_random_circuit(qubits, random_state=i),
            measurement=BitstringsMeasurement(n_repetitions=10),
        ) for i in range(3)
    ]
Exemple #3
0
def test_random_device_placer_bad_device():
    topo = cirq.LineTopology(8)
    qubits = cirq.LineQubit.range(8)
    circuit = cirq.testing.random_circuit(qubits, n_moments=8, op_density=1.0, random_state=52)
    qp = cg.RandomDevicePlacer()
    with pytest.raises(ValueError, match=r'.*shared_rt_info\.device.*'):
        qp.place_circuit(
            circuit,
            problem_topology=topo,
            shared_rt_info=cg.SharedRuntimeInfo(run_id='1'),
            rs=np.random.RandomState(1),
        )
def test_quantum_runtime_configuration_qubit_placer(rt_config):
    device = rt_config.processor_record.get_device()
    c, _ = rt_config.qubit_placer.place_circuit(
        cirq.Circuit(cirq.measure(cirq.LineQubit(0), cirq.LineQubit(1), key='z')),
        problem_topology=cirq.LineTopology(n_nodes=2),
        shared_rt_info=cg.SharedRuntimeInfo(run_id=rt_config.run_id, device=device),
        rs=np.random.RandomState(rt_config.random_seed),
    )
    if isinstance(rt_config.qubit_placer, cg.NaiveQubitPlacer):
        assert all(isinstance(q, cirq.LineQubit) for q in c.all_qubits())
    else:
        assert all(isinstance(q, cirq.GridQubit) for q in c.all_qubits())
def test_hqp_missing_placement():
    hqp = cg.HardcodedQubitPlacer(
        {cirq.LineTopology(5): dict(enumerate(cirq.LineQubit.range(5)))})

    circuit = cirq.testing.random_circuit(cirq.LineQubit.range(5),
                                          n_moments=2,
                                          op_density=1)
    shared_rt_info = cg.SharedRuntimeInfo(run_id='example')
    rs = np.random.RandomState(10)
    placed_c, _ = hqp.place_circuit(circuit,
                                    problem_topology=cirq.LineTopology(5),
                                    shared_rt_info=shared_rt_info,
                                    rs=rs)
    assert isinstance(placed_c, cirq.AbstractCircuit)

    circuit = cirq.testing.random_circuit(cirq.LineQubit.range(6),
                                          n_moments=2,
                                          op_density=1)
    with pytest.raises(cg.CouldNotPlaceError):
        hqp.place_circuit(circuit,
                          problem_topology=cirq.LineTopology(6),
                          shared_rt_info=shared_rt_info,
                          rs=rs)
Exemple #6
0
def test_random_device_placer_line():
    topo = cirq.LineTopology(8)
    qubits = cirq.LineQubit.range(8)
    circuit = cirq.testing.random_circuit(qubits, n_moments=8, op_density=1.0, random_state=52)

    qp = cg.RandomDevicePlacer()
    circuit2, mapping = qp.place_circuit(
        circuit,
        problem_topology=topo,
        shared_rt_info=cg.SharedRuntimeInfo(run_id='1', device=cg.Sycamore23),
        rs=np.random.RandomState(1),
    )
    assert circuit is not circuit2
    assert circuit != circuit2
    assert all(q in cg.Sycamore23.qubit_set() for q in circuit2.all_qubits())
    for k, v in mapping.items():
        assert k != v