Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove undefined variable #10117

Merged
merged 2 commits into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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