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

Add lightweight v2 provider interface starter #5086

Merged
merged 41 commits into from
Oct 6, 2020

Conversation

mtreinish
Copy link
Member

Summary

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.

Details and comments

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.
@mtreinish mtreinish requested review from jyu00 and a team as code owners September 18, 2020 17:55
@mtreinish
Copy link
Member Author

So this is blocked on aqua doing explicit type checking in its quantum instance for a BaseBackend class and Basic Aer's backends being a v2 Backend object. I think this means we'll have to split out the basic aer v2 conversion to post release. Then we can merge v2 provider support to aqua after this merges. Then there shouldn't be a blocker on this anymore.

@1ucian0 1ucian0 marked this pull request as draft September 22, 2020 20:20
mtreinish added a commit to mtreinish/aqua that referenced this pull request Sep 24, 2020
In Qiskit/qiskit#5086 the v2 provider interface is being added.
This starter interface is basically a drop in replacement for the v1
interface with 3 changes it's explicitly versioned at the object level,
Backend.run() can take in a circuit object, and Job objects can also be
async or sync. Eventually the interace will likely evolve towards a
model similar to what was initially done in Qiskit/qiskit#4885.
This commit adds initial support for v2 provider backend objects, the
explicit type checking for BaseBackend objects is blocking the terra PR
from moving forward (because it switched BasicAer to use the v2
interface). This initial support just means accepting v2 Backend objects
in addition to v1 BaseBackend objects.

Depends on Qiskit/qiskit#5086
@mtreinish mtreinish changed the title [WIP] Add lightweight v2 provider interface starter Add lightweight v2 provider interface starter Sep 24, 2020
@mtreinish mtreinish marked this pull request as ready for review September 24, 2020 16:21
@mtreinish mtreinish added this to the 0.16 milestone Sep 24, 2020
@mtreinish mtreinish added the Changelog: New Feature Include in the "Added" section of the changelog label Sep 24, 2020
@mtreinish
Copy link
Member Author

I've removed the basicaer changes that switched the basic aer provider to be the first user of the v2 providers interface. This worksaround the tutorials job failure. I also pushed up qiskit-community/qiskit-aqua#1270 to add support for type checking v2 Backend classes to aqua. After this PR merges we can merge the aqua PR. Then after both terra and aqua release I'll push up a PR migrating basic aer to use the v2 interface (we can also start the migration of aer and ibmq too).

qiskit/providers/v2/backend.py Outdated Show resolved Hide resolved
qiskit/providers/v2/job.py Outdated Show resolved Hide resolved
qiskit/providers/v2/options.py Outdated Show resolved Hide resolved
qiskit/providers/v2/options.py Outdated Show resolved Hide resolved
qiskit/providers/v2/options.py Outdated Show resolved Hide resolved
qiskit/providers/v2/job.py Outdated Show resolved Hide resolved
qiskit/providers/v2/provider.py Outdated Show resolved Hide resolved
Copy link
Member

@ajavadia ajavadia left a comment

Choose a reason for hiding this comment

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

i'm a little confused by v1 vs. v2 - there's a v2 folder, is the intention that there will be v3, v4, etc. folders in the future? or by v2 you mean "everything that will be versioned from now on"?

also ProviderV1 is under the v2 folder. If the idea is that ProviderV2, ProviderV3, etc. will all be in this folder, then I think this folder is a bit redundant and everything should be under the main provider folder.

qiskit/providers/v2/backend.py Outdated Show resolved Hide resolved
def __init__(self, **kwargs):
self.data = kwargs if kwargs else {}

def update_options(self, **fields):
Copy link
Member

Choose a reason for hiding this comment

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

is it possible to make them into attributes of Options so updating them looks like backend.options.shots=2000?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, @jyu00's suggestion above about using SimpleNamespace should enable that pattern for setting it. I'd still like to keep the method because it has the membership check with a custom exception.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you still need a @options.setter in Backend to do backend.options.shots, since right now _options is the real attribute. Maybe just convert set_options() to a setter?

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 think it should be good in it's current form because there is a @parameter decorator on options. So backend.options will return the Options object and then .shots = will call setattr on that object. If we added a setter on options to Backend it would be called when Backend.options =. I do think I should try to figure out if there is a way to add a __setattr__ method to this class to call update_options since right now you could call Backend.options.secret_shots = 10 and that would get set even though its probably not a valid option. But, maybe that's not a problem

qiskit/providers/v2/job.py Outdated Show resolved Hide resolved
Comment on lines 204 to 206
For v1 providers migrating to this first version of a v2
provider interface a :class:`~qiskit.qobj.QasmQobj` or
:class:`~qiskit.qobj.PulseQobj` object. These will be
Copy link
Member

Choose a reason for hiding this comment

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

this sentence seems incomplete

Copy link
Member

Choose a reason for hiding this comment

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

do you mean a QasmQobj and PulseQobj will be supported for now? but the type in docstring doesn't say that

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops yeah I missed that. I'll fix it now.

I didn't want to put Qobj in the docstring type because I didn't want to encourage its use for new providers. But, I still wanted to call out anyone migrating from v1 to v2 should probably still support Qobj (but deprecate it) objects for backwards compatibility reasons.

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 updated it here: 523fba9 hopefully it makes more sense now

@mergify mergify bot merged commit 900c048 into Qiskit:master Oct 6, 2020
mtreinish added a commit to mtreinish/aqua that referenced this pull request Oct 6, 2020
In Qiskit/qiskit#5086 the v2 provider interface is being added.
This starter interface is basically a drop in replacement for the v1
interface with 3 changes it's explicitly versioned at the object level,
Backend.run() can take in a circuit object, and Job objects can also be
async or sync. Eventually the interace will likely evolve towards a
model similar to what was initially done in Qiskit/qiskit#4885.
This commit adds initial support for v2 provider backend objects, the
explicit type checking for BaseBackend objects is blocking the terra PR
from moving forward (because it switched BasicAer to use the v2
interface). This initial support just means accepting v2 Backend objects
in addition to v1 BaseBackend objects.

Depends on Qiskit/qiskit#5086
manoelmarques added a commit to qiskit-community/qiskit-aqua that referenced this pull request Oct 6, 2020
* Add support for v2 provider interface

In Qiskit/qiskit#5086 the v2 provider interface is being added.
This starter interface is basically a drop in replacement for the v1
interface with 3 changes it's explicitly versioned at the object level,
Backend.run() can take in a circuit object, and Job objects can also be
async or sync. Eventually the interace will likely evolve towards a
model similar to what was initially done in Qiskit/qiskit#4885.
This commit adds initial support for v2 provider backend objects, the
explicit type checking for BaseBackend objects is blocking the terra PR
from moving forward (because it switched BasicAer to use the v2
interface). This initial support just means accepting v2 Backend objects
in addition to v1 BaseBackend objects.

Depends on Qiskit/qiskit#5086

* Fix import path

* fix style

Co-authored-by: Manoel Marques <manoel.marques@ibm.com>
@mtreinish mtreinish deleted the v2-providers-lite branch October 7, 2020 13:10
mtreinish added a commit to mtreinish/qiskit-aer that referenced this pull request Oct 7, 2020
Since Qiskit/qiskit#5086 merged the aer CI jobs have been failing.
It looks like it's because pylint can't find the pybind modules. I'm not
sure how Qiskit/qiskit#5086 changed things, but this commit tries
to fix it by installing aer in the pylint job.
chriseclectic added a commit to chriseclectic/qiskit-aer that referenced this pull request Oct 8, 2020
Qiskit/qiskit#5086 seemd to break pylint testing by preventing the Aer package from being found by pylint without building and installing. This fixes the issue by replacing all absolute imports in Aer with relative module imports. This is a work around until general namespace packaging issues are implemented to move all of Aer into its own namespace.
chriseclectic added a commit to Qiskit/qiskit-aer that referenced this pull request Oct 8, 2020
Qiskit/qiskit#5086 seemd to break pylint testing by preventing the Aer package from being found by pylint without building and installing. This fixes the issue by replacing all absolute imports in Aer with relative module imports. This is a work around until general namespace packaging issues are implemented to move all of Aer into its own namespace.
mtreinish added a commit to mtreinish/qiskit-core that referenced this pull request Nov 20, 2020
)

* Add support for v2 provider interface

In Qiskit#5086 the v2 provider interface is being added.
This starter interface is basically a drop in replacement for the v1
interface with 3 changes it's explicitly versioned at the object level,
Backend.run() can take in a circuit object, and Job objects can also be
async or sync. Eventually the interace will likely evolve towards a
model similar to what was initially done in Qiskit#4885.
This commit adds initial support for v2 provider backend objects, the
explicit type checking for BaseBackend objects is blocking the terra PR
from moving forward (because it switched BasicAer to use the v2
interface). This initial support just means accepting v2 Backend objects
in addition to v1 BaseBackend objects.

Depends on Qiskit#5086

* Fix import path

* fix style

Co-authored-by: Manoel Marques <manoel.marques@ibm.com>
manoelmarques added a commit to manoelmarques/qiskit-terra that referenced this pull request Nov 23, 2020
)

* Add support for v2 provider interface

In Qiskit#5086 the v2 provider interface is being added.
This starter interface is basically a drop in replacement for the v1
interface with 3 changes it's explicitly versioned at the object level,
Backend.run() can take in a circuit object, and Job objects can also be
async or sync. Eventually the interace will likely evolve towards a
model similar to what was initially done in Qiskit#4885.
This commit adds initial support for v2 provider backend objects, the
explicit type checking for BaseBackend objects is blocking the terra PR
from moving forward (because it switched BasicAer to use the v2
interface). This initial support just means accepting v2 Backend objects
in addition to v1 BaseBackend objects.

Depends on Qiskit#5086

* Fix import path

* fix style

Co-authored-by: Manoel Marques <manoel.marques@ibm.com>
manoelmarques added a commit to manoelmarques/qiskit-terra that referenced this pull request Dec 2, 2020
)

* Add support for v2 provider interface

In Qiskit#5086 the v2 provider interface is being added.
This starter interface is basically a drop in replacement for the v1
interface with 3 changes it's explicitly versioned at the object level,
Backend.run() can take in a circuit object, and Job objects can also be
async or sync. Eventually the interace will likely evolve towards a
model similar to what was initially done in Qiskit#4885.
This commit adds initial support for v2 provider backend objects, the
explicit type checking for BaseBackend objects is blocking the terra PR
from moving forward (because it switched BasicAer to use the v2
interface). This initial support just means accepting v2 Backend objects
in addition to v1 BaseBackend objects.

Depends on Qiskit#5086

* Fix import path

* fix style

Co-authored-by: Manoel Marques <manoel.marques@ibm.com>
manoelmarques added a commit to manoelmarques/qiskit-terra that referenced this pull request Dec 7, 2020
)

* Add support for v2 provider interface

In Qiskit#5086 the v2 provider interface is being added.
This starter interface is basically a drop in replacement for the v1
interface with 3 changes it's explicitly versioned at the object level,
Backend.run() can take in a circuit object, and Job objects can also be
async or sync. Eventually the interace will likely evolve towards a
model similar to what was initially done in Qiskit#4885.
This commit adds initial support for v2 provider backend objects, the
explicit type checking for BaseBackend objects is blocking the terra PR
from moving forward (because it switched BasicAer to use the v2
interface). This initial support just means accepting v2 Backend objects
in addition to v1 BaseBackend objects.

Depends on Qiskit#5086

* Fix import path

* fix style

Co-authored-by: Manoel Marques <manoel.marques@ibm.com>
manoelmarques added a commit to qiskit-community/qiskit-optimization that referenced this pull request Jan 14, 2021
)

* Add support for v2 provider interface

In Qiskit/qiskit#5086 the v2 provider interface is being added.
This starter interface is basically a drop in replacement for the v1
interface with 3 changes it's explicitly versioned at the object level,
Backend.run() can take in a circuit object, and Job objects can also be
async or sync. Eventually the interace will likely evolve towards a
model similar to what was initially done in Qiskit/qiskit#4885.
This commit adds initial support for v2 provider backend objects, the
explicit type checking for BaseBackend objects is blocking the terra PR
from moving forward (because it switched BasicAer to use the v2
interface). This initial support just means accepting v2 Backend objects
in addition to v1 BaseBackend objects.

Depends on Qiskit/qiskit#5086

* Fix import path

* fix style

Co-authored-by: Manoel Marques <manoel.marques@ibm.com>
@mtreinish mtreinish mentioned this pull request Feb 18, 2021
6 tasks
manoelmarques added a commit to qiskit-community/qiskit-machine-learning that referenced this pull request Feb 27, 2021
)

* Add support for v2 provider interface

In Qiskit/qiskit#5086 the v2 provider interface is being added.
This starter interface is basically a drop in replacement for the v1
interface with 3 changes it's explicitly versioned at the object level,
Backend.run() can take in a circuit object, and Job objects can also be
async or sync. Eventually the interace will likely evolve towards a
model similar to what was initially done in Qiskit/qiskit#4885.
This commit adds initial support for v2 provider backend objects, the
explicit type checking for BaseBackend objects is blocking the terra PR
from moving forward (because it switched BasicAer to use the v2
interface). This initial support just means accepting v2 Backend objects
in addition to v1 BaseBackend objects.

Depends on Qiskit/qiskit#5086

* Fix import path

* fix style

Co-authored-by: Manoel Marques <manoel.marques@ibm.com>
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
Changelog: New Feature Include in the "Added" section of the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants