Exemplo n.º 1
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),
        )
Exemplo n.º 2
0
def test_random_device_placer_small_device():
    topo = cirq.TiltedSquareLattice(3, 3)
    qubits = sorted(topo.nodes_to_gridqubits().values())
    circuit = cirq.experiments.random_rotations_between_grid_interaction_layers_circuit(
        qubits, depth=8, two_qubit_op_factory=lambda a, b, _: cirq.SQRT_ISWAP(a, b)
    )
    qp = cg.RandomDevicePlacer()
    with pytest.raises(cg.CouldNotPlaceError):
        qp.place_circuit(
            circuit,
            problem_topology=topo,
            shared_rt_info=cg.SharedRuntimeInfo(run_id='1', device=cg.Foxtail),
            rs=np.random.RandomState(1),
        )
Exemplo n.º 3
0
def rt_config(request):
    if request.param == 'minimal':
        return cg.QuantumRuntimeConfiguration(
            processor_record=cg.SimulatedProcessorWithLocalDeviceRecord('rainbow')
        )

    elif request.param == 'full':
        return cg.QuantumRuntimeConfiguration(
            processor_record=cg.SimulatedProcessorWithLocalDeviceRecord('rainbow'),
            run_id='unit-test',
            random_seed=52,
            qubit_placer=cg.RandomDevicePlacer(),
            target_gateset=cirq.CZTargetGateset(),
        )

    raise ValueError(f"Unknown flavor {request}")  # coverage: ignore
Exemplo n.º 4
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
Exemplo n.º 5
0
def test_device_missing_metadata():
    class BadDevice(cirq.Device):
        pass

    topo = cirq.TiltedSquareLattice(3, 3)
    qubits = sorted(topo.nodes_to_gridqubits().values())
    circuit = cirq.experiments.random_rotations_between_grid_interaction_layers_circuit(
        qubits,
        depth=8,
        two_qubit_op_factory=lambda a, b, _: cirq.SQRT_ISWAP(a, b))
    qp = cg.RandomDevicePlacer()
    with pytest.raises(ValueError):
        qp.place_circuit(
            circuit,
            problem_topology=topo,
            shared_rt_info=cg.SharedRuntimeInfo(run_id='1',
                                                device=BadDevice()),
            rs=np.random.RandomState(1),
        )
Exemplo n.º 6
0
def test_random_device_placer_tilted_square_lattice():
    topo = cirq.TiltedSquareLattice(4, 2)
    qubits = sorted(topo.nodes_to_gridqubits().values())
    circuit = cirq.experiments.random_rotations_between_grid_interaction_layers_circuit(
        qubits, depth=8, two_qubit_op_factory=lambda a, b, _: cirq.SQRT_ISWAP(a, b)
    )
    assert not all(q in cg.Sycamore23.qubit_set() for q in circuit.all_qubits())

    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
Exemplo n.º 7
0
def test_random_device_placer_repr():
    cirq.testing.assert_equivalent_repr(cg.RandomDevicePlacer(),
                                        global_vals={'cirq_google': cg})