Skip to content

Commit

Permalink
Add measurements to sampler
Browse files Browse the repository at this point in the history
  • Loading branch information
ElePT committed Sep 21, 2023
1 parent 3cccebd commit 4fffcda
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions test/unit/test_ibm_primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -730,11 +730,12 @@ def test_raise_faulty_qubits(self):
estimator = Estimator(session=session)

with self.assertRaises(ValueError) as err:
sampler.run(transpiled, skip_transpilation=True)
estimator.run(transpiled, observable, skip_transpilation=True)
self.assertIn(f"faulty qubit {faulty_qubit}", str(err.exception))

transpiled.measure_all()
with self.assertRaises(ValueError) as err:
estimator.run(transpiled, observable, skip_transpilation=True)
sampler.run(transpiled, skip_transpilation=True)
self.assertIn(f"faulty qubit {faulty_qubit}", str(err.exception))

def test_raise_faulty_qubits_many(self):
Expand All @@ -759,11 +760,14 @@ def test_raise_faulty_qubits_many(self):
estimator = Estimator(session=session)

with self.assertRaises(ValueError) as err:
sampler.run(transpiled, skip_transpilation=True)
estimator.run(transpiled, [observable, observable], skip_transpilation=True)
self.assertIn(f"faulty qubit {faulty_qubit}", str(err.exception))

for circ in transpiled:
circ.measure_all()

with self.assertRaises(ValueError) as err:
estimator.run(transpiled, [observable, observable], skip_transpilation=True)
sampler.run(transpiled, skip_transpilation=True)
self.assertIn(f"faulty qubit {faulty_qubit}", str(err.exception))

def test_raise_faulty_edge(self):
Expand All @@ -785,12 +789,13 @@ def test_raise_faulty_edge(self):
estimator = Estimator(session=session)

with self.assertRaises(ValueError) as err:
sampler.run(transpiled, skip_transpilation=True)
estimator.run(transpiled, observable, skip_transpilation=True)
self.assertIn("cx", str(err.exception))
self.assertIn(f"faulty edge {tuple(edge_qubits)}", str(err.exception))

transpiled.measure_all()
with self.assertRaises(ValueError) as err:
estimator.run(transpiled, observable, skip_transpilation=True)
sampler.run(transpiled, skip_transpilation=True)
self.assertIn("cx", str(err.exception))
self.assertIn(f"faulty edge {tuple(edge_qubits)}", str(err.exception))

Expand All @@ -813,11 +818,12 @@ def test_faulty_qubit_not_used(self):
estimator = Estimator(session=session)

with patch.object(Session, "run") as mock_run:
sampler.run(transpiled, skip_transpilation=True)
estimator.run(transpiled, observable, skip_transpilation=True)
mock_run.assert_called_once()

transpiled.measure_active()
with patch.object(Session, "run") as mock_run:
estimator.run(transpiled, observable, skip_transpilation=True)
sampler.run(transpiled, skip_transpilation=True)
mock_run.assert_called_once()

def test_faulty_edge_not_used(self):
Expand All @@ -841,11 +847,12 @@ def test_faulty_edge_not_used(self):
estimator = Estimator(session=session)

with patch.object(Session, "run") as mock_run:
sampler.run(transpiled, skip_transpilation=True)
estimator.run(transpiled, observable, skip_transpilation=True)
mock_run.assert_called_once()

transpiled.measure_all()
with patch.object(Session, "run") as mock_run:
estimator.run(transpiled, observable, skip_transpilation=True)
sampler.run(transpiled, skip_transpilation=True)
mock_run.assert_called_once()

def test_no_raise_skip_transpilation(self):
Expand All @@ -870,11 +877,12 @@ def test_no_raise_skip_transpilation(self):
estimator = Estimator(session=session)

with patch.object(Session, "run") as mock_run:
sampler.run(transpiled)
estimator.run(transpiled, observable)
mock_run.assert_called_once()

transpiled.measure_all()
with patch.object(Session, "run") as mock_run:
estimator.run(transpiled, observable)
sampler.run(transpiled)
mock_run.assert_called_once()

def _update_dict(self, dict1, dict2):
Expand Down

0 comments on commit 4fffcda

Please sign in to comment.