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

Conversation

senecameeks
Copy link
Collaborator

@senecameeks senecameeks commented Mar 22, 2024

  • Add a DeviceConfigKey proto wrapper class.
  • Initialize a sampler with the run_name and config_alias from the inner QuantumProcessor.
  • ProcessorSelector renamed its field to device_config_selector, this PR fixes the client code so it aligns with the QuantumEngine representation of a processor selector. This also de-dupes the class DeviceConfigKey.

@senecameeks senecameeks marked this pull request as ready for review March 25, 2024 04:55
@senecameeks senecameeks requested review from wcourtney, vtomole, cduck, verult and a team as code owners March 25, 2024 04:55
Copy link

codecov bot commented Mar 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.77%. Comparing base (4afe4ae) to head (a70f2ff).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6521      +/-   ##
==========================================
- Coverage   97.78%   97.77%   -0.01%     
==========================================
  Files        1105     1105              
  Lines       95112    95154      +42     
==========================================
+ Hits        93003    93041      +38     
- Misses       2109     2113       +4     

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

@senecameeks senecameeks changed the title [DRAFT] add default device config key to grid device metadata Initialize processor sampler with the default device config key Mar 25, 2024
@senecameeks senecameeks requested a review from wcourtney March 25, 2024 19:36
Copy link
Collaborator

@wcourtney wcourtney left a comment

Choose a reason for hiding this comment

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

Nearly there, thanks for the updates!

@senecameeks senecameeks requested a review from wcourtney March 26, 2024 00:04
@senecameeks
Copy link
Collaborator Author

My local env was missing some dependencies which made testing locally difficult. I was able to install the write dependencies buried in dev_tools/conf/pip-install-minimal-for-pytest-changed-files.sh

super().__init__()
self._processor = quantum.QuantumProcessor()

async def get_processor_async(
Copy link
Collaborator

Choose a reason for hiding this comment

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

This doesn't do anything async and doesn't seem to be called by the system under test. Is it needed? It seems like getProcessor() could just return the value instead.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The fake needed to match the method signature of its parent class, otherwise errors arose or it would default to the super class. My initial attempt was to do what you described but that caused errors. Regardless, this chunk was removed in the update in favor of a mock client. :)



def test_get_sampler_loads_processor_with_default_device_configuration() -> None:
client = FakeEngineClient()
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks almost the same as a mock, which would skip creating the FakeEngineClient class; wdyt?

client = mock.Mock(engine_client.EngineClient)
client.get_processor.return_value = quantum.QuantumProcessor(
   ...
)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

+1, added

cirq-google/cirq_google/engine/engine_processor_test.py Outdated Show resolved Hide resolved
"""
processor = self._inner_processor()
if processor is not None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

self._inner_processor() should never return None according to the type hint.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point, although there are null checks on _inner_processor() in other parts of the code :)

I added a bit of logic that initializes the sampler with the default values if get_sampler is improperly parameterized with one of either run_name or config_alias, and thus would raise a ValueError.

Instead, we correct the device config key for them and print out that the default value are being used. @wcourtney , WDYT? Right now the device spec being returned is always the Processor's default, but this will be useful in the future as the device spec reflects the device_config_key specified.

@senecameeks senecameeks requested a review from wcourtney March 26, 2024 18:49
# to the Processor's default values.
if not run_name or not device_config_name:
logging.info(
"Cannot specify only one of `run_name` and `device_config_name`. "
Copy link
Collaborator

Choose a reason for hiding this comment

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

If a user tried to specify a config then they probably didn't intend to use the default. If we automatically fix it for them, then they may not notice and wind up running the experiment with a different config than they expected. They should acknowledge the issue by fixing the incorrect config, so we should probably still raise an error.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I considered this, but thought logging that we're switching to the default values would be sufficient since there's precedent for switching to a simulator if the user is unable to connect to the quantum_engine. Example.

But, I think this is a good concern so I opted to only initialize with the default value if run_name and config_alias are not specified.

@@ -14,13 +14,14 @@

import datetime

import logging
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you know if there's a policy on logging in Cirq? I only see it used for tests in Google-managed code (cirq-core and cirq-google). I do see some examples of print statements coupled with a verbosity flag, e.g.:

@senecameeks senecameeks requested a review from wcourtney March 26, 2024 23:53
Copy link
Collaborator

@wcourtney wcourtney left a comment

Choose a reason for hiding this comment

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

Looks great, thanks @senecameeks !

@senecameeks senecameeks merged commit 46e4483 into quantumlib:main Mar 27, 2024
31 checks passed
jselig-rigetti pushed a commit to jselig-rigetti/Cirq that referenced this pull request May 28, 2024
…tumlib#6521)

* add default device config key to grid device metadata

* Revert "add default device config key to grid device metadata"

This reverts commit bcd3533.

* initialize sampler with default device config key and add tests

* add properties to sampler

* dedupe DeviceConfigK, onewas renamed to DeviceConfigSelector

* spelling

* coverage

* address comments

* add fake engine context and client for testing

* lint

* use new FakeEngineContext

* typecheck

* lint , local env not catching CI errors

* signature of fakes  match real impls

* add logic to initialize default values instead of throwing value error

* lint

* rm logging and prefer to throw value error
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.

2 participants