Skip to content

Commit

Permalink
Remove deprecated pulse-builder contexts (Qiskit#8697)
Browse files Browse the repository at this point in the history
* Remove qiskit.pulse.builder.inline as deprecated in 0.18.0 (2021-07-13)

* remove imports

* remove test

* Remove qiskit.pulse.builder.pad as deprecated in 0.18.0 (2021-07-13)

* reno

* Reword removal note

Co-authored-by: Jake Lishman <[email protected]>
  • Loading branch information
2 people authored and ewinston committed Sep 8, 2022
1 parent ee0a4f1 commit bb41815
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 84 deletions.
2 changes: 0 additions & 2 deletions qiskit/pulse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@
align_sequential,
circuit_scheduler_settings,
frequency_offset,
inline,
pad,
phase_offset,
transpiler_settings,
# Macros.
Expand Down
60 changes: 0 additions & 60 deletions qiskit/pulse/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,6 @@
align_sequential
circuit_scheduler_settings
frequency_offset
inline
pad
phase_offset
transpiler_settings
Expand Down Expand Up @@ -442,7 +440,6 @@
import contextvars
import functools
import itertools
import warnings
from contextlib import contextmanager
from typing import (
Any,
Expand Down Expand Up @@ -473,7 +470,6 @@
macros,
library,
transforms,
utils,
)
from qiskit.pulse.instructions import directives
from qiskit.pulse.schedule import Schedule, ScheduleBlock
Expand Down Expand Up @@ -1372,62 +1368,6 @@ def general_transforms(alignment_context: AlignmentKind) -> ContextManager[None]
builder.append_block(current)


@utils.deprecated_functionality
@contextmanager
def inline() -> ContextManager[None]:
"""Deprecated. Inline all instructions within this context into the parent context,
inheriting the scheduling policy of the parent context.
.. warning:: This will cause all scheduling directives within this context
to be ignored.
"""

def _flatten(block):
for inst in block.blocks:
if isinstance(inst, ScheduleBlock):
yield from _flatten(inst)
else:
yield inst

builder = _active_builder()

# set a placeholder
builder.push_context(transforms.AlignLeft())
try:
yield
finally:
placeholder = builder.pop_context()
for inst in _flatten(placeholder):
builder.append_instruction(inst)


@contextmanager
def pad(*chs: chans.Channel) -> ContextManager[None]: # pylint: disable=unused-argument
"""Deprecated. Pad all available timeslots with delays upon exiting context.
Args:
chs: Channels to pad with delays. Defaults to all channels in context
if none are supplied.
Yields:
None
"""
warnings.warn(
"Context-wise padding is being deprecated. Requested padding is being ignored. "
"Now the pulse builder generate a program in `ScheduleBlock` representation. "
"The padding with delay as a blocker is no longer necessary for this program. "
"However, if you still want delays, you can convert the output program "
"into `Schedule` representation by calling "
"`qiskit.pulse.transforms.target_qobj_transform`. Then, you can apply "
"`qiskit.pulse.transforms.pad` to the converted schedule. ",
DeprecationWarning,
)
try:
yield
finally:
pass


@contextmanager
def transpiler_settings(**settings) -> ContextManager[None]:
"""Set the currently active transpiler settings for this context.
Expand Down
8 changes: 8 additions & 0 deletions releasenotes/notes/qiskit.pulse.builder-ddefe88dca5765b9.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
upgrade:
- |
The ``qiskit.pulse.builder`` contexts ``inline`` and ``pad`` have been
removed. These were first deprecated in Terra 0.18.0 (July 2021). There is
no replacement for ``inline``; one can simply write the pulses in the
containing scope. The ``pad`` context manager has had no effect since it
was deprecated.
22 changes: 0 additions & 22 deletions test/python/pulse/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,28 +184,6 @@ def test_align_right(self):

self.assertScheduleEqual(schedule, reference)

def test_inline(self):
"""Test the inlining context."""
d0 = pulse.DriveChannel(0)
d1 = pulse.DriveChannel(1)

with pulse.build() as schedule:
pulse.delay(3, d0)
with pulse.inline():
# this alignment will be ignored due to inlining.
with pulse.align_right():
pulse.delay(5, d1)
pulse.delay(7, d0)

reference = pulse.Schedule()
# d0
reference += instructions.Delay(3, d0)
reference += instructions.Delay(7, d0)
# d1
reference += instructions.Delay(5, d1)

self.assertScheduleEqual(schedule, reference)

def test_transpiler_settings(self):
"""Test the transpiler settings context.
Expand Down

0 comments on commit bb41815

Please sign in to comment.