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 qubit_properties to Target class #7736

Merged
merged 6 commits into from
Mar 31, 2022
Merged

Conversation

mtreinish
Copy link
Member

Summary

This commit adds a new attribute to the target class for defining qubit
properties. This was originally not included in the target because
nothing in the transpiler supports using any qubit properties. However,
in a future PR I'm planning to modify the default heuristic layout score
used by VF2Layout to factor in T1 and/or T2 in addition to the
measurement error rate it's using now. To do this though we need to
ensure that we have these values available via the target. This commit
also is the first time we've had to expand the set of information that
can optionally be pecified in a target. I opted to just make a straight
addition here rather than versioning it. There should be no backwards
compatibility issue for users or provider maintainers on upgrade because
not specifying a qubit properties payload will not change any behavior
the Target and BackendV2 objects will behave exactly as before.

I was thinking we'd only use a version if we needed to make a backwards
incompatible change in the future. That way we can support both versions
of the class a the same time while we migrated to a newer interface. But
for simple additions like this that don't effect the behavior or cause
any issues with compatibility we can simply add them to the class.

Details and comments

This commit adds a new attribute to the target class for defining qubit
properties. This was originally not included in the target because
nothing in the transpiler supports using any qubit properties. However,
in a future PR I'm planning to modify the default heuristic layout score
used by VF2Layout to factor in T1 and/or T2 in addition to the
measurement error rate it's using now. To do this though we need to
ensure that we have these values available via the target. This commit
also is the first time we've had to expand the set of information that
can optionally be pecified in a target. I opted to just make a straight
addition here rather than versioning it. There should be no backwards
compatibility issue for users or provider maintainers on upgrade because
not specifying a qubit properties payload will not change any behavior
the Target and BackendV2 objects will behave exactly as before.

I was thinking we'd only use a version if we needed to make a backwards
incompatible change in the future. That way we can support both versions
of the class a the same time while we migrated to a newer interface. But
for simple additions like this that don't effect the behavior or cause
any issues with compatibility we can simply add them to the class.
@mtreinish mtreinish added the Changelog: New Feature Include in the "Added" section of the changelog label Mar 4, 2022
@mtreinish mtreinish added this to the 0.20 milestone Mar 4, 2022
@mtreinish mtreinish requested review from a team and jyu00 as code owners March 4, 2022 14:42
@coveralls
Copy link

coveralls commented Mar 4, 2022

Pull Request Test Coverage Report for Build 2069003425

  • 15 of 18 (83.33%) changed or added relevant lines in 4 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.004%) to 83.774%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/providers/backend.py 4 5 80.0%
qiskit/transpiler/target.py 5 7 71.43%
Totals Coverage Status
Change from base Build 2069001728: 0.004%
Covered Lines: 53731
Relevant Lines: 64138

💛 - Coveralls

Copy link
Collaborator

@HuangJunye HuangJunye left a comment

Choose a reason for hiding this comment

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

The PR looks good to me based on my limited experience of BackendV2. I would like to know whether I should update my PR #7643 to reflect the changes here after this PR is merged. I was initially planning to rename the backends in fake_backend_v2.py to avoid confusion with the new FakeBackendV2 I created, but perhaps that can be made in a follow up PR separately. What do you think? @mtreinish

Comment on lines +30 to +33
# import QubitProperties here to provide convenience alias for building a
# full target
from qiskit.providers.backend import QubitProperties # pylint: disable=unused-import

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't fully understand the motivation of this line. Can you explain a bit more?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's a convenience thing since QubitProperties is now optionally part of a target I thought it would be good to have a single import for everything needed to make a taget. This is just to enable someone creating a Target object to do:

from qiskit.transpiler.target import Target, InstructionProperties, QubitProperties

instead of:

from qiskit.transpiler.target import Target, InstructionProperties
from qiskit.providers.backend import QubitProperties

(although the latter will still work even with this.)

But, it is a bit weird to do this, so I'm not really tied to it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

That makes a lot of sense. It's much more convenient this way.

Comment on lines 184 to 185
class FakeBackendSimple(BackendV2):
"""A fake simple backend that wraps BasicAer to implement run()."""
Copy link
Collaborator

Choose a reason for hiding this comment

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

This was not introduced by this PR but I think it would be good to explain in the docstring the difference between FakeBackendV2 and FakeBackendSimple.

@mtreinish
Copy link
Member Author

The PR looks good to me based on my limited experience of BackendV2. I would like to know whether I should update my PR #7643 to reflect the changes here after this PR is merged.

Yeah if we merge this before #7643 it would be good to update the #7643 to include the QubitProperties in the Target (it should be a minimal change). But if #7643 merges first I'll take care of updating the fake objects in this PR.

I was initially planning to rename the backends in fake_backend_v2.py to avoid confusion with the new FakeBackendV2 I created, but perhaps that can be made in a follow up PR separately. What do you think? @mtreinish

I think we can do that in a follow up to #7643. For #7643 I think it would be good if we just keep the PR to adding a v2 implementation of the fake backends (which will be a big enough change on its own). Cleanups like renaming things are small enough that they should be quick PRs.

qiskit/transpiler/target.py Outdated Show resolved Hide resolved
This commit removes an unecessary getter method to access the
qubit_properties attribute of the target. The attribute was already
public and we could get the qubit properties directly from the list
stored in the target.
Copy link
Contributor

@itoko itoko left a comment

Choose a reason for hiding this comment

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

LGTM. Could you write up reno?

@mtreinish
Copy link
Member Author

LGTM. Could you write up reno?

Oops, not sure how I forgot that. Added in d4e0fd4

Copy link
Contributor

@itoko itoko left a comment

Choose a reason for hiding this comment

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

Thanks!

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.

5 participants