Skip to content

Commit

Permalink
tests, typo
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrandhsn committed Jul 11, 2024
1 parent a4ac027 commit d4d01c6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
10 changes: 7 additions & 3 deletions qiskit/providers/fake_provider/generic_backend_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ def __init__(
None by default.
seed: Optional seed for generation of default values.
pulse_channels: If true, sets default pulse channel information on the backend.
noise_info: If true, associates gates and qubits with default noise information.
"""

Expand All @@ -179,7 +181,7 @@ def __init__(
self._control_flow = control_flow
self._calibrate_instructions = calibrate_instructions
self._supported_gates = get_standard_gate_name_mapping()
self._include_errors = noise_info
self._noise_info = noise_info

if calibrate_instructions and not noise_info:
raise QiskitError("Must set parameter noise_info when calibrating instructions.")
Expand Down Expand Up @@ -208,6 +210,8 @@ def __init__(
self._build_generic_target()
if pulse_channels:
self._build_default_channels()
else:
self.channels_map = {}

@property
def target(self):
Expand Down Expand Up @@ -349,7 +353,7 @@ def _build_generic_target(self):
"""
# the qubit properties are sampled from default ranges
properties = _QUBIT_PROPERTIES
if not self._include_errors:
if not self._noise_info:
self._target = Target(
description=f"Generic Target with {self._num_qubits} qubits",
num_qubits=self._num_qubits,
Expand Down Expand Up @@ -398,7 +402,7 @@ def _build_generic_target(self):
f"Provided basis gate {name} needs more qubits than {self.num_qubits}, "
f"which is the size of the backend."
)
if self._include_errors:
if self._noise_info:
noise_params = self._get_noise_defaults(name, gate.num_qubits)
self._add_noisy_instruction_to_target(gate, noise_params, calibration_inst_map)
else:
Expand Down
20 changes: 20 additions & 0 deletions test/python/providers/fake_provider/test_generic_backend_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,26 @@ def test_ccx_2Q(self):
with self.assertRaises(QiskitError):
GenericBackendV2(num_qubits=2, basis_gates=["ccx", "id"])

def test_calibration_no_noise_info(self):
"""Test failing with a backend with calibration and no noise info"""
with self.assertRaises(QiskitError):
GenericBackendV2(
num_qubits=2,
basis_gates=["ccx", "id"],
calibrate_instructions=True,
noise_info=False,
)

def test_no_noise(self):
"""Test no noise info when parameter is false"""
backend = GenericBackendV2(num_qubits=2, noise_info=False)
self.assertEqual(backend.target.qubit_properties, None)

def test_no_pulse_channels(self):
"""Test no/empty pulse channels when parameter is false"""
backend = GenericBackendV2(num_qubits=2, pulse_channels=False)
self.assertTrue(len(backend.channels_map) == 0)

def test_operation_names(self):
"""Test that target basis gates include "delay", "measure" and "reset" even
if not provided by user."""
Expand Down

0 comments on commit d4d01c6

Please sign in to comment.