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 fake generic and modify tests #10266

Merged
merged 65 commits into from
Jan 29, 2024

Conversation

MozammilQ
Copy link
Contributor

@MozammilQ MozammilQ commented Jun 12, 2023

Summary

(1/4) --> This is the first PR of the FakeBackends refactoring epic.

This PR adds a FakeGeneric(BackendV2) backend for qiskit unit testing purposes. It only updates the uses of V2 FakeBackends in test/python/compiler/test_transpiler.py. The rest of the unit tests using V2 fake backends are updated in #10918.

Details and comments

Note: I can move the GenericTarget class to an independent file once the approach is agreed upon and I am still not 100% convinced by the FakeGeneric name for the backend.

…th instruction_dict in fake_generic.py; added support of grid type of coupling map; using lower number of qubits, passed all tests of test_transpiler except one method ( test_parallel_dispatch_lazy_cal_loading )
@MozammilQ MozammilQ requested review from a team and jyu00 as code owners June 12, 2023 17:41
@qiskit-bot qiskit-bot added the Community PR PRs from contributors that are not 'members' of the Qiskit repo label Jun 12, 2023
@qiskit-bot
Copy link
Collaborator

Thank you for opening a new pull request.

Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient.

While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone.

One or more of the the following people are requested to review this:

  • @Qiskit/terra-core

@MozammilQ
Copy link
Contributor Author

@HuangJunye, I humbly request you to see if this is good enough :)

@HuangJunye HuangJunye self-assigned this Jun 13, 2023
@HuangJunye
Copy link
Collaborator

@HuangJunye, I humbly request you to see if this is good enough :)

Thanks for submitting the PR. I will review it.

This PR is part of QAMP Spring 23: qiskit-advocate/qamp-spring-23#26

Copy link
Contributor

@atharva-satpute atharva-satpute left a comment

Choose a reason for hiding this comment

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

Please fix the typos

qiskit/providers/fake_provider/fake_generic.py Outdated Show resolved Hide resolved
qiskit/providers/fake_provider/fake_generic.py Outdated Show resolved Hide resolved
test/python/providers/fake_provider/test_fake_generic.py Outdated Show resolved Hide resolved
test/python/providers/fake_provider/test_fake_generic.py Outdated Show resolved Hide resolved
@MozammilQ
Copy link
Contributor Author

@atharva-satpute , done with the changes :)

@HuangJunye
Copy link
Collaborator

@MozammilQ Thanks for the awesome work here! Qiskit core developers really like it. Is it ok for them to take over the PR to finish it up?

@MozammilQ
Copy link
Contributor Author

To Qiskit Core developers: Thanks for the kind consideration, this work is not possible without the kind guidance of my mentor @HuangJunye , credit to any such work goes to him ! :)

@HuangJunye , around the time we last talked, I did some further work and did some more commits, today I have opened a draft PR for that work.
Here it is:
#10942
#10943

@MozammilQ
Copy link
Contributor Author

@HuangJunye , Yes, it is ok for Qiskit Core to take over the PR to finish it up!!

@HuangJunye
Copy link
Collaborator

To Qiskit Core developers: Thanks for the kind consideration, this work is not possible without the kind guidance of my mentor @HuangJunye , credit to any such work goes to him ! :)

@HuangJunye , around the time we last talked, I did some further work and did some more commits, today I have opened a draft PR for that work. Here it is: #10942 #10943

Great. Thank you for adding the new work as well. The core team will take a look and work with them too.

Copy link
Contributor

@ElePT ElePT left a comment

Choose a reason for hiding this comment

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

Thank you very much @MozammilQ for your contribution. I have added a couple of commits to try to get the PR up to speed, and will now add some comments for reference of the dev. team (no need to act on them) @HuangJunye.

qiskit/providers/fake_provider/fake_generic.py Outdated Show resolved Hide resolved
@ElePT
Copy link
Contributor

ElePT commented Jan 27, 2024

Thanks for the feedback, I have addressed all of the review comments in 54496db, except for the backend name. I think that the candidates are:

  • ConfigurableFakeBackend or ConfigurableFakeBackendV2
  • GenericBackend or GenericBackendV2
  • GenericFakeBackend or GenericFakeBackendV2

I am fine settling for GenericBackendV2, if that seems like a better option.

@ElePT
Copy link
Contributor

ElePT commented Jan 29, 2024

I've renamed it to GenericBackendV2 in a36acaf. The module docs are still improvable, but I was planning to update them in #11376 once the deprecated classes are out, and include the examples that are currently in the release note.

Copy link
Contributor

@kevinhartman kevinhartman left a comment

Choose a reason for hiding this comment

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

Looking good, a few minor comments / typos.

qiskit/providers/fake_provider/fake_generic.py Outdated Show resolved Hide resolved
qiskit/providers/fake_provider/fake_generic.py Outdated Show resolved Hide resolved
qiskit/providers/fake_provider/fake_generic.py Outdated Show resolved Hide resolved
]


class GenericFakeBackend(BackendV2):
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess the way I see it is, if you don't need a simulator, subclassing this thing won't do anything for you, in which case you really ought to define your own subclass. The name GenericBackendV2 is fine assuming the term "generic" implies "simulator-based", I'm just less convinced that this is a minimal implementor of BackendV2.

basis_gates if basis_gates is not None else ["cx", "id", "rz", "sx", "x"]
)
for name in ["reset", "delay", "measure"]:
if name not in self._basis_gates:
Copy link
Contributor

Choose a reason for hiding this comment

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

One trick I found when working in my branch was to use Target.operation_names to test for instruction presence in constant time. That's backed by a dictionary, I believe, so it's insertion ordered and should side-step the non-determinism issues you were seeing before.

(Not important for this PR IMO given that basis_gates often small, but perhaps a helpful pattern for the future.)

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, the issue here is that we are constructing a target, so we cannot access its gate map yet... but I see your point, will keep it in mind :)

qiskit/providers/fake_provider/fake_generic.py Outdated Show resolved Hide resolved
qiskit/providers/fake_provider/fake_generic.py Outdated Show resolved Hide resolved
test/python/compiler/test_transpiler.py Outdated Show resolved Hide resolved
kevinhartman
kevinhartman previously approved these changes Jan 29, 2024
Copy link
Contributor

@kevinhartman kevinhartman left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for seeing this through @ElePT and @MozammilQ for your contributions.

ElePT
ElePT previously approved these changes Jan 29, 2024
Copy link
Contributor

@ElePT ElePT left a comment

Choose a reason for hiding this comment

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

The approval was dismissed after fixing a last-minute merge conflict, so I'm re-approving to get it back in the queue :)

@kevinhartman
Copy link
Contributor

Looks like another merge issue. I'll resolve this and push shortly.

@jakelishman
Copy link
Member

The problems are likely a minor logical merge conflict with new tests added in #11554, and no inherent problem.

@kevinhartman kevinhartman added this pull request to the merge queue Jan 29, 2024
Merged via the queue into Qiskit:main with commit b4582a9 Jan 29, 2024
12 checks passed
@ElePT
Copy link
Contributor

ElePT commented Jan 29, 2024

@Mergifyio backport stable/0.46

Copy link
Contributor

mergify bot commented Jan 29, 2024

backport stable/0.46

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Jan 29, 2024
* Added a FakeGeneric BackendV2 backend, this is just a bare minimum working code

* All FakeBackends (like FakeMelbourne, FakeBoeblingen ,etc) is replaced with FakeGeneric

* relocated FakeGeneric in fake_provider directory; replaced if-elif with instruction_dict in fake_generic.py; added support of grid type of coupling map; using lower number of qubits, passed all tests of test_transpiler except one method ( test_parallel_dispatch_lazy_cal_loading )

* added tests for FakeGeneric

* This commit just reformats test_transpiler.py fake_generic.py and test_fake_generic.py

* Update qiskit/providers/fake_provider/fake_generic.py

Co-authored-by: atharva-satpute <[email protected]>

* Update qiskit/providers/fake_provider/fake_generic.py

Co-authored-by: atharva-satpute <[email protected]>

* Update test/python/providers/fake_provider/test_fake_generic.py

Co-authored-by: atharva-satpute <[email protected]>

* Update test/python/providers/fake_provider/test_fake_generic.py

Co-authored-by: atharva-satpute <[email protected]>

* Fix some tests

* Add calibration schedules, fix transpiler tests

* Fix lint

* Refactor, add pulse functionality

* Latest updates to FakeGeneric

* Fix some unit tests

* Fix some unit tests

* Fix tests, lint, refactor

* Remove unused inputs

* Make calibrations optional

* Attempt to speed up test: only add calibrations if option enabled

* Revert some tests to V1

* Refactor FakeGeneric

* Update unit test

* Rename supported instructions to operations, fix tests

Fix test seed

Fix unit test, lint

* Restore vf2postlayout test to V1

Fx vf2 test

* Add pulse test to validate pulse capabilities of new fake backend

Update fake generic

* Update docs, fix lint

* Avoid set for basis gates to allow reproducibility in the error/duration value generation

* Update calibrations

* Fix transpiler test

* Add run test to confirm noise defaults

* Add CZ to basis gates, dtm, update backend names, fix docs

* Remove GenericTarget, add default for basis_gates, remove supported_operations.

* Apply review comments, modify calibrate_instructions to avoid public calibration method.

* New name proposal

* Fix lint and test

* Fix comment

* Apply Kevin's suggestions to extract defaults from class

* Make defaults private

* Fix lint

* Revert previous 3 comments.

* Privatize GenericFakeBackend

* Remove from docs

* Revert privatization

* Apply review comments

* Add reno

* Fix lint

* Apply suggestions from Matt's code review

Co-authored-by: Matthew Treinish <[email protected]>

* Apply comments from code review

* Fix lint

* Rename to GenericBackendV2 and adjust docs.

* Fix lint

* Apply comments from code review

* It's not 2023 anymore

* Fix conflict

* Fix test conflict.

---------

Co-authored-by: atharva-satpute <[email protected]>
Co-authored-by: Elena Peña Tapia <[email protected]>
Co-authored-by: Elena Peña Tapia <[email protected]>
Co-authored-by: Matthew Treinish <[email protected]>
Co-authored-by: Kevin Hartman <[email protected]>
(cherry picked from commit b4582a9)

# Conflicts:
#	qiskit/providers/fake_provider/__init__.py
#	test/python/compiler/test_transpiler.py
github-merge-queue bot pushed a commit that referenced this pull request Jan 30, 2024
* Add fake generic and modify tests (#10266)

* Added a FakeGeneric BackendV2 backend, this is just a bare minimum working code

* All FakeBackends (like FakeMelbourne, FakeBoeblingen ,etc) is replaced with FakeGeneric

* relocated FakeGeneric in fake_provider directory; replaced if-elif with instruction_dict in fake_generic.py; added support of grid type of coupling map; using lower number of qubits, passed all tests of test_transpiler except one method ( test_parallel_dispatch_lazy_cal_loading )

* added tests for FakeGeneric

* This commit just reformats test_transpiler.py fake_generic.py and test_fake_generic.py

* Update qiskit/providers/fake_provider/fake_generic.py

Co-authored-by: atharva-satpute <[email protected]>

* Update qiskit/providers/fake_provider/fake_generic.py

Co-authored-by: atharva-satpute <[email protected]>

* Update test/python/providers/fake_provider/test_fake_generic.py

Co-authored-by: atharva-satpute <[email protected]>

* Update test/python/providers/fake_provider/test_fake_generic.py

Co-authored-by: atharva-satpute <[email protected]>

* Fix some tests

* Add calibration schedules, fix transpiler tests

* Fix lint

* Refactor, add pulse functionality

* Latest updates to FakeGeneric

* Fix some unit tests

* Fix some unit tests

* Fix tests, lint, refactor

* Remove unused inputs

* Make calibrations optional

* Attempt to speed up test: only add calibrations if option enabled

* Revert some tests to V1

* Refactor FakeGeneric

* Update unit test

* Rename supported instructions to operations, fix tests

Fix test seed

Fix unit test, lint

* Restore vf2postlayout test to V1

Fx vf2 test

* Add pulse test to validate pulse capabilities of new fake backend

Update fake generic

* Update docs, fix lint

* Avoid set for basis gates to allow reproducibility in the error/duration value generation

* Update calibrations

* Fix transpiler test

* Add run test to confirm noise defaults

* Add CZ to basis gates, dtm, update backend names, fix docs

* Remove GenericTarget, add default for basis_gates, remove supported_operations.

* Apply review comments, modify calibrate_instructions to avoid public calibration method.

* New name proposal

* Fix lint and test

* Fix comment

* Apply Kevin's suggestions to extract defaults from class

* Make defaults private

* Fix lint

* Revert previous 3 comments.

* Privatize GenericFakeBackend

* Remove from docs

* Revert privatization

* Apply review comments

* Add reno

* Fix lint

* Apply suggestions from Matt's code review

Co-authored-by: Matthew Treinish <[email protected]>

* Apply comments from code review

* Fix lint

* Rename to GenericBackendV2 and adjust docs.

* Fix lint

* Apply comments from code review

* It's not 2023 anymore

* Fix conflict

* Fix test conflict.

---------

Co-authored-by: atharva-satpute <[email protected]>
Co-authored-by: Elena Peña Tapia <[email protected]>
Co-authored-by: Elena Peña Tapia <[email protected]>
Co-authored-by: Matthew Treinish <[email protected]>
Co-authored-by: Kevin Hartman <[email protected]>
(cherry picked from commit b4582a9)

# Conflicts:
#	qiskit/providers/fake_provider/__init__.py
#	test/python/compiler/test_transpiler.py

* Update __init__.py

* Update test_transpiler.py

* Update test_transpiler.py

* Fix conflicts (#11673)

* Rename test, switch to basic simulator

* Fix bug in pulse default generation

---------

Co-authored-by: MozammilQ <[email protected]>
Co-authored-by: Elena Peña Tapia <[email protected]>
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 Community PR PRs from contributors that are not 'members' of the Qiskit repo
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Add generic Fake Backends and update use in Qiskit unit tests
9 participants