Skip to content

Configurable backends#486

Merged
chriseclectic merged 15 commits into
Qiskit:masterfrom
chriseclectic:feature/configurable-backends
Oct 13, 2020
Merged

Configurable backends#486
chriseclectic merged 15 commits into
Qiskit:masterfrom
chriseclectic:feature/configurable-backends

Conversation

@chriseclectic
Copy link
Copy Markdown
Member

@chriseclectic chriseclectic commented Dec 9, 2019

Summary

Makes simulator backends have configurable options. Allows configuring a noisy backend from

Closes #645

Details and comments

Backend options initialization of the simulator object, or after, and still overridden using execute/run kwargs as previously.

All backend options may be passed in as kwargs, rather than a dict (though dict is maintained for backwards compatibility).

Example

Configuring a simulator after initializing

from qiskit.providers.aer import QasmSimulator
from qiskit.providers.aer.noise import *

# Make a NoiseModel
noise_model = NoiseModel()
error1 = depolarizing_error(1e-3, 1)
error2 = depolarizing_error(1e-2, 2)
noise_model.add_all_qubit_quantum_error(error1, 'u3')
noise_model.add_all_qubit_quantum_error(error2, 'cx')

# Make a backend then configure
backend = QasmSimulator()
backend.set_options(noise_model=noise_model, method='density_matrix')

# Equivalent to configuring during init
backend = QasmSimulator(noise_model=noise_model, method='density_matrix')

# Run noisy density matrix simulation on backend
qc = QuantumCircuit(2, 2)
qc.h(0)
qc.cx(0, 1)
qc.measure([0, 1], [0, 1])
result = execute(qc, backend).result()
result.get_counts(0)

Make a noisy backend from backend noise model

from qiskit import IBMQ

# Create noisy QasmSimulator backend from provider noise model
provider = IBMQ.load_account()
real_backend = provider.get_backend('ibmq_vigo')
fake_backend = QasmSimulator.from_backend(real_backend)

# Run noisy simulation on backend
qc = QuantumCircuit(2, 2)
qc.h(0)
qc.cx(0, 1)
qc.measure([0, 1], [0, 1])
result = execute(qc, fake_backend).result()
result.get_counts(0)

TODO:

  • Add API documentation examples
  • Add deprecation warning for backend_options kwarg
  • Add basic tests
  • Add tests for QasmSimulator.from_backend
  • Add test for PulseSimulator.from_backend
  • Add release note

Follow up

  • Update tests to avoid deprecated interface
  • Update tutorials
  • Improve documentation
  • Add mock backends

@chriseclectic chriseclectic requested a review from atilag as a code owner December 9, 2019 21:21
@chriseclectic chriseclectic added the on hold Can not fix yet label Jan 22, 2020
@chriseclectic chriseclectic force-pushed the feature/configurable-backends branch from a285b80 to 0034862 Compare March 2, 2020 18:37
@chriseclectic chriseclectic removed the on hold Can not fix yet label Mar 2, 2020
@chriseclectic chriseclectic force-pushed the feature/configurable-backends branch from 48d6c3a to 079a4e1 Compare March 2, 2020 22:43
@chriseclectic chriseclectic added this to the Aer 0.5 milestone Mar 3, 2020
@nonhermitian
Copy link
Copy Markdown
Contributor

This is cool.

It would be extra cool if Aer could autogen the noisy sims from those found doing IBMQ.load_account() or from Terra mock backends if no IBMQ such that one can simply do:

sim = Aer.get_backend('vigo_simulator')
job = execute([qc], sim)
...

@chriseclectic chriseclectic force-pushed the feature/configurable-backends branch from 079a4e1 to d684399 Compare March 17, 2020 21:29
@chriseclectic chriseclectic requested a review from mtreinish March 25, 2020 21:50
@chriseclectic chriseclectic force-pushed the feature/configurable-backends branch from d684399 to e01e375 Compare July 8, 2020 21:10
@chriseclectic chriseclectic force-pushed the feature/configurable-backends branch from e01e375 to 4862ec4 Compare July 27, 2020 17:01
@chriseclectic chriseclectic modified the milestones: Aer 0.6, Aer 0.7 Aug 6, 2020
@chriseclectic chriseclectic force-pushed the feature/configurable-backends branch from 95a95d8 to 8230e14 Compare August 26, 2020 18:33
@chriseclectic chriseclectic changed the title [WIP] Configurable backends Configurable backends Aug 26, 2020
Copy link
Copy Markdown
Contributor

@vvilpas vvilpas left a comment

Choose a reason for hiding this comment

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

Looks good. I have some very minor comments/sugggestions (most of them remainders to add 'cy' in list of basis)

Comment thread qiskit/providers/aer/backends/aerbackend.py Outdated
Comment on lines +227 to +282
if hasattr(self.configuration(), 'hamiltonian'):
warn('Specifying both a configuration with a Hamiltonian and a '
'system model may result in inconsistencies.')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shouldn't we raise an exception in this case?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Im not sure, @DanPuzzuoli what do you think?

Copy link
Copy Markdown
Contributor

@DanPuzzuoli DanPuzzuoli Oct 5, 2020

Choose a reason for hiding this comment

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

I figured a warning gives a bit more flexibility, enabling the user to independently specify a system model without having to modify other backend attributes. At the same time, I don't have a very clear/obvious use-case for this, and in any case if we change it to an exception, the user could still specify an independent system model by first deleting the Hamiltonian. I think personally I'm leaning towards keeping it as is and leaving it up to the user to choose what to do, though I acknowledge changing it to an exception does keep the object state "cleaner".

Comment thread qiskit/providers/aer/backends/qasm_simulator.py Outdated
Comment thread qiskit/providers/aer/backends/qasm_simulator.py Outdated
Comment thread qiskit/providers/aer/backends/qasm_simulator.py Outdated
Comment thread qiskit/providers/aer/backends/statevector_simulator.py Outdated
Comment thread qiskit/providers/aer/backends/unitary_simulator.py Outdated
Comment thread qiskit/providers/aer/noise/noise_model.py Outdated
Comment thread qiskit/providers/aer/pulse/controllers/pulse_controller.py Outdated
Comment thread test/terra/backends/test_pulse_simulator.py Outdated
@chriseclectic chriseclectic modified the milestones: Aer 0.7, Aer 0.8 Sep 15, 2020
@chriseclectic chriseclectic force-pushed the feature/configurable-backends branch 4 times, most recently from 9001555 to 7a97b47 Compare October 8, 2020 20:49
chriseclectic and others added 3 commits October 9, 2020 10:48
Make aer simulator backends configurable

Add deprecation warning to backend_options kwarg

Update AerJob and AerBackend

Update PulseSimulator configurable backends

Clean up config, properties, defaults option settings in AerBackend

This simplifies the _set_option method in the PulseSimulator and QasmSimulator

Simplify handling of run options in qobj config

Make pulse_controller only require qobj input

Update docs for pulse simulator

Co-Authored-By: Daniel Puzzuoli <dan.puzzuoli@gmail.com>
Qiskit Aqua was making direct use of internal AerBackend and AerJob functions that would break its use with thie refactor. This adds deprecated backwards compatible internal functions until aqua can be updated.
system_model has been changed from arg to kwarg, so this allows old way of passing by arg and raising a deprecation warning.
@chriseclectic chriseclectic force-pushed the feature/configurable-backends branch from bb76d56 to dce1c5a Compare October 9, 2020 14:49
@chriseclectic chriseclectic modified the milestones: Aer 0.8, Aer 0.7 Oct 9, 2020
vvilpas
vvilpas previously approved these changes Oct 10, 2020
mtreinish
mtreinish previously approved these changes Oct 12, 2020
Copy link
Copy Markdown
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.

At a high level this looks good to me. It aligns with the model we're moving towards in Qiskit/qiskit#5086 and puts us in a good place to switch over to that in the next aer release. The only piece missing is the default options (which being none is fine for a default) to define which options are available for a backend. Right now there isn't an easily discoverable way since everything is done via kwargs besides reading the docs. But, that's fine to do in a follow up when we migrate this Aer to be a v2 provider.

I just had a question inline and a doc suggestion, but easy enough to fix in a follow up.

Comment thread releasenotes/notes/configurable-backends-a55cd6a39a0a1561.yaml Outdated
Comment thread qiskit/providers/aer/backends/aerbackend.py Outdated
Comment thread qiskit/providers/aer/aerjob.py Outdated
@chriseclectic chriseclectic dismissed stale reviews from mtreinish and vvilpas via 017a4e1 October 13, 2020 15:48
@chriseclectic chriseclectic merged commit d5deb42 into Qiskit:master Oct 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Configurable backends

6 participants