Skip to content

Conversation

mtreinish
Copy link
Member

@mtreinish mtreinish commented May 21, 2020

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:

  • Fix all the lint failures
  • Fix test failures (points to more backwards incompatibilities with BasicAer during transition
  • Add tests for new provider interface
  • Expand documentation with examples
  • Figure out backwards compat for backend.configuration() and backend.properties()
  • Figure out pulse pieces (currently only circuits is handled) maybe a second commit

Implements Qiskit/RFCs#2
Fixes #4105

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
@mtreinish mtreinish requested review from jyu00 and a team as code owners May 21, 2020 19:13
mtreinish added a commit to mtreinish/qiskit-core that referenced this pull request May 27, 2020
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.
@mtreinish mtreinish mentioned this pull request May 27, 2020
# v2 Providers Backend
if isinstance(backend, Backend):
start_time = time()
backend.set_configuration(shots=shots, **run_config)
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. 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
  2. It'll need to pass more of the keywords (e.g. meas_level and meas_return) than just shots and run_config.

Copy link
Member Author

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().

@jyu00
Copy link
Contributor

jyu00 commented May 27, 2020

To summarize, the new backend behaviors are now:
v1/backend.configuration() is now v2/backend.target
v1/backend.properties() is now v2/backend.properties
v2/backend.configuration defines dynamic backend parameters for the experiments

Is this correct?

@mtreinish
Copy link
Member Author

To summarize, the new backend behaviors are now:
v1/backend.configuration() is now v2/backend.target
v1/backend.properties() is now v2/backend.properties
v2/backend.configuration defines dynamic backend parameters for the experiments

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 backend.configuration() for ibmq returns more fields than that. I was thinking those could be set as properties on the Backend subclass we define in the provider, but we can put them anywhere that makes sense since it's not used.

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).

@mtreinish
Copy link
Member Author

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 options instead of configuration (which is what @chriseclectic did in Qiskit/qiskit-aer#486 ).

@jyu00
Copy link
Contributor

jyu00 commented May 27, 2020

The current backend.configuration() for ibmq returns more fields than that. I was thinking those could be set as properties on the Backend subclass we define in the provider, but we can put them anywhere that makes sense since it's not used.

backend.properties() today returns only the calibration data. I think it'd be better not to mix existing configuration fields with properties to avoid confusion and, in the case of ibmq, unnecessary trip to the server (properties and configuration are returned by separate endpoints today).

But for example we could change the dynamic stuff to use options instead of configuration

If the naming is flexible, can we leave properties and configuration as-is? The new backend.target will be a subset of configuration for the transpiler. And the dynamic stuff will be backend.options or backend.parameters (which is what I've been using for the "configurable backend"). This would also make migration easier.

@mtreinish
Copy link
Member Author

The current backend.configuration() for ibmq returns more fields than that. I was thinking those could be set as properties on the Backend subclass we define in the provider, but we can put them anywhere that makes sense since it's not used.

backend.properties() today returns only the calibration data. I think it'd be better not to mix existing configuration fields with properties to avoid confusion and, in the case of ibmq, unnecessary trip to the server (properties and configuration are returned by separate endpoints today).

Sorry I worded that poorly, I meant as python properties of the Backend subclass, not attributes of the Properties class. I intended properties to remain the same basically be only calibration data. Heh, this is why getting the naming right here is important :)

mtreinish added a commit to mtreinish/rfcs that referenced this pull request Jun 12, 2020
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.
@ajavadia ajavadia added this to the 0.15 milestone Jun 18, 2020
@kdk kdk removed this from the 0.15 milestone Jun 30, 2020
mergify bot added a commit that referenced this pull request Jul 7, 2020
* 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>
faisaldebouni pushed a commit to faisaldebouni/qiskit-terra that referenced this pull request Aug 5, 2020
* 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>
@1ucian0 1ucian0 marked this pull request as draft August 27, 2020 21:05
mtreinish added a commit to mtreinish/qiskit-core that referenced this pull request Sep 18, 2020
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.
mergify bot added a commit that referenced this pull request Oct 6, 2020
* 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>
@mtreinish
Copy link
Member Author

mtreinish commented Feb 18, 2021

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.

@mtreinish mtreinish closed this Feb 18, 2021
mergify bot pushed a commit that referenced this pull request Mar 30, 2021
* 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>
ElePT pushed a commit to ElePT/qiskit-algorithms that referenced this pull request Jul 27, 2023
…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>
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.

Qiskit Services API
5 participants