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

Removed noise_model and sim_config as an argument in the pulse simulator #503

20 changes: 3 additions & 17 deletions qiskit/providers/aer/backends/pulse_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from qiskit.providers.models import BackendConfiguration, PulseDefaults
from .aerbackend import AerBackend
from ..aerjob import AerJob
from ..aererror import AerError
from ..version import __version__
from ..openpulse.qobj.digest import digest_pulse_obj
from ..openpulse.solver.opsolve import opsolve
Expand Down Expand Up @@ -67,27 +66,25 @@ def __init__(self, configuration=None, provider=None):
def run(self, qobj,
system_model,
backend_options=None,
noise_model=None,
validate=False):
"""Run a qobj on the backend."""
# Submit job
job_id = str(uuid.uuid4())
aer_job = AerJob(self, job_id, self._run_job, qobj, system_model,
backend_options, noise_model, validate)
backend_options, validate)
aer_job.submit()
return aer_job

def _run_job(self, job_id, qobj,
system_model,
backend_options,
noise_model,
validate):
"""Run a qobj job"""
start = time.time()
if validate:
self._validate(qobj, backend_options, noise_model)
self._validate(qobj, backend_options, noise_model=None)
# Send to solver
openpulse_system = digest_pulse_obj(qobj, system_model, backend_options, noise_model)
openpulse_system = digest_pulse_obj(qobj, system_model, backend_options)
results = opsolve(openpulse_system)
end = time.time()
return self._format_results(job_id, results, end - start, qobj.qobj_id)
Expand All @@ -106,17 +103,6 @@ def _format_results(self, job_id, results, time_taken, qobj_id):
output["time_taken"] = time_taken
return Result.from_dict(output)

def _validate(self, qobj, backend_options, noise_model):
"""Validate the pulse object. Make sure a
config has been attached in the proper location"""

# Check to make sure a sim_config has been added
if not hasattr(qobj.config, 'sim_config'):
raise AerError('The pulse simulator qobj must have a sim_config '
'entry to configure the simulator')

super()._validate(qobj, backend_options, noise_model)

def defaults(self):
"""Return defaults.

Expand Down
16 changes: 7 additions & 9 deletions qiskit/providers/aer/openpulse/qobj/digest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from warnings import warn
from collections import OrderedDict
import numpy as np
from qiskit.providers.aer.aererror import AerError
from .op_system import OPSystem
from .opparse import NoiseParser
from .operators import qubit_occ_oper_dressed
Expand All @@ -29,15 +30,14 @@
from . import op_qobj as op


def digest_pulse_obj(qobj, system_model, backend_options=None, noise_model=None):
def digest_pulse_obj(qobj, system_model, backend_options=None):
"""Convert specification of a simulation in the pulse language into the format accepted
by the simulator.

Args:
qobj (PulseQobj): experiment specification
system_model (PulseSystemModel): object representing system model
backend_options (dict): dictionary of simulation options
noise_model (dict): noise model specification
Returns:
out (OPSystem): object understandable by the pulse simulator
Raises:
Expand All @@ -53,11 +53,7 @@ def digest_pulse_obj(qobj, system_model, backend_options=None, noise_model=None)
if backend_options is None:
backend_options = {}

# Temp backwards compatibility
if 'sim_config' in qobj_config:
for key, val in qobj_config['sim_config'].items():
backend_options[key] = val
qobj_config.pop('sim_config')
noise_model = backend_options.get('noise_model', None)

# post warnings for unsupported features
_unsupported_warnings(qobj_dict, noise_model)
Expand All @@ -76,7 +72,8 @@ def digest_pulse_obj(qobj, system_model, backend_options=None, noise_model=None)

if 'qubit_lo_freq' not in qobj_config:
raise ValueError('qubit_lo_freq must be specified in qobj.')
qubit_lo_freq = qobj_config['qubit_lo_freq']
# qobj frequencies are divided by 1e9, so multiply back
qubit_lo_freq = [freq * 1e9 for freq in qobj_config['qubit_lo_freq']]

# Build pulse arrays ***************************************************************
pulses, pulses_idx, pulse_dict = build_pulse_arrays(qobj_dict['experiments'],
Expand Down Expand Up @@ -212,14 +209,15 @@ def _unsupported_warnings(qobj_dict, noise_model):
noise_model (dict): backend_options for simulation
Returns:
Raises:
AerError: for unsupported features
"""

# Warnings that don't stop execution
warning_str = '{} are an untested feature, and therefore may not behave as expected.'
if noise_model is not None:
warn(warning_str.format('Noise models'))
Copy link
Member

Choose a reason for hiding this comment

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

I think we should keep the noise model as a warning for now

if _contains_pv_instruction(qobj_dict['experiments']):
warn(warning_str.format('PersistentValue instructions'))
raise AerError(warning_str.format('PersistentValue instructions'))


def _contains_pv_instruction(experiments):
Expand Down