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

Allow external users to use snapshot_id #6739

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

senecameeks
Copy link
Collaborator

@senecameeks senecameeks commented Sep 20, 2024

A follow up to PR, CL

Allows external users to set a snapshot_id

@senecameeks senecameeks marked this pull request as ready for review October 3, 2024 22:59
Copy link

codecov bot commented Oct 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.83%. Comparing base (95f6a3f) to head (6ad91b2).
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6739   +/-   ##
=======================================
  Coverage   97.83%   97.83%           
=======================================
  Files        1077     1077           
  Lines       92577    92633   +56     
=======================================
+ Hits        90574    90630   +56     
  Misses       2003     2003           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@mhucka mhucka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM. However, I don't think I'm at the point yet in my understanding of Cirq and the internal systems that I'm qualified to review this, so I think this needs someone else's approval.

@@ -156,15 +156,48 @@ class QuantumJob(proto.Message):

class DeviceConfigSelector(proto.Message):
r"""-
This message has `oneof`_ fields (mutually exclusive fields).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is auto generated code?

Copy link
Collaborator Author

@senecameeks senecameeks Oct 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, the changes in this file are from gapic client generation

cirq-google/cirq_google/engine/engine_client.py Outdated Show resolved Hide resolved
cirq-google/cirq_google/engine/engine_client.py Outdated Show resolved Hide resolved
Comment on lines 390 to 391
run_name: str | None = "",
snapshot_id: str | None = None,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the default value of run_name is "" instead of None? Can we make run_name and snapshot_id identical -- both use None?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted, so now both run_name and snapshot_id default to "" for consistency (See Will's comment)

cirq-google/cirq_google/engine/engine_processor.py Outdated Show resolved Hide resolved
@@ -105,19 +111,23 @@ def get_sampler(
processor = self._inner_processor()
# If a run_name or config_alias is not provided, initialize them
# to the Processor's default values.
if not run_name and not device_config_name:
if not run_name and not device_config_name and not snapshot_id:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious why before we use if (bool(run_name) or bool(snapshot_id)) ^ bool(device_config_name):?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before we use XOR expression to determine (and enforce) the validity of some parameter permutations. Here we check if no values were passed then initialize to the Processors default values.

Comment on lines 112 to 113
# If a run_name or config_alias is not provided, initialize them
# to the Processor's default values.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update the comment here. "If a run_name or config_alias" isn't neither of them provided?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

@@ -79,6 +80,9 @@ async def run_async(
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.
snapshot_id: A unique identifier for an immutable snapshot reference.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be documented (and enforced) that it's invalid to specify both run name and snapshot id - both here and elsewhere.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some documentation here, and enforcement in the subclasses.

cirq-google/cirq_google/engine/engine.py Outdated Show resolved Hide resolved
cirq-google/cirq_google/engine/engine_client_test.py Outdated Show resolved Hide resolved
@@ -634,7 +686,9 @@ 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_selector=quantum.DeviceConfigSelector(),
device_config_selector=quantum.DeviceConfigSelector(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this change remove an existing test case? Should it be preserved?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted, and created new test to explicitly test new code

)
)


@pytest.mark.parametrize(
'run_job_kwargs, expected_submit_args',
[
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recognize that this was an existing test, but this massive parameterization block makes it really difficult to figure out what's being tested. Consider adding a new test that explicitly refers to the condition you're demonstrating.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, and reverted changes from massive parametrization block

@@ -600,7 +650,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_selector=quantum.DeviceConfigSelector(),
device_config_selector=quantum.DeviceConfigSelector(run_name=""),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change needed? I wouldn't expect this PR's change to affect the existing tests of run_name.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a side-effect of moving run_name into a oneof

"Oneof Impact: When you assign an empty string to a string field within a oneof, protocol buffers interpret this as explicitly setting that field to a value (even if it's an empty value). This triggers the oneof to recognize that field as the active one."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants