Skip to content

Commit

Permalink
Fix custom pulse instruction conversion to Qobj. (#11829)
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
TsafrirA authored and mergify[bot] committed Feb 20, 2024
1 parent beb7310 commit fa67e0b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
6 changes: 3 additions & 3 deletions qiskit/qobj/converters/pulse_instruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ def from_instance(
Raises:
QiskitError: When pulse instance is not recognizable type.
"""
try:
if isinstance(instance, library.SymbolicPulse):
return cls(instance.pulse_type)
except ValueError as ex:
raise QiskitError(f"'{instance}' is not valid pulse type.") from ex

raise QiskitError(f"'{instance}' is not valid pulse type.")

@classmethod
def to_type(cls, name: str) -> library.SymbolicPulse:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
fixes:
- |
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
and caused conversion of instructions with custom pulse shapes to raise an error. After the fix, the conversion is
carried out correctly, and the custom pulse is converted to :class:`.pulse.Waveform` as it should.
Fixed `#11828 <https://github.com/Qiskit/qiskit/issues/11828>`__.
18 changes: 18 additions & 0 deletions test/python/compiler/test_assembler.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,24 @@ def test_pulse_gates_single_circ(self):
self.assertEqual(len(lib), 2)
self.assertTrue(all(len(item.samples) == 50 for item in lib))

def test_custom_pulse_gates_single_circ(self):
"""Test that we can add calibrations to circuits of pulses which are not in
qiskit.qobj.converters.pulse_instruction.ParametricPulseShapes"""
circ = QuantumCircuit(2)
circ.h(0)

with pulse.build() as custom_h_schedule:
pulse.play(pulse.library.Triangle(50, 0.1, 0.2), pulse.DriveChannel(0))

circ.add_calibration("h", [0], custom_h_schedule)

qobj = assemble(circ, FakeOpenPulse2Q())
lib = qobj.config.pulse_library
self.assertEqual(len(lib), 1)
np.testing.assert_almost_equal(
lib[0].samples, pulse.library.Triangle(50, 0.1, 0.2).get_waveform().samples
)

def test_pulse_gates_with_parameteric_pulses(self):
"""Test that pulse gates are assembled efficiently for backends that enable
parametric pulses.
Expand Down

0 comments on commit fa67e0b

Please sign in to comment.