Skip to content

Commit

Permalink
revert test cases to use qobj
Browse files Browse the repository at this point in the history
  • Loading branch information
hhorii committed Feb 7, 2023
1 parent aa47332 commit c726fb5
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions test/terra/backends/test_parameterized_qobj.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,57 @@ def parameterized_qobj(
parameterizations=params)
return qobj

def test_parameterized_qobj_qasm_save_expval(self):
"""Test parameterized qobj with Expectation Value snapshot and qasm simulator."""
shots = 1000
labels = save_expval_labels() * 3
counts_targets = save_expval_counts(shots) * 3
value_targets = save_expval_pre_meas_values() * 3

backend = AerSimulator()
qobj = self.parameterized_qobj(backend=backend,
shots=1000,
measure=True,
snapshot=True)
self.assertIn('parameterizations', qobj.to_dict()['config'])
with self.assertWarns(DeprecationWarning):
job = backend.run(qobj, **self.BACKEND_OPTS)
result = job.result()
success = getattr(result, 'success', False)
num_circs = len(result.to_dict()['results'])
self.assertTrue(success)
self.compare_counts(result,
range(num_circs),
counts_targets,
delta=0.1 * shots)
# Check snapshots
for j, target in enumerate(value_targets):
data = result.data(j)
for label in labels:
self.assertAlmostEqual(
data[label], target[label], delta=1e-7)

def test_parameterized_qobj_statevector(self):
"""Test parameterized qobj with Expectation Value snapshot and qasm simulator."""
statevec_targets = save_expval_final_statevecs() * 3

backend = AerSimulator(method="statevector")
qobj = self.parameterized_qobj(
backend=backend, measure=False, snapshot=False, save_state=True,
)
self.assertIn('parameterizations', qobj.to_dict()['config'])
with self.assertWarns(DeprecationWarning):
job = backend.run(qobj, **self.BACKEND_OPTS)
result = job.result()
success = getattr(result, 'success', False)
num_circs = len(result.to_dict()['results'])
self.assertTrue(success)

for j in range(num_circs):
statevector = result.get_statevector(j)
np.testing.assert_array_almost_equal(
statevector, statevec_targets[j].data, decimal=7)

def test_run_path(self):
"""Test parameterized circuit path via backed.run()"""
shots = 1000
Expand Down

0 comments on commit c726fb5

Please sign in to comment.