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 BackendV2 mocked backend #7643

Merged
merged 109 commits into from
Mar 31, 2022
Merged

Add BackendV2 mocked backend #7643

merged 109 commits into from
Mar 31, 2022

Conversation

HuangJunye
Copy link
Collaborator

@HuangJunye HuangJunye commented Feb 10, 2022

Summary

Still work in progress. Create mocked backends based on new BackendV2. These mocked backends are useful for testing purposes.

Fixes #7391

To do

Follow up issues

Details and comments

Added

  • Added new FakeBackendV2 class that builds BackendV2 object and itsTarget using IBM Quantum System snapshots json files (configuration, properties and pulse defaults)
    • The FakeBackendV2 removes the distinction of QasmBackend and PulseBackend. It also get rids of the usage of QasmBackendConfiguration, PulseBackendConfiguration, BackendProperties (except in run method) objects and FakeQasmBackend and FakePulseBackend classes that were introduced due to historical reasons.
    • Implemented target, dtm, meas_map, qubit_properties, max_circuits attributes for BackendV2 class. Pulse channels (drive_channel, measure_channel, acquire_channel, control_channel) are not implemented.
    • Implemented run method. Added _get_noise_model_from_backend_v2 method to generate NoiseModel for noisy simulation as a work-around until Are supports V2 backend. [Issue]
  • Added backend_converter.py written by Matthew under qiskit.test.mock.utils for converting Target object using configuration, properties and pulse defaults dictionary.
  • Added V2 versions of all existing fake backends except the following because no snapshots are available. [Issue]
    • Tokyo
    • Tenerife
    • Rueschlikon
    • CambridgeAlternativeBasis (not relevant anymore)
  • Added FakeProviderV2 to contain all FakeBackendV2 for testing.
  • Added test_circuit_on_fake_backend_v2 in test.python.providers.test_fake_backends.py for testing fake v2 backends.

Changed

  • Removed import of ConfigurableFakeBackend in qiskit.test.mock.utils.__init__.py to resolve circular import issue. Import statements across files where ConfigurableFakeBackend are used were also changed.

@HuangJunye HuangJunye requested a review from a team as a code owner February 10, 2022 10:41
@HuangJunye HuangJunye marked this pull request as draft February 10, 2022 10:43
@HuangJunye HuangJunye changed the title [WIP] Add v2 mocked backend 7391 [WIP] Add BackendV2 mocked backend Feb 10, 2022
Copy link
Member

@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

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

This LGTM, just one last minute thing I just remembered we're going to need to fix around the FakeMumbaiV2 name. Once that's done I think this is ready.

qiskit/test/mock/backends/__init__.py Show resolved Hide resolved
Copy link
Member

@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

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

One other thing I just remembered while reviewing #7839 should we need to expose the new FakeProviderV2 class from https://github.com/Qiskit/qiskit-terra/blob/main/qiskit/providers/fake_provider/__init__.py

return self.fake_provider


class FakeProviderV2(ProviderV1):
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering if we want a different name for this class because what if we ever finish #5629 and want to have an implementation of the ProviderV2 interface. Not really a blocker but given my other comment now is the time to change it,

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catch. I was thinking the same when I was writing the code :) How about FakeProviderForBackendV2?

mtreinish
mtreinish previously approved these changes Mar 30, 2022
Copy link
Member

@mtreinish mtreinish 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 doing this and sticking with it and all the updates.

@HuangJunye
Copy link
Collaborator Author

Thank you for your advice along the way. I am very happy that the PR is read to merge!

@mergify mergify bot merged commit 5ed5db9 into Qiskit:main Mar 31, 2022
@omarcostahamido
Copy link
Contributor

oh, nice!

@HuangJunye HuangJunye added the mod: fake_provider Related to the fake_provider module and fake backends label Apr 1, 2022
ElePT pushed a commit to ElePT/qiskit-ibm-provider that referenced this pull request Oct 4, 2023
* Add backend converter script from Matthew

Co-Authored-By: Matthew Treinish <[email protected]>

* FakeBackendV2, FakeQasmBeckendV2, FakeJakartaV2 in progress

* Temporary fix for circular import

* First try of implementing FakeJakartaV2 based on FakeQasmBackendV2/FakeBackendV2

* Implement FakeQasmBackend methods into FakeBackendV2

* Implement FakePulseBackend methods into FakeBackendV2

* Import missing PulseDefaults and adjust _get_conf_from_json method position

* Adjust _get_config_from_dict method position

* Fix target property

Need to take closer look at _convert_to_target method

* Fix _default_options method

* Add FakeProviderV2 for V2 fake backends

* Remove FakeQasmBackendV2 class

* Copy run method from FakeBackendV1

* change configuration to self._configuration

* Update backend_converter.py

Based on the latest version on Qiskit/qiskit-ibm-runtime#102

Co-Authored-By: Rathish Cholarajan <[email protected]>

* @rathishcholarajan Use BackendConfiguration, BackendProperties and PulseDefaults classes for convert_to_target

* Add dtm

* Add qubit properties

* Add drive, measure and acquire channels.

* Fix test_fake_backends

* Fix ConfigurableFakeBackend circular import problem

* Fix configurable_backend circular import problem

* FakeAlmadenV2

* FakeArmonkV2

* FakeAthensV2

* FakeBelemV2

* FakeBoeblingenV2

* Add fake backends (except rueschlikon, tenerife and tokyo)

* import fake v2 backends in __init__.py

* add fake backends to mock.backend.__init__ and fake provider

* Fix typos

* Add defs files to manila, poughkeepsie, rome and santiago

* Fix FakeCambridgeV2

* Add Hanoi and Kolkata to FakeProviderV2

* Handle no pulse backends in V2

* Fix getting qubit properties from properties bug

* Fix _parse_inst_map for BackendV2 with no pulse support

* Revert "Update backend_converter.py"

This reverts commit 2438935d218bf3e1059bef185d77c426cc0978d3.

* Revert " @rathishcholarajan Use BackendConfiguration, BackendProperties and PulseDefaults classes for convert_to_target"

This reverts commit eec4a49f590399c15a90c4579844009cc9d0dc20.

* Use dicts instead of conf, props, defs objects

* remove channels

* add type hints

* Use dict.get instead of brackets

* clean up backend_converter.py

* construct target using defs files if it exist

* Fix typo in target.acquire_alignment

* Handle BackendV2 in transpiler._parse_inst_map

* Comment out backends in fake provider and Aer run method for testing

* undo typo fix for target.acquire_alignment

* Revert "Comment out backends in fake provider and Aer run method for testing"

This reverts commit 2127b345b63e9dea1bbdbd44b397f1d14089213b.

* Copy NoiseModel.from_backend() method from Aer

* modify NoiseModel.from_backend method to support V2 backend

* Build V2 backend noise model from self._props_dict

* black reformatting

* Move V2 backend code to above V1 and Legacy

* Clean up FakeBackendV2 for testing

* Order FakeBackendV2 to match BackendV2

* Uncomment out fake backends from fake provider v1 and fake legacy provider

* Remove unused imports

* Remove FakeTokyoV2 import

* Remove warnings for missing conf, props and defs files

* Remove lazy loading of target

* Remove lazy loading of qubit properties

* Remove deprecation warning for standard_gates option in noise model

* linting for fake_backend.py

* linting for backend_converter.py

* fix `Redefining name 'warnings' from outer scope` error

* lint: rename qubit_props_dict_from_props_dict

* Raise error for pulse simulation

* remove warnings flag

* Move V2 to in front of V1

* revert changes in transpiler._parse_inst_map

The changes are now in a separate PR: Qiskit/qiskit#7765

* remove warnings flag

* fix 'no-else-raise' error

* Add docstring to FakeBackendV2

* rename `kwargs` to `options` in .run method

following BackendV2

* Update qiskit/test/mock/fake_backend.py

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

* Update qiskit/test/mock/fake_backend.py

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

* Update qiskit/test/mock/fake_backend.py

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

* rearrange raising error for pulse job

* Add a TODO comment for removing PulseDefaults

* fix typo

* black reformat

* Add release note.

* Fix no else raise error

* Add blank new line in release note

* black formatting

* fix release note missing black tick

* Rename FakeProviderV2 to FakeProviderForBackendV2

* Re-export FakeProviderForBackendV2 to qiskit.providers.fake_provider

* black reformatting

Co-authored-by: Matthew Treinish <[email protected]>
Co-authored-by: Rathish Cholarajan <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
ElePT pushed a commit to ElePT/qiskit-ibm-provider that referenced this pull request Oct 9, 2023
* Add backend converter script from Matthew

Co-Authored-By: Matthew Treinish <[email protected]>

* FakeBackendV2, FakeQasmBeckendV2, FakeJakartaV2 in progress

* Temporary fix for circular import

* First try of implementing FakeJakartaV2 based on FakeQasmBackendV2/FakeBackendV2

* Implement FakeQasmBackend methods into FakeBackendV2

* Implement FakePulseBackend methods into FakeBackendV2

* Import missing PulseDefaults and adjust _get_conf_from_json method position

* Adjust _get_config_from_dict method position

* Fix target property

Need to take closer look at _convert_to_target method

* Fix _default_options method

* Add FakeProviderV2 for V2 fake backends

* Remove FakeQasmBackendV2 class

* Copy run method from FakeBackendV1

* change configuration to self._configuration

* Update backend_converter.py

Based on the latest version on Qiskit/qiskit-ibm-runtime#102

Co-Authored-By: Rathish Cholarajan <[email protected]>

* @rathishcholarajan Use BackendConfiguration, BackendProperties and PulseDefaults classes for convert_to_target

* Add dtm

* Add qubit properties

* Add drive, measure and acquire channels.

* Fix test_fake_backends

* Fix ConfigurableFakeBackend circular import problem

* Fix configurable_backend circular import problem

* FakeAlmadenV2

* FakeArmonkV2

* FakeAthensV2

* FakeBelemV2

* FakeBoeblingenV2

* Add fake backends (except rueschlikon, tenerife and tokyo)

* import fake v2 backends in __init__.py

* add fake backends to mock.backend.__init__ and fake provider

* Fix typos

* Add defs files to manila, poughkeepsie, rome and santiago

* Fix FakeCambridgeV2

* Add Hanoi and Kolkata to FakeProviderV2

* Handle no pulse backends in V2

* Fix getting qubit properties from properties bug

* Fix _parse_inst_map for BackendV2 with no pulse support

* Revert "Update backend_converter.py"

This reverts commit 2438935d218bf3e1059bef185d77c426cc0978d3.

* Revert " @rathishcholarajan Use BackendConfiguration, BackendProperties and PulseDefaults classes for convert_to_target"

This reverts commit eec4a49f590399c15a90c4579844009cc9d0dc20.

* Use dicts instead of conf, props, defs objects

* remove channels

* add type hints

* Use dict.get instead of brackets

* clean up backend_converter.py

* construct target using defs files if it exist

* Fix typo in target.acquire_alignment

* Handle BackendV2 in transpiler._parse_inst_map

* Comment out backends in fake provider and Aer run method for testing

* undo typo fix for target.acquire_alignment

* Revert "Comment out backends in fake provider and Aer run method for testing"

This reverts commit 2127b345b63e9dea1bbdbd44b397f1d14089213b.

* Copy NoiseModel.from_backend() method from Aer

* modify NoiseModel.from_backend method to support V2 backend

* Build V2 backend noise model from self._props_dict

* black reformatting

* Move V2 backend code to above V1 and Legacy

* Clean up FakeBackendV2 for testing

* Order FakeBackendV2 to match BackendV2

* Uncomment out fake backends from fake provider v1 and fake legacy provider

* Remove unused imports

* Remove FakeTokyoV2 import

* Remove warnings for missing conf, props and defs files

* Remove lazy loading of target

* Remove lazy loading of qubit properties

* Remove deprecation warning for standard_gates option in noise model

* linting for fake_backend.py

* linting for backend_converter.py

* fix `Redefining name 'warnings' from outer scope` error

* lint: rename qubit_props_dict_from_props_dict

* Raise error for pulse simulation

* remove warnings flag

* Move V2 to in front of V1

* revert changes in transpiler._parse_inst_map

The changes are now in a separate PR: Qiskit/qiskit#7765

* remove warnings flag

* fix 'no-else-raise' error

* Add docstring to FakeBackendV2

* rename `kwargs` to `options` in .run method

following BackendV2

* Update qiskit/test/mock/fake_backend.py

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

* Update qiskit/test/mock/fake_backend.py

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

* Update qiskit/test/mock/fake_backend.py

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

* rearrange raising error for pulse job

* Add a TODO comment for removing PulseDefaults

* fix typo

* black reformat

* Add release note.

* Fix no else raise error

* Add blank new line in release note

* black formatting

* fix release note missing black tick

* Rename FakeProviderV2 to FakeProviderForBackendV2

* Re-export FakeProviderForBackendV2 to qiskit.providers.fake_provider

* black reformatting

Co-authored-by: Matthew Treinish <[email protected]>
Co-authored-by: Rathish Cholarajan <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
ElePT pushed a commit to ElePT/qiskit-ibm-runtime that referenced this pull request Oct 10, 2023
* Add backend converter script from Matthew

Co-Authored-By: Matthew Treinish <[email protected]>

* FakeBackendV2, FakeQasmBeckendV2, FakeJakartaV2 in progress

* Temporary fix for circular import

* First try of implementing FakeJakartaV2 based on FakeQasmBackendV2/FakeBackendV2

* Implement FakeQasmBackend methods into FakeBackendV2

* Implement FakePulseBackend methods into FakeBackendV2

* Import missing PulseDefaults and adjust _get_conf_from_json method position

* Adjust _get_config_from_dict method position

* Fix target property

Need to take closer look at _convert_to_target method

* Fix _default_options method

* Add FakeProviderV2 for V2 fake backends

* Remove FakeQasmBackendV2 class

* Copy run method from FakeBackendV1

* change configuration to self._configuration

* Update backend_converter.py

Based on the latest version on Qiskit#102

Co-Authored-By: Rathish Cholarajan <[email protected]>

* @rathishcholarajan Use BackendConfiguration, BackendProperties and PulseDefaults classes for convert_to_target

* Add dtm

* Add qubit properties

* Add drive, measure and acquire channels.

* Fix test_fake_backends

* Fix ConfigurableFakeBackend circular import problem

* Fix configurable_backend circular import problem

* FakeAlmadenV2

* FakeArmonkV2

* FakeAthensV2

* FakeBelemV2

* FakeBoeblingenV2

* Add fake backends (except rueschlikon, tenerife and tokyo)

* import fake v2 backends in __init__.py

* add fake backends to mock.backend.__init__ and fake provider

* Fix typos

* Add defs files to manila, poughkeepsie, rome and santiago

* Fix FakeCambridgeV2

* Add Hanoi and Kolkata to FakeProviderV2

* Handle no pulse backends in V2

* Fix getting qubit properties from properties bug

* Fix _parse_inst_map for BackendV2 with no pulse support

* Revert "Update backend_converter.py"

This reverts commit 2438935d218bf3e1059bef185d77c426cc0978d3.

* Revert " @rathishcholarajan Use BackendConfiguration, BackendProperties and PulseDefaults classes for convert_to_target"

This reverts commit eec4a49f590399c15a90c4579844009cc9d0dc20.

* Use dicts instead of conf, props, defs objects

* remove channels

* add type hints

* Use dict.get instead of brackets

* clean up backend_converter.py

* construct target using defs files if it exist

* Fix typo in target.acquire_alignment

* Handle BackendV2 in transpiler._parse_inst_map

* Comment out backends in fake provider and Aer run method for testing

* undo typo fix for target.acquire_alignment

* Revert "Comment out backends in fake provider and Aer run method for testing"

This reverts commit 2127b345b63e9dea1bbdbd44b397f1d14089213b.

* Copy NoiseModel.from_backend() method from Aer

* modify NoiseModel.from_backend method to support V2 backend

* Build V2 backend noise model from self._props_dict

* black reformatting

* Move V2 backend code to above V1 and Legacy

* Clean up FakeBackendV2 for testing

* Order FakeBackendV2 to match BackendV2

* Uncomment out fake backends from fake provider v1 and fake legacy provider

* Remove unused imports

* Remove FakeTokyoV2 import

* Remove warnings for missing conf, props and defs files

* Remove lazy loading of target

* Remove lazy loading of qubit properties

* Remove deprecation warning for standard_gates option in noise model

* linting for fake_backend.py

* linting for backend_converter.py

* fix `Redefining name 'warnings' from outer scope` error

* lint: rename qubit_props_dict_from_props_dict

* Raise error for pulse simulation

* remove warnings flag

* Move V2 to in front of V1

* revert changes in transpiler._parse_inst_map

The changes are now in a separate PR: Qiskit/qiskit#7765

* remove warnings flag

* fix 'no-else-raise' error

* Add docstring to FakeBackendV2

* rename `kwargs` to `options` in .run method

following BackendV2

* Update qiskit/test/mock/fake_backend.py

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

* Update qiskit/test/mock/fake_backend.py

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

* Update qiskit/test/mock/fake_backend.py

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

* rearrange raising error for pulse job

* Add a TODO comment for removing PulseDefaults

* fix typo

* black reformat

* Add release note.

* Fix no else raise error

* Add blank new line in release note

* black formatting

* fix release note missing black tick

* Rename FakeProviderV2 to FakeProviderForBackendV2

* Re-export FakeProviderForBackendV2 to qiskit.providers.fake_provider

* black reformatting

Co-authored-by: Matthew Treinish <[email protected]>
Co-authored-by: Rathish Cholarajan <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
ElePT pushed a commit to ElePT/qiskit that referenced this pull request Oct 12, 2023
* Add backend converter script from Matthew

Co-Authored-By: Matthew Treinish <[email protected]>

* FakeBackendV2, FakeQasmBeckendV2, FakeJakartaV2 in progress

* Temporary fix for circular import

* First try of implementing FakeJakartaV2 based on FakeQasmBackendV2/FakeBackendV2

* Implement FakeQasmBackend methods into FakeBackendV2

* Implement FakePulseBackend methods into FakeBackendV2

* Import missing PulseDefaults and adjust _get_conf_from_json method position

* Adjust _get_config_from_dict method position

* Fix target property

Need to take closer look at _convert_to_target method

* Fix _default_options method

* Add FakeProviderV2 for V2 fake backends

* Remove FakeQasmBackendV2 class

* Copy run method from FakeBackendV1

* change configuration to self._configuration

* Update backend_converter.py

Based on the latest version on Qiskit/qiskit-ibm-runtime#102

Co-Authored-By: Rathish Cholarajan <[email protected]>

* @rathishcholarajan Use BackendConfiguration, BackendProperties and PulseDefaults classes for convert_to_target

* Add dtm

* Add qubit properties

* Add drive, measure and acquire channels.

* Fix test_fake_backends

* Fix ConfigurableFakeBackend circular import problem

* Fix configurable_backend circular import problem

* FakeAlmadenV2

* FakeArmonkV2

* FakeAthensV2

* FakeBelemV2

* FakeBoeblingenV2

* Add fake backends (except rueschlikon, tenerife and tokyo)

* import fake v2 backends in __init__.py

* add fake backends to mock.backend.__init__ and fake provider

* Fix typos

* Add defs files to manila, poughkeepsie, rome and santiago

* Fix FakeCambridgeV2

* Add Hanoi and Kolkata to FakeProviderV2

* Handle no pulse backends in V2

* Fix getting qubit properties from properties bug

* Fix _parse_inst_map for BackendV2 with no pulse support

* Revert "Update backend_converter.py"

This reverts commit 2438935.

* Revert " @rathishcholarajan Use BackendConfiguration, BackendProperties and PulseDefaults classes for convert_to_target"

This reverts commit eec4a49.

* Use dicts instead of conf, props, defs objects

* remove channels

* add type hints

* Use dict.get instead of brackets

* clean up backend_converter.py

* construct target using defs files if it exist

* Fix typo in target.acquire_alignment

* Handle BackendV2 in transpiler._parse_inst_map

* Comment out backends in fake provider and Aer run method for testing

* undo typo fix for target.acquire_alignment

* Revert "Comment out backends in fake provider and Aer run method for testing"

This reverts commit 2127b34.

* Copy NoiseModel.from_backend() method from Aer

* modify NoiseModel.from_backend method to support V2 backend

* Build V2 backend noise model from self._props_dict

* black reformatting

* Move V2 backend code to above V1 and Legacy

* Clean up FakeBackendV2 for testing

* Order FakeBackendV2 to match BackendV2

* Uncomment out fake backends from fake provider v1 and fake legacy provider

* Remove unused imports

* Remove FakeTokyoV2 import

* Remove warnings for missing conf, props and defs files

* Remove lazy loading of target

* Remove lazy loading of qubit properties

* Remove deprecation warning for standard_gates option in noise model

* linting for fake_backend.py

* linting for backend_converter.py

* fix `Redefining name 'warnings' from outer scope` error

* lint: rename qubit_props_dict_from_props_dict

* Raise error for pulse simulation

* remove warnings flag

* Move V2 to in front of V1

* revert changes in transpiler._parse_inst_map

The changes are now in a separate PR: Qiskit#7765

* remove warnings flag

* fix 'no-else-raise' error

* Add docstring to FakeBackendV2

* rename `kwargs` to `options` in .run method

following BackendV2

* Update qiskit/test/mock/fake_backend.py

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

* Update qiskit/test/mock/fake_backend.py

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

* Update qiskit/test/mock/fake_backend.py

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

* rearrange raising error for pulse job

* Add a TODO comment for removing PulseDefaults

* fix typo

* black reformat

* Add release note.

* Fix no else raise error

* Add blank new line in release note

* black formatting

* fix release note missing black tick

* Rename FakeProviderV2 to FakeProviderForBackendV2

* Re-export FakeProviderForBackendV2 to qiskit.providers.fake_provider

* black reformatting

Co-authored-by: Matthew Treinish <[email protected]>
Co-authored-by: Rathish Cholarajan <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.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 mod: fake_provider Related to the fake_provider module and fake backends
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add BackendV2 mocked backends
6 participants