Skip to content

Commit

Permalink
Removed noise_model and sim_config as an argument in the pulse si…
Browse files Browse the repository at this point in the history
…mulator (Qiskit#503)

* removed noise_model from digest args, and also sim_config handling

* Changed warnings in digest for persistentValue pulses

* multiplying qubit_lo_freq by 1e9 in digest.py, as assemble divides it by 1e9
  • Loading branch information
DanPuzzuoli authored and chriseclectic committed Jan 23, 2020
1 parent 29129cf commit 89b7624
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 26 deletions.
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'))
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

0 comments on commit 89b7624

Please sign in to comment.