Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize processor sampler with the default device config key #6521

Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions cirq-google/cirq_google/cloud/quantum/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
from cirq_google.cloud.quantum_v1alpha1.types.engine import UpdateQuantumJobRequest
from cirq_google.cloud.quantum_v1alpha1.types.engine import UpdateQuantumProgramRequest
from cirq_google.cloud.quantum_v1alpha1.types.engine import UpdateQuantumReservationRequest
from cirq_google.cloud.quantum_v1alpha1.types.quantum import DeviceConfigKey
from cirq_google.cloud.quantum_v1alpha1.types.quantum import DeviceConfigSelector
from cirq_google.cloud.quantum_v1alpha1.types.quantum import ExecutionStatus
from cirq_google.cloud.quantum_v1alpha1.types.quantum import GcsLocation
from cirq_google.cloud.quantum_v1alpha1.types.quantum import InlineData
Expand All @@ -77,6 +77,7 @@
from cirq_google.cloud.quantum_v1alpha1.types.quantum import QuantumResult
from cirq_google.cloud.quantum_v1alpha1.types.quantum import QuantumTimeSlot
from cirq_google.cloud.quantum_v1alpha1.types.quantum import SchedulingConfig
from cirq_google.cloud.quantum_v1alpha1.types.quantum import DeviceConfigKey

__all__ = (
'QuantumEngineServiceClient',
Expand Down Expand Up @@ -121,7 +122,7 @@
'UpdateQuantumJobRequest',
'UpdateQuantumProgramRequest',
'UpdateQuantumReservationRequest',
'DeviceConfigKey',
'DeviceConfigSelector',
'ExecutionStatus',
'GcsLocation',
'InlineData',
Expand All @@ -137,4 +138,5 @@
'QuantumResult',
'QuantumTimeSlot',
'SchedulingConfig',
'DeviceConfigKey',
)
6 changes: 4 additions & 2 deletions cirq-google/cirq_google/cloud/quantum_v1alpha1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
from .types.engine import UpdateQuantumJobRequest
from .types.engine import UpdateQuantumProgramRequest
from .types.engine import UpdateQuantumReservationRequest
from .types.quantum import DeviceConfigKey
from .types.quantum import DeviceConfigSelector
from .types.quantum import ExecutionStatus
from .types.quantum import GcsLocation
from .types.quantum import InlineData
Expand All @@ -73,6 +73,7 @@
from .types.quantum import QuantumResult
from .types.quantum import QuantumTimeSlot
from .types.quantum import SchedulingConfig
from .types.quantum import DeviceConfigKey

__all__ = (
'QuantumEngineServiceAsyncClient',
Expand All @@ -85,7 +86,7 @@
'DeleteQuantumJobRequest',
'DeleteQuantumProgramRequest',
'DeleteQuantumReservationRequest',
'DeviceConfigKey',
'DeviceConfigSelector',
'ExecutionStatus',
'GcsLocation',
'GetQuantumCalibrationRequest',
Expand Down Expand Up @@ -133,4 +134,5 @@
'UpdateQuantumJobRequest',
'UpdateQuantumProgramRequest',
'UpdateQuantumReservationRequest',
'DeviceConfigKey',
)
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
)
from .quantum import (
DeviceConfigKey,
DeviceConfigSelector,
ExecutionStatus,
GcsLocation,
InlineData,
Expand Down Expand Up @@ -115,7 +116,7 @@
'UpdateQuantumJobRequest',
'UpdateQuantumProgramRequest',
'UpdateQuantumReservationRequest',
'DeviceConfigKey',
'DeviceConfigSelector',
'ExecutionStatus',
'GcsLocation',
'InlineData',
Expand All @@ -131,4 +132,5 @@
'QuantumResult',
'QuantumTimeSlot',
'SchedulingConfig',
'DeviceConfigKey',
)
26 changes: 23 additions & 3 deletions cirq-google/cirq_google/cloud/quantum_v1alpha1/types/quantum.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
'QuantumReservationBudget',
'QuantumTimeSlot',
'QuantumReservation',
'DeviceConfigSelector',
'DeviceConfigKey',
},
)

Expand Down Expand Up @@ -152,7 +154,7 @@ class QuantumJob(proto.Message):
run_context = proto.Field(proto.MESSAGE, number=11, message=any_pb2.Any)


class DeviceConfigKey(proto.Message):
class DeviceConfigSelector(proto.Message):
r"""-
Attributes:
run_name (str):
Expand Down Expand Up @@ -185,13 +187,13 @@ class ProcessorSelector(proto.Message):
-
processor (str):
-
device_config_key ((google.cloud.quantum_v1alpha1.types.DeviceConfigKey):
device_config_selector ((google.cloud.quantum_v1alpha1.types.DeviceConfigSelector):
-
"""

processor_names = proto.RepeatedField(proto.STRING, number=1)
processor = proto.Field(proto.STRING, number=2)
device_config_key = proto.Field(proto.MESSAGE, number=3, message=DeviceConfigKey)
device_config_selector = proto.Field(proto.MESSAGE, number=3, message=DeviceConfigSelector)

target_route = proto.Field(proto.STRING, number=1)
processor_selector = proto.Field(proto.MESSAGE, number=3, message=ProcessorSelector)
Expand Down Expand Up @@ -378,6 +380,9 @@ class QuantumProcessor(proto.Message):
Output only. -
activity_stats (google.cloud.quantum_v1alpha1.types.QuantumProcessor.ActivityStats):
-
default_device_config_key (google.cloud.quantum_v1alpha1.types.DeviceConfigKey):
-

"""

class Health(proto.Enum):
Expand Down Expand Up @@ -413,6 +418,7 @@ class ActivityStats(proto.Message):
current_calibration = proto.Field(proto.STRING, number=10)
active_time_slot = proto.Field(proto.MESSAGE, number=11, message='QuantumTimeSlot')
activity_stats = proto.Field(proto.MESSAGE, number=12, message=ActivityStats)
default_device_config_key = proto.Field(proto.MESSAGE, number=13, message='DeviceConfigKey')


class QuantumCalibration(proto.Message):
Expand Down Expand Up @@ -605,4 +611,18 @@ class QuantumReservation(proto.Message):
whitelisted_users = proto.RepeatedField(proto.STRING, number=5)


class DeviceConfigKey(proto.Message):
r"""-

Attributes:
run (str):
-
config_alias (str):
-
"""

run = proto.Field(proto.STRING, number=1)
config_alias = proto.Field(proto.STRING, number=2)


__all__ = tuple(sorted(__protobuf__.manifest))
4 changes: 2 additions & 2 deletions cirq-google/cirq_google/engine/engine_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ async def create_job_async(
scheduling_config=quantum.SchedulingConfig(
processor_selector=quantum.SchedulingConfig.ProcessorSelector(
processor=_processor_name_from_ids(project_id, processor_id),
device_config_key=quantum.DeviceConfigKey(
device_config_selector=quantum.DeviceConfigSelector(
run_name=run_name, config_alias=device_config_name
),
)
Expand Down Expand Up @@ -816,7 +816,7 @@ def run_job_over_stream(
scheduling_config=quantum.SchedulingConfig(
processor_selector=quantum.SchedulingConfig.ProcessorSelector(
processor=_processor_name_from_ids(project_id, processor_id),
device_config_key=quantum.DeviceConfigKey(
device_config_selector=quantum.DeviceConfigSelector(
run_name=run_name, config_alias=device_config_name
),
)
Expand Down
34 changes: 22 additions & 12 deletions cirq-google/cirq_google/engine/engine_client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,9 @@ def test_create_job(client_constructor):
priority=10,
processor_selector=quantum.SchedulingConfig.ProcessorSelector(
processor='projects/proj/processors/processor0',
device_config_key=quantum.DeviceConfigKey(run_name="", config_alias=""),
device_config_selector=quantum.DeviceConfigSelector(
run_name="", config_alias=""
),
),
),
description='A job',
Expand All @@ -396,7 +398,9 @@ def test_create_job(client_constructor):
priority=10,
processor_selector=quantum.SchedulingConfig.ProcessorSelector(
processor='projects/proj/processors/processor0',
device_config_key=quantum.DeviceConfigKey(run_name="", config_alias=""),
device_config_selector=quantum.DeviceConfigSelector(
run_name="", config_alias=""
),
),
),
description='A job',
Expand All @@ -417,7 +421,9 @@ def test_create_job(client_constructor):
priority=10,
processor_selector=quantum.SchedulingConfig.ProcessorSelector(
processor='projects/proj/processors/processor0',
device_config_key=quantum.DeviceConfigKey(run_name="", config_alias=""),
device_config_selector=quantum.DeviceConfigSelector(
run_name="", config_alias=""
),
),
),
labels=labels,
Expand All @@ -439,7 +445,9 @@ def test_create_job(client_constructor):
priority=10,
processor_selector=quantum.SchedulingConfig.ProcessorSelector(
processor='projects/proj/processors/processor0',
device_config_key=quantum.DeviceConfigKey(run_name="", config_alias=""),
device_config_selector=quantum.DeviceConfigSelector(
run_name="", config_alias=""
),
),
),
),
Expand All @@ -463,7 +471,9 @@ def test_create_job(client_constructor):
priority=10,
processor_selector=quantum.SchedulingConfig.ProcessorSelector(
processor='projects/proj/processors/processor0',
device_config_key=quantum.DeviceConfigKey(run_name="", config_alias=""),
device_config_selector=quantum.DeviceConfigSelector(
run_name="", config_alias=""
),
),
),
),
Expand Down Expand Up @@ -573,7 +583,7 @@ def test_create_job_with_run_name_and_device_config_name(
priority=10,
processor_selector=quantum.SchedulingConfig.ProcessorSelector(
processor='projects/proj/processors/processor0',
device_config_key=quantum.DeviceConfigKey(
device_config_selector=quantum.DeviceConfigSelector(
run_name=run_name, config_alias=device_config_name
),
),
Expand Down Expand Up @@ -615,7 +625,7 @@ def test_create_job_with_run_name_and_device_config_name(
priority=10,
processor_selector=quantum.SchedulingConfig.ProcessorSelector(
processor='projects/proj/processors/processor0',
device_config_key=quantum.DeviceConfigKey(),
device_config_selector=quantum.DeviceConfigSelector(),
),
),
description='A job',
Expand Down Expand Up @@ -649,7 +659,7 @@ def test_create_job_with_run_name_and_device_config_name(
priority=10,
processor_selector=quantum.SchedulingConfig.ProcessorSelector(
processor='projects/proj/processors/processor0',
device_config_key=quantum.DeviceConfigKey(),
device_config_selector=quantum.DeviceConfigSelector(),
),
),
description='A job',
Expand Down Expand Up @@ -680,7 +690,7 @@ def test_create_job_with_run_name_and_device_config_name(
priority=10,
processor_selector=quantum.SchedulingConfig.ProcessorSelector(
processor='projects/proj/processors/processor0',
device_config_key=quantum.DeviceConfigKey(),
device_config_selector=quantum.DeviceConfigSelector(),
),
),
description='A job',
Expand Down Expand Up @@ -717,7 +727,7 @@ def test_create_job_with_run_name_and_device_config_name(
priority=10,
processor_selector=quantum.SchedulingConfig.ProcessorSelector(
processor='projects/proj/processors/processor0',
device_config_key=quantum.DeviceConfigKey(),
device_config_selector=quantum.DeviceConfigSelector(),
),
),
description='A job',
Expand Down Expand Up @@ -752,7 +762,7 @@ def test_create_job_with_run_name_and_device_config_name(
priority=10,
processor_selector=quantum.SchedulingConfig.ProcessorSelector(
processor='projects/proj/processors/processor0',
device_config_key=quantum.DeviceConfigKey(),
device_config_selector=quantum.DeviceConfigSelector(),
),
),
),
Expand Down Expand Up @@ -784,7 +794,7 @@ def test_create_job_with_run_name_and_device_config_name(
scheduling_config=quantum.SchedulingConfig(
processor_selector=quantum.SchedulingConfig.ProcessorSelector(
processor='projects/proj/processors/processor0',
device_config_key=quantum.DeviceConfigKey(),
device_config_selector=quantum.DeviceConfigSelector(),
)
),
),
Expand Down
7 changes: 5 additions & 2 deletions cirq-google/cirq_google/engine/engine_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
from google.protobuf import any_pb2

import cirq
from cirq_google.cloud import quantum
from cirq_google.api import v2
from cirq_google.cloud import quantum
from cirq_google.devices import grid_device
from cirq_google.engine import abstract_processor, calibration, processor_sampler, util

Expand Down Expand Up @@ -110,8 +110,11 @@ def get_sampler(
Returns:
A `cirq.Sampler` instance (specifically a `engine_sampler.ProcessorSampler`
that will send circuits to the Quantum Computing Service
when sampled.1
when sampled.
"""
if processor := self._inner_processor():
senecameeks marked this conversation as resolved.
Show resolved Hide resolved
run_name = processor.default_device_config_key.run
device_config_name = processor.default_device_config_key.config_alias
return processor_sampler.ProcessorSampler(
processor=self, run_name=run_name, device_config_name=device_config_name
)
Expand Down
17 changes: 17 additions & 0 deletions cirq-google/cirq_google/engine/engine_processor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,23 @@ def test_get_missing_device():
_ = processor.get_device()


def test_get_sampler_initializes_default_device_configuration() -> None:
processor = cg.EngineProcessor(
'a',
'p',
EngineContext(),
_processor=quantum.QuantumProcessor(
senecameeks marked this conversation as resolved.
Show resolved Hide resolved
default_device_config_key=quantum.DeviceConfigKey(
run="run", config_alias="config_alias"
)
),
)
sampler = processor.get_sampler()

assert sampler.run_name == "run"
assert sampler.device_config_name == "config_alias"


@mock.patch('cirq_google.engine.engine_client.EngineClient.list_calibrations_async')
def test_list_calibrations(list_calibrations):
list_calibrations.return_value = [_CALIBRATION]
Expand Down
8 changes: 8 additions & 0 deletions cirq-google/cirq_google/engine/processor_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,11 @@ async def run_batch_async(
@property
def processor(self) -> 'cg.engine.AbstractProcessor':
return self._processor

@property
def run_name(self) -> str:
return self._run_name

@property
def device_config_name(self) -> str:
return self._device_config_name