Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Refactor get sampler#7672

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
dyates wants to merge22 commits intoquantumlib:main
base:main
Choose a base branch
Loading
fromdyates:refactor_get_sampler

Conversation

@dyates
Copy link
Contributor

@dyatesdyates commentedSep 26, 2025
edited
Loading

Fixes bug 435217087. Refactorget_sampler .

get_sampler: This function no longer requires or acceptsrun_name andsnapshot_id

sampler = engine.get_sampler(processor_id='proc_id', device_config_name='test_alias')another_sampler = engine.get_sampler(processor_id='proc_id')

get_sampler using a run id:

sampler = engine.get_sampler(     processor_id='proc_id', Run(id='current)', device_config_name='test_alias')processor = engine.get_processor('proc_id')another_sampler = processor.get_sampler(     processor_id='proc_id', Run(id='current'), device_config_name='test_alias')

get_sampler using a snapshot id:

sampler = engine.get_sampler(     processor_id='proc_id', Snapshot(id='test_snapshot'), device_config_name='test_alias')processor = engine.get_processor('proc_id')another_sampler = processor.get_sampler(    processor_id='proc_id', Snapshot(id='test_snapshot_id'), device_config_name='test_alias')

You can now get a sampler from a config as well

sampler = engine.get_processor('proc_id').get_config().sampler()

@github-actionsgithub-actionsbot added the size: L250< lines changed <1000 labelSep 26, 2025
@codecov
Copy link

codecovbot commentedSep 26, 2025
edited
Loading

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.38%. Comparing base (8dd8a8f) to head (b7de024).

Additional details and impacted files
@@           Coverage Diff           @@##             main    #7672   +/-   ##=======================================  Coverage   99.38%   99.38%           =======================================  Files        1090     1090             Lines       98300    98299    -1     =======================================  Hits        97694    97694+ Misses        606      605    -1

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

🚀 New features to boost your workflow:
  • ❄️Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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
Copy link
Collaborator

Choose a reason for hiding this comment

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

This removes what I would expect to be the most common use case: specify only a device config name, but not the version (run or snapshot).

@eliottrosenberg - do we really want to support a default config name ("config alias") at all? While defaults make sense to get the "latest" version, a default grid seem more risky and I think are worth forcing explicit selection.

returnengine_processor.EngineProcessor(self.project_id,processor_id,self.context)

defget_sampler(
defget_sampler_from_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.

The methods inEngine are intended to be easy-to-remember convenience helpers and I'm concerned that over-specialization makes these less usable and more painful to maintain. e.g., if we add another feature with 2 ways to construct a sampler and follow this pattern, these 3 functions will turn into 6 new functions with very long names.

Thestyle guide suggests that defaults are useful to avoid "lots of functions for the rare exceptions", and@eliottrosenberg made it sound like these specialized versions are exceptional.

Would it suffice to just check for mutual exclusivity of the arguments and raise an exception if that's violated? Alternatively, if you find it important to bake this check into the interface, you could alternatively do it with the type system, e.g.:

@dataclassclass Snapshot:  id: str@dataclassclass Run:  id: strtype DeviceVersion = Snapshot | Runclass Engine  ...  def get_sampler(     self,     processor_id: str | list[str],     device_config_name: str,     device_version: DeviceVersion | None = None,     max_concurrent_jobs: int = 100,  ) -> cirq_google.ProcessorSampler:  ...

WDYT?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

@hoisinberg and I were discussing this exact pattern. Yes this is better I think.

device_config_name:str="",
snapshot_id:str="",
max_concurrent_jobs:int=100,
defget_sampler_from_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.

Could this be simplified by adding asampler() method onProcessorConfig? The equivalent of.get_sampler_from_run_name(...) would then be.get_config_from_run_name(...).sampler(). As a bonus, this form localizes scope of each resource configuration, e.g. expanded:

sampler = (    engine.get_processor('willow_123')        .get_config_from_run(run_name='current', config_name='some_cool_grid')        .sampler())

This or something like it should probably the the canonical form of retrieval because a sampler should always refer to a fully-qualified config even if the user used defaults to construct it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I like Will's suggestion.

Raises:
ValueError: If only one of `run_name` and `device_config_name` are specified.
ValueError: If both `run_name` and `snapshot_id` are specified.
defget_sampler(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Following on from the above comment regarding the requirement of a device config to build a sampler, should we removeget_sampler from the processor and instead rely on explicitly grabbing the default configuration to generate the sampler?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree with Will about removing theget_sampler methods of the processor, althoughengine.get_sampler() is useful as a convenience function so that you don't always have to get a config first.

@github-actionsgithub-actionsbot added size: XLlines changed >1000 and removed size: L250< lines changed <1000 labelsOct 24, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@hoisinberghoisinberghoisinberg left review comments

@vtomolevtomoleAwaiting requested review from vtomolevtomole is a code owner

@verultverultAwaiting requested review from verultverult is a code owner

@wcourtneywcourtneyAwaiting requested review from wcourtneywcourtney is a code owner

@eliottrosenbergeliottrosenbergAwaiting requested review from eliottrosenberg

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Labels

size: XLlines changed >1000

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

4 participants

@dyates@hoisinberg@wcourtney@eliottrosenberg

[8]ページ先頭

©2009-2025 Movatter.jp