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

feat: Introduce MultiSimulator class #260

Closed
wants to merge 2 commits into from
Closed

feat: Introduce MultiSimulator class #260

wants to merge 2 commits into from

Conversation

speller26
Copy link
Member

Issue #, if available:

Description of changes:

Introduces MultiSimulator class to allow backends to leverage their own batching implementations. Will next publish SDK PR to make use of this interface.

Testing done:

Merge Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your pull request.

General

Tests

  • I have added tests that prove my fix is effective or that my feature works (if appropriate)
  • I have checked that my tests are not configured for a specific region or account (if appropriate)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@speller26 speller26 requested a review from kshyatt-aws June 4, 2024 23:17
@speller26 speller26 requested a review from a team as a code owner June 4, 2024 23:17
Copy link

codecov bot commented Jun 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (a4d7f98) to head (119439f).
Report is 20 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #260   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           48        48           
  Lines         3712      3712           
  Branches       889       890    +1     
=========================================
  Hits          3712      3712           

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

kshyatt-aws
kshyatt-aws previously approved these changes Jun 11, 2024
@@ -63,3 +63,33 @@ def run(
@abstractmethod
def properties(self) -> DeviceCapabilities:
"""DeviceCapabilities: Properties of the device."""


class MultiSimulator(BraketSimulator):
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like a little overkill to create a new abstract class/interface this one method that's very related to the existing run method.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I'm also curious why we couldn't just add run_multiple to the existing interface, and provide a default implementation.

Copy link
Member Author

Choose a reason for hiding this comment

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

Regardless, we're going to need a new method for the backend to run multiple circuits; this means it has to live either in BraketSimulator or a new class. If it lives in BraketSimulator, then the SDK would need either check whether the method throws an exception (not great), or we'd need to add a new property in BraketSimulator for the SDK to check, which then leads to a situation where devs can implement the method and forget to mark the property true, or vice-versa.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could BraketSimulator also provide a default implementation of run_multiple? (maybe it could do exactly what the SDK does today for run_batch - delegate to Pool)

Copy link
Member Author

Choose a reason for hiding this comment

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

I suppose it could; it just doesn't seem useful to have the same implementation in both the simulator and the SDK; as well, the abstract BraketSimulator class having a default implementation could potentially lead to multiple inheritance issues down the line.

Copy link
Member Author

Choose a reason for hiding this comment

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

Alternative implementation in #264

"""

@abstractmethod
def run_multiple(
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably have a default implementation of this, so that future simulators don't need to re-implement it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we call it run_multiple instead of run_batch? It's also a little confusing because it's unspecified how the *args and **kwargs should apply to the batch. For example, do they apply globally to all of the tasks? Or should these be lists of the (*args, **kwargs) that would be provided to a single run call?

Copy link
Member Author

Choose a reason for hiding this comment

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

The SDK already provides the default implementation if the simulator doesn't subclass MultiSimulator; if someone doesn't want a native run_multiple method, they can just implement BraketSimulator.

As for run_multiple vs run_batch, the reasons are twofold:

  1. The simulator doesn't really have any notion of "batch" the way the SDK does; the method just returns a list of results.
  2. The word "batch" is already used in the state vector simulator for subdividing the circuit into chunks of gates and contracting these "batches" together (I'm sorry about the name, my bad), so I didn't want to reuse it.

Comment on lines +85 to +86
Extra arguments will contain any additional information necessary to run the tasks,
such as number of qubits.
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this is copied from the run docstring, but "number of qubits" is a weird example here. Better examples would be number of shots, or lists of input parameters to the tasks.

@rmshaffer
Copy link
Contributor

@speller26 should we close this now in favor of #264?

@speller26 speller26 closed this Jun 27, 2024
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