Skip to content

Commit fa67e0b

Browse files
TsafrirAmergify[bot]
authored andcommitted
Fix custom pulse instruction conversion to Qobj. (#11829)
* Possible fix. * Update releasenotes/notes/fix-custom-pulse-qobj-conversion-5d6041b36356cfd1.yaml Co-authored-by: Will Shanks <wshaos@posteo.net> * release notes fix * Add test --------- Co-authored-by: Will Shanks <wshaos@posteo.net> (cherry picked from commit 060cb70)
1 parent beb7310 commit fa67e0b

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

qiskit/qobj/converters/pulse_instruction.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ def from_instance(
6262
Raises:
6363
QiskitError: When pulse instance is not recognizable type.
6464
"""
65-
try:
65+
if isinstance(instance, library.SymbolicPulse):
6666
return cls(instance.pulse_type)
67-
except ValueError as ex:
68-
raise QiskitError(f"'{instance}' is not valid pulse type.") from ex
67+
68+
raise QiskitError(f"'{instance}' is not valid pulse type.")
6969

7070
@classmethod
7171
def to_type(cls, name: str) -> library.SymbolicPulse:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
fixes:
3+
- |
4+
Fixed a bug in the conversion of custom pulse instructions to the legacy :mod:`qiskit.qobj` format. The bug was introduced in Qiskit 1.0.0
5+
and caused conversion of instructions with custom pulse shapes to raise an error. After the fix, the conversion is
6+
carried out correctly, and the custom pulse is converted to :class:`.pulse.Waveform` as it should.
7+
Fixed `#11828 <https://github.com/Qiskit/qiskit/issues/11828>`__.

test/python/compiler/test_assembler.py

+18
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,24 @@ def test_pulse_gates_single_circ(self):
528528
self.assertEqual(len(lib), 2)
529529
self.assertTrue(all(len(item.samples) == 50 for item in lib))
530530

531+
def test_custom_pulse_gates_single_circ(self):
532+
"""Test that we can add calibrations to circuits of pulses which are not in
533+
qiskit.qobj.converters.pulse_instruction.ParametricPulseShapes"""
534+
circ = QuantumCircuit(2)
535+
circ.h(0)
536+
537+
with pulse.build() as custom_h_schedule:
538+
pulse.play(pulse.library.Triangle(50, 0.1, 0.2), pulse.DriveChannel(0))
539+
540+
circ.add_calibration("h", [0], custom_h_schedule)
541+
542+
qobj = assemble(circ, FakeOpenPulse2Q())
543+
lib = qobj.config.pulse_library
544+
self.assertEqual(len(lib), 1)
545+
np.testing.assert_almost_equal(
546+
lib[0].samples, pulse.library.Triangle(50, 0.1, 0.2).get_waveform().samples
547+
)
548+
531549
def test_pulse_gates_with_parameteric_pulses(self):
532550
"""Test that pulse gates are assembled efficiently for backends that enable
533551
parametric pulses.

0 commit comments

Comments
 (0)