-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add get config functions #7565
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
base: main
Are you sure you want to change the base?
Add get config functions #7565
Changes from all commits
77eec1a
69f1397
a8e8262
df98f15
5fb5fbc
3b29858
71dad68
7cbcdc1
6866f26
20ca033
b3413a4
eed577d
cc447ff
c30bde8
b1ef097
2eb9ee9
aee07e6
bc7db00
9e2fdcd
cc4b43e
6835a61
e96871c
e2429c3
093cd1e
11d97f5
2365a57
67cabf4
afe7f0e
947ad46
4783519
3d1e101
1505ba8
f7bba28
f15e751
449fdd4
d259f1a
6eba4b4
cd81646
4a03de1
000ce5d
00e2f36
4584bff
a89213e
f9ef67a
7059f1a
32ad541
2ef6805
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1181,6 +1181,76 @@ async def list_time_slots_async( | |
|
||
list_time_slots = duet.sync(list_time_slots_async) | ||
|
||
async def _get_quantum_processor_config( | ||
self, name: str | ||
) -> quantum.QuantumProcessorConfig | None: | ||
"""Runs get_quantum_processor_config with the given resource name.""" | ||
try: | ||
request = quantum.GetQuantumProcessorConfigRequest(name=name) | ||
return await self._send_request_async( | ||
self.grpc_client.get_quantum_processor_config, request | ||
) | ||
except EngineException as err: | ||
if isinstance(err.__cause__, NotFound): | ||
return None | ||
raise | ||
|
||
async def get_quantum_processor_config_from_snapshot_async( | ||
self, project_id: str, processor_id: str, snapshot_id: str, config_name: str | ||
) -> quantum.QuantumProcessorConfig | None: | ||
"""Returns the QuantumProcessorConfig for the given snapshot id. | ||
|
||
Args: | ||
project_id: A project_id of the parent Google Cloud Project. | ||
processor_id: The processor unique identifier. | ||
snapshot_id: The id of the snapshot that contains the quantum processor config. | ||
config_name: The id of the quantum processor config. | ||
|
||
Returns: | ||
The quantum procesor config or None if it does not exist. | ||
|
||
Raises: | ||
EngineException: If the request to get the config fails. | ||
""" | ||
name = _quantum_processor_name_with_snapshot_id( | ||
project_id=project_id, | ||
processor_id=processor_id, | ||
snapshot_id=snapshot_id, | ||
config_name=config_name, | ||
) | ||
return await self._get_quantum_processor_config(name) | ||
|
||
get_quantum_processor_config_from_snapshot = duet.sync( | ||
get_quantum_processor_config_from_snapshot_async | ||
) | ||
|
||
async def get_quantum_processor_config_from_run_async( | ||
self, project_id: str, processor_id: str, run_name: str, config_name: str | ||
) -> quantum.QuantumProcessorConfig | None: | ||
"""Returns the QuantumProcessorConfig for the given run_name. | ||
|
||
Args: | ||
project_id: A project_id of the parent Google Cloud Project. | ||
processor_id: The processor unique identifier. | ||
config_name: The id of the quantum processor config. | ||
run_name: The run_name that contains the quantum processor config. | ||
|
||
Returns: | ||
The quantum procesor config or None if it does not exist. | ||
|
||
Raises: | ||
EngineException: If the request to get the config fails. | ||
""" | ||
name = _quantum_processor_name_with_run_name( | ||
project_id=project_id, | ||
processor_id=processor_id, | ||
run_name=run_name, | ||
config_name=config_name, | ||
) | ||
return await self._get_quantum_processor_config(name) | ||
|
||
get_quantum_processor_config_from_run = duet.sync(get_quantum_processor_config_from_run_async) | ||
|
||
|
||
def _project_name(project_id: str) -> str: | ||
return f'projects/{project_id}' | ||
|
@@ -1230,6 +1300,28 @@ def _ids_from_calibration_name(calibration_name: str) -> tuple[str, str, int]: | |
return parts[1], parts[3], int(parts[5]) | ||
|
||
|
||
def _quantum_processor_name_with_snapshot_id( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This name represents a "processor config" and not a "processor" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is an existing pattern above of "_name_from_ids" - can we use that instead for consistency? |
||
project_id: str, processor_id: str, snapshot_id: str, config_name: str | ||
) -> str: | ||
return ( | ||
f'projects/{project_id}/' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: since this is a sub-resource of processor, WDYT of relying on |
||
f'processors/{processor_id}/' | ||
f'configSnapshots/{snapshot_id}/' | ||
f'configs/{config_name}' | ||
) | ||
|
||
|
||
def _quantum_processor_name_with_run_name( | ||
project_id: str, processor_id: str, run_name: str, config_name: str | ||
) -> str: | ||
return ( | ||
f'projects/{project_id}/' | ||
f'processors/{processor_id}/' | ||
f'configAutomationRuns/{run_name}/' | ||
f'configs/{config_name}' | ||
) | ||
|
||
|
||
def _date_or_time_to_filter_expr(param_name: str, param: datetime.datetime | datetime.date): | ||
"""Formats datetime or date to filter expressions. | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this needed? It's no longer part of the
AbstractLocalProcessor
afaict.