Skip to content

Commit

Permalink
Remove undefined variable (#10117)
Browse files Browse the repository at this point in the history
* Remove undefined variable (fix #10113)

* Add test and bugfix description

(cherry picked from commit 02502b5)
  • Loading branch information
Randl authored and mergify[bot] committed May 24, 2023
1 parent c9656b2 commit 87ae1f4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
5 changes: 4 additions & 1 deletion qiskit/transpiler/passes/calibration/rzx_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,10 @@ def _check_calibration_type(
cr_sched = inst_sched_map.get("ecr", tuple(reversed(qubits)))
cal_type = CRCalType.ECR_REVERSE
else:
raise QiskitError(f"{repr(cr_sched)} native direction cannot be determined.")
raise QiskitError(
f"Native direction cannot be determined: operation on qubits {qubits} "
f"for the following instruction schedule map:\n{inst_sched_map}"
)

cr_tones = [t[1] for t in filter_instructions(cr_sched, [_filter_cr_tone]).instructions]
comp_tones = [t[1] for t in filter_instructions(cr_sched, [_filter_comp_tone]).instructions]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
fixes:
- Fix a bug in :class:`~.RZXCalibrationBuilder` where calling calibration with wrong parameters
would crash instead of raising exception.
22 changes: 21 additions & 1 deletion test/python/transpiler/test_calibrationbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@

import numpy as np
from ddt import data, ddt
from qiskit.converters import circuit_to_dag

from qiskit import circuit, schedule
from qiskit import circuit, schedule, QiskitError
from qiskit.circuit.library.standard_gates import SXGate, RZGate
from qiskit.providers.fake_provider import FakeHanoi # TODO - include FakeHanoiV2, FakeSherbrooke
from qiskit.providers.fake_provider import FakeArmonk
from qiskit.pulse import (
ControlChannel,
DriveChannel,
Expand Down Expand Up @@ -247,6 +249,24 @@ def test_rzx_calibration_rotary_pulse_stretch(self, theta: float):
test_sched.duration, self.compute_stretch_duration(self.d1p_play(cr_schedule), theta)
)

def test_raise(self):
"""Test that the correct error is raised."""
theta = np.pi / 4

qc = circuit.QuantumCircuit(2)
qc.rzx(theta, 0, 1)
dag = circuit_to_dag(qc)

backend = FakeArmonk()
inst_map = backend.defaults().instruction_schedule_map
_pass = RZXCalibrationBuilder(inst_map)

qubit_map = {qubit: i for i, qubit in enumerate(dag.qubits)}
with self.assertRaises(QiskitError):
for node in dag.gate_nodes():
qubits = [qubit_map[q] for q in node.qargs]
_pass.get_calibration(node.op, qubits)

def test_ecr_cx_forward(self):
"""Test that correct pulse sequence is generated for native CR pair."""
# Sufficiently large angle to avoid minimum duration, i.e. amplitude rescaling
Expand Down

0 comments on commit 87ae1f4

Please sign in to comment.