Skip to content

Commit

Permalink
Add new processor selector parameters to processor run methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Jose Urruticoechea committed Aug 28, 2023
1 parent f78a537 commit 89cf4d7
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 9 deletions.
38 changes: 36 additions & 2 deletions cirq-google/cirq_google/engine/abstract_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ async def run_async(
program_labels: Optional[Dict[str, str]] = None,
job_description: Optional[str] = None,
job_labels: Optional[Dict[str, str]] = None,
run_name: str = "",
device_config_name: str = "",
) -> cirq.Result:
"""Runs the supplied Circuit on this processor.
Expand All @@ -85,6 +87,12 @@ async def run_async(
program_labels: Optional set of labels to set on the program.
job_description: An optional description to set on the job.
job_labels: Optional set of labels to set on the job.
run_name: A unique identifier representing an automation run for the
processor. An Automation Run contains a collection of device
configurations for the processor.
device_config_name: An identifier used to select the processor configuration
utilized to run the job. A configuration identifies the set of
available qubits, couplers, and supported gates in the processor.
Returns:
A single Result for this run.
"""
Expand Down Expand Up @@ -115,6 +123,8 @@ async def run_sweep_async(
program_labels: Optional[Dict[str, str]] = None,
job_description: Optional[str] = None,
job_labels: Optional[Dict[str, str]] = None,
run_name: str = "",
device_config_name: str = "",
) -> 'abstract_job.AbstractJob':
"""Runs the supplied Circuit on this processor.
Expand All @@ -138,6 +148,12 @@ async def run_sweep_async(
program_labels: Optional set of labels to set on the program.
job_description: An optional description to set on the job.
job_labels: Optional set of labels to set on the job.
run_name: A unique identifier representing an automation run for the
processor. An Automation Run contains a collection of device
configurations for the processor.
device_config_name: An identifier used to select the processor configuration
utilized to run the job. A configuration identifies the set of
available qubits, couplers, and supported gates in the processor.
Returns:
An AbstractJob. If this is iterated over it returns a list of
`cirq.Result`, one for each parameter sweep.
Expand All @@ -157,6 +173,8 @@ async def run_batch_async(
program_labels: Optional[Dict[str, str]] = None,
job_description: Optional[str] = None,
job_labels: Optional[Dict[str, str]] = None,
run_name: str = "",
device_config_name: str = "",
) -> 'abstract_job.AbstractJob':
"""Runs the supplied Circuits on this processor.
Expand Down Expand Up @@ -188,6 +206,12 @@ async def run_batch_async(
program_labels: Optional set of labels to set on the program.
job_description: An optional description to set on the job.
job_labels: Optional set of labels to set on the job.
run_name: A unique identifier representing an automation run for the
processor. An Automation Run contains a collection of device
configurations for the processor.
device_config_name: An identifier used to select the processor configuration
utilized to run the job. A configuration identifies the set of
available qubits, couplers, and supported gates in the processor.
Returns:
An AbstractJob. If this is iterated over it returns a list of
`cirq.Result`. All Results for the first circuit are listed
Expand Down Expand Up @@ -244,8 +268,18 @@ async def run_calibration_async(
run_calibration = duet.sync(run_calibration_async)

@abc.abstractmethod
def get_sampler(self) -> 'cg.ProcessorSampler':
"""Returns a sampler backed by the processor."""
def get_sampler(
self, run_name: str = "", device_config_name: str = ""
) -> 'cg.ProcessorSampler':
"""Returns a sampler backed by the processor.
Args:
run_name: A unique identifier representing an automation run for the
processor. An Automation Run contains a collection of device
configurations for the processor.
device_config_name: An identifier used to select the processor configuration
utilized to run the job. A configuration identifies the set of
available qubits, couplers, and supported gates in the processor.
"""

@abc.abstractmethod
def engine(self) -> Optional['abstract_engine.AbstractEngine']:
Expand Down
52 changes: 47 additions & 5 deletions cirq-google/cirq_google/engine/engine_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,25 @@ def engine(self) -> 'engine_base.Engine':

return engine_base.Engine(self.project_id, context=self.context)

def get_sampler(self) -> 'cg.engine.ProcessorSampler':
def get_sampler(
self, run_name: str = "", device_config_name=""
) -> 'cg.engine.ProcessorSampler':
"""Returns a sampler backed by the engine.
Args:
run_name: A unique identifier representing an automation run for the
processor. An Automation Run contains a collection of device
configurations for the processor.
device_config_name: An identifier used to select the processor configuration
utilized to run the job. A configuration identifies the set of
available qubits, couplers, and supported gates in the processor.
Returns:
A `cirq.Sampler` instance (specifically a `engine_sampler.ProcessorSampler`
that will send circuits to the Quantum Computing Service
when sampled.1
"""
return processor_sampler.ProcessorSampler(processor=self)
return processor_sampler.ProcessorSampler(
processor=self, run_name=run_name, device_config_name=device_config_name
)

async def run_batch_async(
self,
Expand All @@ -123,6 +133,8 @@ async def run_batch_async(
program_labels: Optional[Dict[str, str]] = None,
job_description: Optional[str] = None,
job_labels: Optional[Dict[str, str]] = None,
run_name: str = "",
device_config_name: str = "",
) -> 'abstract_job.AbstractJob':
"""Runs the supplied Circuits on this processor.
Expand Down Expand Up @@ -154,23 +166,37 @@ async def run_batch_async(
program_labels: Optional set of labels to set on the program.
job_description: An optional description to set on the job.
job_labels: Optional set of labels to set on the job.
run_name: A unique identifier representing an automation run for the
processor. An Automation Run contains a collection of device
configurations for the processor.
device_config_name: An identifier used to select the processor configuration
utilized to run the job. A configuration identifies the set of
available qubits, couplers, and supported gates in the processor.
Returns:
An `abstract_job.AbstractJob`. If this is iterated over it returns
a list of `cirq.Result`. All Results for the first circuit are listed
first, then the Results for the second, etc. The Results
for a circuit are listed in the order imposed by the associated
parameter sweep.
Raises:
ValueError: If neither `processor_id` or `processor_ids` are set.
ValueError: If only one of `run_name` and `device_config_name` are specified.
ValueError: If `processor_ids` has more than one processor id.
ValueError: If either `run_name` and `device_config_name` are set but
`processor_id` is empty.
"""
return await self.engine().run_batch_async(
programs=programs,
processor_ids=[self.processor_id],
program_id=program_id,
params_list=list(params_list) if params_list is not None else None,
repetitions=repetitions,
program_description=program_description,
program_labels=program_labels,
job_description=job_description,
job_labels=job_labels,
processor_id=self.processor_id,
run_name=run_name,
device_config_name=device_config_name,
)

async def run_calibration_async(
Expand Down Expand Up @@ -237,6 +263,8 @@ async def run_sweep_async(
program_labels: Optional[Dict[str, str]] = None,
job_description: Optional[str] = None,
job_labels: Optional[Dict[str, str]] = None,
run_name: str = "",
device_config_name: str = "",
) -> 'abstract_job.AbstractJob':
"""Runs the supplied Circuit on this processor.
Expand All @@ -261,12 +289,23 @@ async def run_sweep_async(
program_labels: Optional set of labels to set on the program.
job_description: An optional description to set on the job.
job_labels: Optional set of labels to set on the job.
run_name: A unique identifier representing an automation run for the
processor. An Automation Run contains a collection of device
configurations for the processor.
device_config_name: An identifier used to select the processor configuration
utilized to run the job. A configuration identifies the set of
available qubits, couplers, and supported gates in the processor.
Returns:
An AbstractJob. If this is iterated over it returns a list of
`cirq.Result`, one for each parameter sweep.
Raises:
ValueError: If neither `processor_id` or `processor_ids` are set.
ValueError: If only one of `run_name` and `device_config_name` are specified.
ValueError: If `processor_ids` has more than one processor id.
ValueError: If either `run_name` and `device_config_name` are set but
`processor_id` is empty.
"""
return await self.engine().run_sweep_async(
processor_ids=[self.processor_id],
program=program,
program_id=program_id,
job_id=job_id,
Expand All @@ -276,6 +315,9 @@ async def run_sweep_async(
program_labels=program_labels,
job_description=job_description,
job_labels=job_labels,
processor_id=self.processor_id,
run_name=run_name,
device_config_name=device_config_name,
)

def _inner_processor(self) -> quantum.QuantumProcessor:
Expand Down
10 changes: 8 additions & 2 deletions cirq-google/cirq_google/engine/simulated_local_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,10 @@ def list_calibrations(
if earliest_timestamp_seconds <= cal[0] <= latest_timestamp_seconds
]

def get_sampler(self) -> ProcessorSampler:
return ProcessorSampler(processor=self)
def get_sampler(self, run_name: str = "", device_config_name="") -> ProcessorSampler:
return ProcessorSampler(
processor=self, run_name=run_name, device_config_name=device_config_name
)

def supported_languages(self) -> List[str]:
return VALID_LANGUAGES
Expand Down Expand Up @@ -208,6 +210,8 @@ async def run_batch_async(
program_labels: Optional[Dict[str, str]] = None,
job_description: Optional[str] = None,
job_labels: Optional[Dict[str, str]] = None,
run_name: str = "",
device_config_name: str = "",
) -> SimulatedLocalJob:
if program_id is None:
program_id = self._create_id(id_type='program')
Expand Down Expand Up @@ -244,6 +248,8 @@ async def run_sweep_async(
program_labels: Optional[Dict[str, str]] = None,
job_description: Optional[str] = None,
job_labels: Optional[Dict[str, str]] = None,
run_name: str = "",
device_config_name: str = "",
) -> SimulatedLocalJob:
if program_id is None:
program_id = self._create_id(id_type='program')
Expand Down

0 comments on commit 89cf4d7

Please sign in to comment.