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

Fix pulse.build() default alignment argument #12029

Merged
merged 1 commit into from
Mar 18, 2024
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/pulse/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,10 @@ def __init__(
self._context_stack.append(root_block)

# Set default alignment context
alignment = _PulseBuilder.__alignment_kinds__.get(default_alignment, default_alignment)
if isinstance(default_alignment, AlignmentKind): # AlignmentKind instance
alignment = default_alignment
else: # str identifier
alignment = _PulseBuilder.__alignment_kinds__.get(default_alignment, default_alignment)
if not isinstance(alignment, AlignmentKind):
raise exceptions.PulseError(
f"Given `default_alignment` {repr(default_alignment)} is "
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
fixes:
- |
Fixed a bug in the handling of ``default_alignment`` argument of :func:`~qiskit.pulse.build`.
Inputs of type :class:`~qiskit.pulse.transforms.AlignmentKind` are now correctly processed as
default alignments.
24 changes: 24 additions & 0 deletions test/python/pulse/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from qiskit.pulse.transforms import target_qobj_transform
from qiskit.providers.fake_provider import FakeOpenPulse2Q, Fake127QPulseV1
from qiskit.pulse import library, instructions
from qiskit.pulse.exceptions import PulseError
from test import QiskitTestCase # pylint: disable=wrong-import-order


Expand Down Expand Up @@ -106,6 +107,29 @@ def test_default_alignment_sequential(self):

self.assertScheduleEqual(schedule, reference)

def test_default_alignment_alignmentkind_instance(self):
"""Test default AlignmentKind instance"""
d0 = pulse.DriveChannel(0)
d1 = pulse.DriveChannel(0)

with pulse.build(default_alignment=pulse.transforms.AlignEquispaced(100)) as schedule:
pulse.delay(10, d0)
pulse.delay(20, d1)

with pulse.build() as reference:
with pulse.align_equispaced(100):
pulse.delay(10, d0)
pulse.delay(20, d1)

self.assertScheduleEqual(schedule, reference)

def test_unknown_string_identifier(self):
"""Test that unknown string identifier raises an error"""

with self.assertRaises(PulseError):
with pulse.build(default_alignment="unknown") as _:
pass


class TestContexts(TestBuilder):
"""Test builder contexts."""
Expand Down
Loading