Skip to content

Commit

Permalink
add a test to the sampler
Browse files Browse the repository at this point in the history
  • Loading branch information
yaelbh committed Jul 2, 2024
1 parent cc28e55 commit ea1453d
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion test/unit/test_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from qiskit.primitives.containers.sampler_pub import SamplerPub
from qiskit.circuit.library import RealAmplitudes
from qiskit_ibm_runtime import Sampler, Session, SamplerV2, SamplerOptions, IBMInputValueError
from qiskit_ibm_runtime.fake_provider import FakeFractionalBackend
from qiskit_ibm_runtime.fake_provider import FakeFractionalBackend, FakeSherbrooke

from ..ibm_test_case import IBMTestCase
from ..utils import bell, MockSession, dict_paritally_equal, get_mocked_backend, transpile_pubs
Expand Down Expand Up @@ -245,3 +245,21 @@ def test_run_fractional_dynamic_mix(self, use_fractional):
inst = SamplerV2(mode=backend)
with self.assertRaises(IBMInputValueError):
inst.run([dynamic_circuit, fractional_circuit])

def test_gate_not_in_target(self):
"""Test exception when circuits contain gates that are not basis gates"""
backend = FakeSherbrooke()
sampler = SamplerV2(backend=backend)

circ = QuantumCircuit(1, 1)
circ.x(0)
circ.measure(0, 0)
with circ.if_test((0, 1)):
with circ.if_test((0, 0)) as else_:
circ.x(0)
with else_:
circ.h(0)
circ.measure(0, 0)

with self.assertRaisesRegex(IBMInputValueError, " h "):
sampler.run(pubs=[(circ)])

0 comments on commit ea1453d

Please sign in to comment.