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

Fake Backends don't pass options to underlying simulator #7500

Closed
mtreinish opened this issue Jan 7, 2022 · 8 comments · Fixed by #7912
Closed

Fake Backends don't pass options to underlying simulator #7500

mtreinish opened this issue Jan 7, 2022 · 8 comments · Fixed by #7912
Assignees
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@mtreinish
Copy link
Member

mtreinish commented Jan 7, 2022

Environment

  • Qiskit Terra version: 0.19.x (and main)
  • Python version: 3.10
  • Operating system: linux

What is happening?

The options object from in the fake backends don't get passed down to the underlying simulator.

How can we reproduce the issue?

from qiskit.circuit import QuantumCircuit
from qiskit import execute
from qiskit.test.mock import FakeQuito

backend = FakeQuito()
circuit = QuantumCircuit(2)
circuit.h(0)
circuit.cx(0, 1)
circuit.measure_all()
backend.set_options(shots=100)
job = execute(circuit, backend)
result = job.result()
counts = result.get_counts()
print(sum(counts.values())

What should happen?

100 should print not 1024

Any suggestions?

In the run() method defined in https://github.com/Qiskit/qiskit-terra/blob/main/qiskit/test/mock/fake_backend.py#L118 we should copy self.options and set the internal simulator backend object's options attribute to be that copy. This will propagate any changes made by the user to the options to the underlying simulation when we call the internal simulator backend's run() method.

@mtreinish mtreinish added bug Something isn't working good first issue Good for newcomers labels Jan 7, 2022
@bopardikarsoham
Copy link
Contributor

bopardikarsoham commented Jan 8, 2022

I would like to work on this issue @mtreinish. Could you please complete what you observed in the "What is happening?" section?

@javabster
Copy link
Contributor

Assigned to you @bopardikarsoham! Remember to read the contributing guidelines and let us know if you have any questions!

I think the unfinished sentence in "What is happening" is just a typo and there should be enough in the rest of the description for you to get started 😄

@VaibhavSanjay
Copy link

Hi @bopardikarsoham, I just wanted to ask about the progress you've made on this issue. I would like to try to solve it, but I wanted to check in with you first. @javabster

@bopardikarsoham
Copy link
Contributor

Hello @VaibhavSanjay, I'm still working on the issue and need some more time. However, if I am unable to solve the issue, @javabster will assign it to you.

@1ucian0
Copy link
Member

1ucian0 commented Jan 31, 2022

Hello @bopardikarsoham, shall I assign it to @VaibhavSanjay ?

@bopardikarsoham
Copy link
Contributor

Yes, you can @1ucian0. I'm not able to solve it.

@VaibhavSanjay
Copy link

I believe I have a fix, could I get the issue assigned to me @1ucian0 ?

@1ucian0
Copy link
Member

1ucian0 commented Feb 4, 2022

assigning you @VaibhavSanjay. Thanks!

mtreinish added a commit to mtreinish/qiskit-core that referenced this issue Apr 8, 2022
This commit updates the FakeBackend and FakeBackendV2 classes
(FakeLegacyBackend is being removed in Qiskit#7886) to only build a noise
model from the stored properties one. This is done by initializing the
internal simulator object only once at storing it as an instance
attribute. The noise model is then constructed once at object
initialization and used to update the backend at the same time.

Fixes Qiskit#7500
Fixes Qiskit#7911
@mergify mergify bot closed this as completed in #7912 Apr 19, 2022
mergify bot added a commit that referenced this issue Apr 19, 2022
* Initialize simulator at FakeBackend inititialization

This commit updates the FakeBackend and FakeBackendV2 classes
(FakeLegacyBackend is being removed in #7886) to only build a noise
model from the stored properties one. This is done by initializing the
internal simulator object only once at storing it as an instance
attribute. The noise model is then constructed once at object
initialization and used to update the backend at the same time.

Fixes #7500
Fixes #7911

* Lazy load simulator backend objects and properties

This commit fixes another regression introduced in the previous commit
around the import and __init__ performance of fake backends. By parsing
the properties payload and creating a noise model we significantly
slowed down the initialization of fake backend objects. This commit
fixes this by ensuring we are lazy loading the noise model and simulator
object creation as well as not parsing the properties (or defaults)
payloads until we actually need them.

* Use qubit properties in target for backendv2

* Filter all noise model warnings

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
mergify bot pushed a commit that referenced this issue Apr 19, 2022
* Initialize simulator at FakeBackend inititialization

This commit updates the FakeBackend and FakeBackendV2 classes
(FakeLegacyBackend is being removed in #7886) to only build a noise
model from the stored properties one. This is done by initializing the
internal simulator object only once at storing it as an instance
attribute. The noise model is then constructed once at object
initialization and used to update the backend at the same time.

Fixes #7500
Fixes #7911

* Lazy load simulator backend objects and properties

This commit fixes another regression introduced in the previous commit
around the import and __init__ performance of fake backends. By parsing
the properties payload and creating a noise model we significantly
slowed down the initialization of fake backend objects. This commit
fixes this by ensuring we are lazy loading the noise model and simulator
object creation as well as not parsing the properties (or defaults)
payloads until we actually need them.

* Use qubit properties in target for backendv2

* Filter all noise model warnings

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
(cherry picked from commit 57f16ab)
mergify bot added a commit that referenced this issue Apr 19, 2022
* Initialize simulator at FakeBackend inititialization

This commit updates the FakeBackend and FakeBackendV2 classes
(FakeLegacyBackend is being removed in #7886) to only build a noise
model from the stored properties one. This is done by initializing the
internal simulator object only once at storing it as an instance
attribute. The noise model is then constructed once at object
initialization and used to update the backend at the same time.

Fixes #7500
Fixes #7911

* Lazy load simulator backend objects and properties

This commit fixes another regression introduced in the previous commit
around the import and __init__ performance of fake backends. By parsing
the properties payload and creating a noise model we significantly
slowed down the initialization of fake backend objects. This commit
fixes this by ensuring we are lazy loading the noise model and simulator
object creation as well as not parsing the properties (or defaults)
payloads until we actually need them.

* Use qubit properties in target for backendv2

* Filter all noise model warnings

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
(cherry picked from commit 57f16ab)

Co-authored-by: Matthew Treinish <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
5 participants