-
Notifications
You must be signed in to change notification settings - Fork 2.6k
[WIP] Add providers v2 interface #4485
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
Conversation
This commit adds the initial implementation of the v2 providers interface. The rfc document in Qiskit/RFCs#2 documents the rationale beind the PR. At a high level this introduces a python based API that provides a general interface for writing additional providers to terra that is flexible enough for both additional types of services in the future and also making it less specific to the IBM Quantum API. Moving forward we will encourage existing provider to migrate to this new interface. Included in this commit the Basicaer provider has been converted to a v2 provider. This will provide a good example for providers on how to use the new model. This is still very much in progress, prior to removing the WIP this will be split into 3 PRs. The first will add the Counts class, the second will add the v2 providers interface, and the 3rd will migrate the BasicAer provider to use the v2 interface all 3 are combined for now for ease ease of testing and development (with github's limitations around dependencies between PRs), but each is an independent piece that can stand on it's own (and will make it much easier for final review). Implements Qiskit/RFCs#2 Fixes Qiskit#4105
This commit adds a new class qiskit.result.Counts which is a dict subclass for dealing with count results from experiment. It takes in a counts dictionary with hexadecimal string keys and it's data is a binary string, like the output of get_counts(). The idea is that this class contains extra attributes about the execution and helper methods for interacting with counts results. It can be used as a direct replacment anywhere a counts dictionary was used previously. It is also now the return type for qiskit.quantum_info.QuantumState.sample_counts(). This commit is part of the v2 providers interface work and will be a key part of the new providers interface. This class is split out as a seperate commit/PR from Qiskit#4485.
qiskit/execute.py
Outdated
# v2 Providers Backend | ||
if isinstance(backend, Backend): | ||
start_time = time() | ||
backend.set_configuration(shots=shots, **run_config) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Do we really need to support
execute()
in v2? While it's a convenience function, the user needs to know what keywords are supported by the backend to use it - It'll need to pass more of the keywords (e.g.
meas_level
andmeas_return
) than justshots
andrun_config
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do, it's part of the backwards compat/migration story. The v2 providers interface is not a user facing thing directly. It's provider api facing, a terra end user won't necessarily know that when they install a new version of aer or ibmq the api version the provider is talking to terra with has changed. execute
in particular is very important because it has been the primary entrypoint we've documented to users for a long time so they'll have existing code leveraging it. I agree, the backwards compat story here isn't finished yet I only did enough to validate execute worked with basicaer. I'll also need to add a check if the configuration object for a v2 backend has the attribute before trying to pass it set_configuration()
.
To summarize, the new backend behaviors are now: Is this correct? |
More or less, the only distinction I would make is that target is specifically any device attributes that the transpiler is looking for, which is currently num_qubits, coupling_map, and gates/basis_gates (maybe we should condense that). I added conditional as a potential future verification pass and the instructions list for potential future use (since that's currently an implicit hardcoded assumption). The current I also need to figure out a backwards compat story for people who call v2/backend.configuration() and v2/backend.properties() since that is something end users do (which is listed as a todo in the PR summary). |
The other thing I should mention is that the naming is flexible at this point. But we should be happy with whatever we decide because it's not worth deprecating and renaming post-release. I chose target for what the transpiler needs because of it's usage in other compilers, and configuration is at least 3x overloaded in the v1 interface which I wanted to fix, so I settled on it for the dynamic bits because we've been calling that feature configurable backends. But for example we could change the dynamic stuff to use |
If the naming is flexible, can we leave |
Sorry I worded that poorly, I meant as python properties of the Backend subclass, not attributes of the |
Between the PoC/WIP PR Qiskit/qiskit#4485 and recent review comments there has been a lot of feedback made on the earlier versions of this RFC. This commit updates the RFC to take much of that into account and also provide a clearer definition on some aspects of the proposal.
* Add Counts object This commit adds a new class qiskit.result.Counts which is a dict subclass for dealing with count results from experiment. It takes in a counts dictionary with hexadecimal string keys and it's data is a binary string, like the output of get_counts(). The idea is that this class contains extra attributes about the execution and helper methods for interacting with counts results. It can be used as a direct replacment anywhere a counts dictionary was used previously. It is also now the return type for qiskit.quantum_info.QuantumState.sample_counts(). This commit is part of the v2 providers interface work and will be a key part of the new providers interface. This class is split out as a seperate commit/PR from #4485. * Fix docs build * Fix lint * Add missing test file * Switch custom exception class to QiskitError * Cleanup release note * Add comment about dict subclassing * Tweak comment wording slightly * Add support for int and binary input keys and handle qudits This commit allows for the input key format for the data dict to be hex, binary, or integers and use all the functionality as expected. It also adds handling for dit strings which don't handle the hex or binary output formats or allow for formating across registers. * Fix tests * Fix lint * Handle 0b prefixed binary strings * Update init docs * Fix docs again * Add tests for 0b prefixed input * Remove metadata from Counts object This commit removes the metadata support from the counts object. There is some debate on wheter we want to enable support for attaching arbitrary key value metadata to a Counts object or not. Until that debate is settled this commit removes it from the object to unblock progress. It will be simple to add in a backwards compat manner if it decided that we want to enable this in the future. * Use Counts instead of dict for Results.get_counts() output * Remove other circuit level metadata * Update results to not include removed metadata * Fix tests * Really remove metadata from class Co-authored-by: Luciano Bello <luciano.bello@ibm.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
* Add Counts object This commit adds a new class qiskit.result.Counts which is a dict subclass for dealing with count results from experiment. It takes in a counts dictionary with hexadecimal string keys and it's data is a binary string, like the output of get_counts(). The idea is that this class contains extra attributes about the execution and helper methods for interacting with counts results. It can be used as a direct replacment anywhere a counts dictionary was used previously. It is also now the return type for qiskit.quantum_info.QuantumState.sample_counts(). This commit is part of the v2 providers interface work and will be a key part of the new providers interface. This class is split out as a seperate commit/PR from Qiskit#4485. * Fix docs build * Fix lint * Add missing test file * Switch custom exception class to QiskitError * Cleanup release note * Add comment about dict subclassing * Tweak comment wording slightly * Add support for int and binary input keys and handle qudits This commit allows for the input key format for the data dict to be hex, binary, or integers and use all the functionality as expected. It also adds handling for dit strings which don't handle the hex or binary output formats or allow for formating across registers. * Fix tests * Fix lint * Handle 0b prefixed binary strings * Update init docs * Fix docs again * Add tests for 0b prefixed input * Remove metadata from Counts object This commit removes the metadata support from the counts object. There is some debate on wheter we want to enable support for attaching arbitrary key value metadata to a Counts object or not. Until that debate is settled this commit removes it from the object to unblock progress. It will be simple to add in a backwards compat manner if it decided that we want to enable this in the future. * Use Counts instead of dict for Results.get_counts() output * Remove other circuit level metadata * Update results to not include removed metadata * Fix tests * Really remove metadata from class Co-authored-by: Luciano Bello <luciano.bello@ibm.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is a lighterweight v2 provider interface. This is an alternative to what is built in Qiskit#4885. While the model in Qiskit#4885 is a desireable end state it requires a lot of changes all at once for providers and potentially users. Instead this commit brings the core concept from Qiskit#4885 of a cleaner explicitly versioned abstract interface but minimizes the changes to the data model used in v1. Only some small changes are made, mainly that jobs can be sync or async, Backend.run() takes a circuit or schedule, options are set via an Options object at __init__, with set_option(), or as kwargs on run(). In all other places the object models from the v1 provider interface are used. This makes the migration to a versioned interface simpler to start. From there we can continue to evolve the interface as was done in Qiskit#4485, like moving to a target object, reimplementing properties and defaults as versioned objects, etc. Since the differences here are so small this commit brings the basicaer provider over to the v2 provider interface. This can be done with minimal effort to showcase how similar the 2 interfaces are.
* Add lightweight v2 provider interface starter This commit is a lighterweight v2 provider interface. This is an alternative to what is built in #4885. While the model in #4885 is a desireable end state it requires a lot of changes all at once for providers and potentially users. Instead this commit brings the core concept from #4885 of a cleaner explicitly versioned abstract interface but minimizes the changes to the data model used in v1. Only some small changes are made, mainly that jobs can be sync or async, Backend.run() takes a circuit or schedule, options are set via an Options object at __init__, with set_option(), or as kwargs on run(). In all other places the object models from the v1 provider interface are used. This makes the migration to a versioned interface simpler to start. From there we can continue to evolve the interface as was done in #4485, like moving to a target object, reimplementing properties and defaults as versioned objects, etc. Since the differences here are so small this commit brings the basicaer provider over to the v2 provider interface. This can be done with minimal effort to showcase how similar the 2 interfaces are. * Fix basicaer simulator init * Fix lint * Add provider property to basicaer for Aqua backwards compat * Add provider method back to backend class for backwards compat * Fix lint * Add release notes * Add v2 provider to docs * Fix lint * Revert basicaer v2 provider migration * Apply suggestions from code review Co-authored-by: Ali Javadi-Abhari <ajavadia@users.noreply.github.com> Co-authored-by: Jessie Yu <jessieyu@us.ibm.com> * Add missing version attributes * Make Options a simplenamespace subclass * Update Backend docstrings * Add v2 Backend support to the rest of terra * Fix lint * Fix lint * Flatten providers subpackage * Apply suggestions from code review Co-authored-by: Ali Javadi-Abhari <ajavadia@users.noreply.github.com> * Update release notes Co-authored-by: Ali Javadi-Abhari <ajavadia@users.noreply.github.com> Co-authored-by: Jessie Yu <jessieyu@us.ibm.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This has been superseded by #5086 which merged a long time ago and has been release. The concepts in this around backends and jobs will probably inform new BackendV2 and JobV2 abstract interface definitions but those will be new PRs. |
* Add lightweight v2 provider interface starter This commit is a lighterweight v2 provider interface. This is an alternative to what is built in #4885. While the model in #4885 is a desireable end state it requires a lot of changes all at once for providers and potentially users. Instead this commit brings the core concept from #4885 of a cleaner explicitly versioned abstract interface but minimizes the changes to the data model used in v1. Only some small changes are made, mainly that jobs can be sync or async, Backend.run() takes a circuit or schedule, options are set via an Options object at __init__, with set_option(), or as kwargs on run(). In all other places the object models from the v1 provider interface are used. This makes the migration to a versioned interface simpler to start. From there we can continue to evolve the interface as was done in #4485, like moving to a target object, reimplementing properties and defaults as versioned objects, etc. Since the differences here are so small this commit brings the basicaer provider over to the v2 provider interface. This can be done with minimal effort to showcase how similar the 2 interfaces are. * Fix basicaer simulator init * Fix lint * Add provider property to basicaer for Aqua backwards compat * Add provider method back to backend class for backwards compat * Fix lint * Add release notes * Add v2 provider to docs * Fix lint * Revert basicaer v2 provider migration * Apply suggestions from code review Co-authored-by: Ali Javadi-Abhari <ajavadia@users.noreply.github.com> Co-authored-by: Jessie Yu <jessieyu@us.ibm.com> * Add missing version attributes * Make Options a simplenamespace subclass * Update Backend docstrings * Add v2 Backend support to the rest of terra * Fix lint * Fix lint * Flatten providers subpackage * Apply suggestions from code review Co-authored-by: Ali Javadi-Abhari <ajavadia@users.noreply.github.com> * Update release notes * Migrate basic aer provider to v2 interface This commit migrates the basic aer provider to the v2 interface. This was originally included in #5086 but had to be removed because of a potential backwards compatibility issue with aqua when using basic aer as the provider (aqua 0.7.x explicity checks for v1 interface backends). * DNM install aqua from source to test tutorials * Remove deprecated schema validation * Test failures * Fix tests and lint * Install aqua from source until release * Add release notes * Add ignis from source too as a dependency of aqua * Apply suggestions from code review Co-authored-by: Ali Javadi-Abhari <ajavadia@users.noreply.github.com> * Finish upgrade release note Co-authored-by: Ali Javadi-Abhari <ajavadia@users.noreply.github.com> Co-authored-by: Jessie Yu <jessieyu@us.ibm.com>
…5128) * Add lightweight v2 provider interface starter This commit is a lighterweight v2 provider interface. This is an alternative to what is built in Qiskit/qiskit#4885. While the model in Qiskit/qiskit#4885 is a desireable end state it requires a lot of changes all at once for providers and potentially users. Instead this commit brings the core concept from Qiskit/qiskit#4885 of a cleaner explicitly versioned abstract interface but minimizes the changes to the data model used in v1. Only some small changes are made, mainly that jobs can be sync or async, Backend.run() takes a circuit or schedule, options are set via an Options object at __init__, with set_option(), or as kwargs on run(). In all other places the object models from the v1 provider interface are used. This makes the migration to a versioned interface simpler to start. From there we can continue to evolve the interface as was done in Qiskit/qiskit#4485, like moving to a target object, reimplementing properties and defaults as versioned objects, etc. Since the differences here are so small this commit brings the basicaer provider over to the v2 provider interface. This can be done with minimal effort to showcase how similar the 2 interfaces are. * Fix basicaer simulator init * Fix lint * Add provider property to basicaer for Aqua backwards compat * Add provider method back to backend class for backwards compat * Fix lint * Add release notes * Add v2 provider to docs * Fix lint * Revert basicaer v2 provider migration * Apply suggestions from code review Co-authored-by: Ali Javadi-Abhari <ajavadia@users.noreply.github.com> Co-authored-by: Jessie Yu <jessieyu@us.ibm.com> * Add missing version attributes * Make Options a simplenamespace subclass * Update Backend docstrings * Add v2 Backend support to the rest of terra * Fix lint * Fix lint * Flatten providers subpackage * Apply suggestions from code review Co-authored-by: Ali Javadi-Abhari <ajavadia@users.noreply.github.com> * Update release notes * Migrate basic aer provider to v2 interface This commit migrates the basic aer provider to the v2 interface. This was originally included in Qiskit/qiskit#5086 but had to be removed because of a potential backwards compatibility issue with aqua when using basic aer as the provider (aqua 0.7.x explicity checks for v1 interface backends). * DNM install aqua from source to test tutorials * Remove deprecated schema validation * Test failures * Fix tests and lint * Install aqua from source until release * Add release notes * Add ignis from source too as a dependency of aqua * Apply suggestions from code review Co-authored-by: Ali Javadi-Abhari <ajavadia@users.noreply.github.com> * Finish upgrade release note Co-authored-by: Ali Javadi-Abhari <ajavadia@users.noreply.github.com> Co-authored-by: Jessie Yu <jessieyu@us.ibm.com>
Summary
This commit adds the initial implementation of the v2 providers
interface. The rfc document in Qiskit/RFCs#2 documents the rationale
behind the PR. At a high level this introduces a python based API that
provides a general interface for writing additional providers to terra
that is flexible enough for both additional types of services in the
future and also making it less specific to the IBM Quantum API.
Moving forward we will encourage existing providers to migrate to this
new interface.
Included in this commit the BasicAer provider has been converted to a
v2 provider. This will provide a good example for providers on how to
use the new model.
Details and comments
This is still very much in progress, prior to removing the WIP this will
be split into 3 PRs. The first will add the Counts class, the second
will add the v2 providers interface, and the 3rd will migrate the
BasicAer provider to use the v2 interface all 3 are combined for now for
ease ease of testing and development (with github's limitations around
dependencies between PRs), but each is an independent piece that can
stand on it's own (and will make it much easier for final review).
TODO:
Implements Qiskit/RFCs#2
Fixes #4105