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

Deprecate QuantumEngineSampler #5432

Merged

Conversation

dstrain115
Copy link
Collaborator

  • Deprecates this class in favor of ProcessorSampler
  • Moves get_engine_sampler into engine with the other utility functions
  • Change engine.get_sampler to only support a single processor and have
    it point to the processor's sampler.

Fixes: #5371

- Deprecates this class in favor of ProcessorSampler
- Moves get_engine_sampler into engine with the other utility functions
- Change engine.get_sampler to only support a single processor and have
  it point to the processor's sampler.

Fixes: quantumlib#5371
@dstrain115 dstrain115 requested review from wcourtney, a team, vtomole, cduck and verult as code owners June 2, 2022 00:18
@dstrain115 dstrain115 requested a review from maffoo June 2, 2022 00:18
@CirqBot CirqBot added the size: M 50< lines changed <250 label Jun 2, 2022
@dstrain115 dstrain115 requested a review from mrwojtek June 2, 2022 16:35
@dstrain115
Copy link
Collaborator Author

@mrwojtek FYI: QuantumEngineSampler is being deprecated in favor of ProcessorSampler. Let me know if you see any problems with the changes to the calibration workflow code.

Comment on lines 830 to 831
processor_id = getattr(sampler.processor, 'processor_id', None)
engine = sampler.processor.engine() if processor_id is not None else None
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems odd to check for the presence of a processor_id attribute to determine whether to call .engine(). Do we need a check at all, given that AbstractProcessor.engine() method is defined as returning Optional[AbstractEngine]?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, there were some typing shenanigans that made this necessary. I refactored so that the function below takes a processor instead of an engine, which removes the need for this.

@@ -801,21 +800,29 @@ def sampler(
@util.deprecated_gate_set_parameter
def get_sampler(
self, processor_id: Union[str, List[str]], gate_set: Optional[Serializer] = None
) -> engine_sampler.QuantumEngineSampler:
) -> cirq.Sampler:
Copy link
Contributor

Choose a reason for hiding this comment

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

Here, too, might be better to type as returning ProcessorSampler.

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.

@@ -782,7 +781,7 @@ def get_processor(self, processor_id: str) -> engine_processor.EngineProcessor:
@util.deprecated_gate_set_parameter
def sampler(
self, processor_id: Union[str, List[str]], gate_set: Optional[Serializer] = None
) -> engine_sampler.QuantumEngineSampler:
) -> cirq.Sampler:
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this return ProcessorSampler 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.

Yeah, it's probably better for this to be more specific.

@@ -877,3 +884,30 @@ def get_engine_calibration(
May return None if no calibration metrics exist for the device.
"""
return get_engine(project_id).get_processor(processor_id).get_current_calibration()


def get_engine_sampler(processor_id: str, project_id: Optional[str] = None) -> cirq.Sampler:
Copy link
Contributor

Choose a reason for hiding this comment

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

Here, too, consider typing the return as ProcessorSampler.

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.

A `QuantumEngineSampler` instance.

Raises:
ValueError: If the supplied gate set is not a supported gate set name.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: remove this as there's no gate_set_name parameter.

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.

Args:
processor_id: Engine processor ID (from Cloud console or
``Engine.list_processors``).
gate_set_name: One of ['sqrt_iswap', 'sycamore'].
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: no gate_set_name arg

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.

personal project IDs in shared code.

Returns:
A `QuantumEngineSampler` instance.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I'd suggest removing this, since it doesn't add anything beyond the return type annotation. If you want to leave it, can just say it returns a sampler.

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.

@dstrain115 dstrain115 requested a review from maffoo June 3, 2022 01:46
@dstrain115 dstrain115 merged commit fdb1527 into quantumlib:master Jun 3, 2022
@@ -877,3 +884,26 @@ def get_engine_calibration(
May return None if no calibration metrics exist for the device.
"""
return get_engine(project_id).get_processor(processor_id).get_current_calibration()


def get_engine_sampler(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why was this moved? Just for better organizational sense?

@mpharrigan
Copy link
Collaborator

nice; when I was doing #5361 I was worried the calibration dispatching would be a mess; but you've done it very nicely

rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
* Deprecate QuantumEngineSampler

- Deprecates this class in favor of ProcessorSampler
- Moves get_engine_sampler into engine with the other utility functions
- Change engine.get_sampler to only support a single processor and have
  it point to the processor's sampler.
- Fix calibration workflow to use ProcessorSampler

Fixes: quantumlib#5371
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: M 50< lines changed <250
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deprecate QuantumEngineSampler
4 participants