Skip to content

Commit

Permalink
support recent change related to noise model
Browse files Browse the repository at this point in the history
  • Loading branch information
hhorii committed Dec 10, 2021
1 parent 63a05ef commit 5c8c12c
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions test/benchmark/simulator_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def __init__(self,
self.backend_options_list[self.RUNTIME_DENSITY_MATRIX_GPU] = { 'enable_truncation': False}
self.backend_qubits[self.RUNTIME_DENSITY_MATRIX_GPU] = [qubit for qubit in qubits if qubit <= 15]

def gen_qobj(self, runtime, app, measure, measure_count, qubit):
def gen_qobj(self, runtime, app, measure, measure_count, qubit, noise_name):

def add_measure_all(base):
circuit = base.copy()
Expand All @@ -153,6 +153,8 @@ def add_expval(base, num_terms):
circuit.snapshot_expectation_value('expval', pauli_op, range(qubit))

circuit = eval('self.{0}'.format(app))(qubit, None if app not in self.app2rep else self.app2rep[app])
noise_model = self.noise_models[noise_name]

if len(circuit.parameters) > 0:
param_binds = {}
for param in circuit.parameters:
Expand All @@ -163,25 +165,24 @@ def add_expval(base, num_terms):
shots = measure_count if measure == self.MEASUREMENT_SAMPLING else 1

if (simulator, app, measure, measure_count, qubit) not in QOBJS:
QOBJS[(runtime, app, measure, measure_count, qubit)] = simulator._assemble(transpile(circuit, simulator), shots=shots)
return QOBJS[(runtime, app, measure, measure_count, qubit)]
QOBJS[(runtime, app, measure, measure_count, qubit, noise_name)] = simulator._assemble(transpile(circuit, simulator), shots=shots, noise_model=noise_model)
return QOBJS[(runtime, app, measure, measure_count, qubit, noise_name)]

def _run(self, runtime, app, measure, measure_count, noise_name, qubit):
if runtime not in self.simulators or runtime not in self.backend_options_list:
raise ValueError('unknown runtime: {0}'.format(runtime))
simulator = self.simulators[runtime]
backend_options = self.backend_options_list[runtime]
noise_model = self.noise_models[noise_name]

if qubit not in self.backend_qubits[runtime]:
raise ValueError('out of qubit range: qubit={0}, list={1}'.format(qubit, self.backend_qubits[runtime]))

qobj = self.gen_qobj(runtime, app, measure, measure_count, qubit)
qobj = self.gen_qobj(runtime, app, measure, measure_count, qubit, noise_name)
if qobj is None:
raise ValueError('no qobj: measure={0}:{1}, qubit={2}'.format(measure, measure_count, qubit))

start = time()
result = simulator._run(qobj, noise_model=noise_model, **backend_options)
result = simulator._run(qobj, **backend_options)
if result.status != 'COMPLETED':
try:
reason = None
Expand Down

0 comments on commit 5c8c12c

Please sign in to comment.