Skip to content

Return Iterator from simulator sweep methods #4064

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
95-martin-orion opened this issue Apr 28, 2021 · 2 comments · Fixed by #4094
Closed

Return Iterator from simulator sweep methods #4064

95-martin-orion opened this issue Apr 28, 2021 · 2 comments · Fixed by #4094
Assignees

Comments

@95-martin-orion
Copy link
Collaborator

Simulator methods that return multiple results can be difficult to work with, since each result object may contains a massive representation of the simulator state. An example of this can be seen in #3979 and #3990, where the simulate_expectation_value_sweep method can't simply invoke the simulate_sweep method for fear of generating (and storing!) all of the output states simultaneously.

To resolve this, we should modify the simulator *_sweep methods to return Iterator objects instead of Lists.

This would also cause sweeps to run one simulation at a time, which reduces the "black box" delay of large sweeps, and may provide opportunities for parallelizing the simulation and result-processing pipelines.

@95-martin-orion 95-martin-orion added the kind/design-issue A conversation around design label Apr 28, 2021
@95-martin-orion 95-martin-orion self-assigned this Apr 28, 2021
@95-martin-orion
Copy link
Collaborator Author

Concern: how do we deprecate this while keeping the same name?

@95-martin-orion
Copy link
Collaborator Author

Concern: how do we deprecate this while keeping the same name?

Given the amount of time necessary (and confusion generated) from reusing the same names to return iterators, it's preferable to just have separate *_iter methods. The list-based methods can be thin wrappers around these.

CirqBot pushed a commit that referenced this issue May 12, 2021
Fixes #4064.

This PR provides `*_iter` methods for all simulator "sweep" methods. External simulators which implement the old list-based APIs will still function properly (through the magic of `@value.alternative`), but these simulators are advised to switch to the iterator-based API for better performance.

Note that the list-based API is _not_ deprecated, and we have no plans to remove it at this time.
rht pushed a commit to rht/Cirq that referenced this issue May 1, 2023
Fixes quantumlib#4064.

This PR provides `*_iter` methods for all simulator "sweep" methods. External simulators which implement the old list-based APIs will still function properly (through the magic of `@value.alternative`), but these simulators are advised to switch to the iterator-based API for better performance.

Note that the list-based API is _not_ deprecated, and we have no plans to remove it at this time.
harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this issue Oct 31, 2024
Fixes quantumlib#4064.

This PR provides `*_iter` methods for all simulator "sweep" methods. External simulators which implement the old list-based APIs will still function properly (through the magic of `@value.alternative`), but these simulators are advised to switch to the iterator-based API for better performance.

Note that the list-based API is _not_ deprecated, and we have no plans to remove it at this time.
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants