Skip to content

Commit

Permalink
Update instruction name AreaBarrier -> TimeBlockade
Browse files Browse the repository at this point in the history
  • Loading branch information
nkanazawa1989 committed Oct 24, 2022
1 parent a69aac0 commit 1f1db8d
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 22 deletions.
2 changes: 1 addition & 1 deletion qiskit/pulse/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ def _naive_typecast_schedule(schedule: Schedule):
from qiskit.pulse.transforms import inline_subroutines, flatten, pad

preprocessed_schedule = inline_subroutines(flatten(schedule))
pad(preprocessed_schedule, inplace=True, pad_with=instructions.AreaBarrier)
pad(preprocessed_schedule, inplace=True, pad_with=instructions.TimeBlockade)

# default to left alignment, namely ASAP scheduling
target_block = ScheduleBlock(name=schedule.name)
Expand Down
2 changes: 1 addition & 1 deletion qiskit/pulse/instructions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"""
from .acquire import Acquire
from .delay import Delay
from .directives import Directive, RelativeBarrier, AreaBarrier
from .directives import Directive, RelativeBarrier, TimeBlockade
from .call import Call
from .instruction import Instruction
from .frequency import SetFrequency, ShiftFrequency
Expand Down
27 changes: 19 additions & 8 deletions qiskit/pulse/instructions/directives.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# that they have been altered from the originals.

"""Directives are hints to the pulse compiler for how to process its input programs."""

import numpy as np
from abc import ABC
from typing import Optional, Tuple

Expand Down Expand Up @@ -57,13 +57,13 @@ def __eq__(self, other):
return isinstance(other, type(self)) and set(self.channels) == set(other.channels)


class AreaBarrier(Directive):
"""Pulse ``AreaBarrier`` directive.
class TimeBlockade(Directive):
"""Pulse ``TimeBlockade`` directive.
This instruction is intended to be used internally within the pulse builder,
to naively convert :class:`.Schedule` into :class:`.ScheduleBlock`.
Becasue :class:`.ScheduleBlock` cannot take absolute instruction interval,
this instruction helps the block represetation with finding instruction starting time.
Because :class:`.ScheduleBlock` cannot take absolute instruction time interval,
this instruction helps the block representation with finding instruction starting time.
Example:
Expand All @@ -79,7 +79,7 @@ class AreaBarrier(Directive):
.. code-block:: python
block = ScheduleBlock()
block.append(AreaBarrier(120, DriveChannel(0)))
block.append(TimeBlockade(120, DriveChannel(0)))
block.append(Play(Constant(10, 0.1), DriveChannel(0)))
Such conversion may be done by
Expand All @@ -93,9 +93,9 @@ class AreaBarrier(Directive):
.. note::
The AreaBarrier instruction behaves almost identically
The TimeBlockade instruction behaves almost identically
to :class:`~qiskit.pulse.instructions.Delay` instruction.
However, the AreaBarrier is just a compiler directive and must be removed before execution.
However, the TimeBlockade is just a compiler directive and must be removed before execution.
This may be done by :func:`~qiskit.pulse.transforms.remove_directives` transform.
Once these directives are removed, occupied timeslots are released and
user can insert another instruction without timing overlap.
Expand All @@ -116,6 +116,17 @@ def __init__(
"""
super().__init__(operands=(duration, channel), name=name)

def _validate(self):
"""Called after initialization to validate instruction data.
Raises:
PulseError: If the input ``duration`` is not integer value.
"""
if not isinstance(self.duration, int):
raise TypeError(
"TimeBlockade duration cannot be parameterized. Specify an integer duration value."
)

@property
def channel(self) -> chans.Channel:
"""Return the :py:class:`~qiskit.pulse.channels.Channel` that this instruction is
Expand Down
12 changes: 6 additions & 6 deletions qiskit/qpy/type_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
SetPhase,
ShiftPhase,
RelativeBarrier,
AreaBarrier,
TimeBlockade,
)
from qiskit.pulse.library import Waveform, SymbolicPulse
from qiskit.pulse.schedule import ScheduleBlock
Expand Down Expand Up @@ -232,7 +232,7 @@ class ScheduleInstruction(TypeKeyBase):
SET_PHASE = b"q"
SHIFT_PHASE = b"r"
BARRIER = b"b"
AREA_BARRIER = b"c"
TimeBlockade = b"t"

# 's' is reserved by ScheduleBlock, i.e. block can be nested as an element.
# Call instructon is not supported by QPY.
Expand All @@ -259,8 +259,8 @@ def assign(cls, obj):
return cls.SHIFT_PHASE
if isinstance(obj, RelativeBarrier):
return cls.BARRIER
if isinstance(obj, AreaBarrier):
return cls.AREA_BARRIER
if isinstance(obj, TimeBlockade):
return cls.TimeBlockade

raise exceptions.QpyError(
f"Object type '{type(obj)}' is not supported in {cls.__name__} namespace."
Expand All @@ -284,8 +284,8 @@ def retrieve(cls, type_key):
return ShiftPhase
if type_key == cls.BARRIER:
return RelativeBarrier
if type_key == cls.AREA_BARRIER:
return AreaBarrier
if type_key == cls.TimeBlockade:
return TimeBlockade

raise exceptions.QpyError(
f"A class corresponding to type key '{type_key}' is not found in {cls.__name__} namespace."
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
---
features:
- |
New pulse directive :class:`~qiskit.pulse.instructions.AreaBarrier` has been added.
New pulse directive :class:`~qiskit.pulse.instructions.TimeBlockade` has been added.
This instruction is QPY compatible. This directive behaves almost identically to
delay instruction, but will be removed before execution.
This directive is intended to be used internally within the pulse builder
and helps :class:`.ScheduleBlock` represent instructions with
absolute time intervals. This allows the pulse builder to convert
:class:`Schedule` into :class:`ScheduleBlock`, rather than wrapping with call instruction.
- |
QPY dump and load now support :class:`~qiskit.pulse.instructions.AreaBarrier` instruction.
QPY dump and load now support :class:`~qiskit.pulse.instructions.TimeBlockade` instruction.
upgrade:
- |
The behavior of the pulse builder when a :class:`.Schedule` is called
Expand Down
8 changes: 4 additions & 4 deletions test/python/qpy/test_block_load_from_qpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
MemorySlot,
RegisterSlot,
)
from qiskit.pulse.instructions import Play, AreaBarrier
from qiskit.pulse.instructions import Play, TimeBlockade
from qiskit.circuit import Parameter, QuantumCircuit, Gate
from qiskit.test import QiskitTestCase
from qiskit.qpy import dump, load
Expand Down Expand Up @@ -155,7 +155,7 @@ def test_barrier(self):
def test_area_barrier(self):
"""Test area barrier."""
with builder.build() as test_sched:
builder.append_instruction(AreaBarrier(10, DriveChannel(0)))
builder.append_instruction(TimeBlockade(10, DriveChannel(0)))
self.assert_roundtrip_equal(test_sched)

def test_measure(self):
Expand Down Expand Up @@ -197,8 +197,8 @@ def test_nested_blocks(self):
def test_called_schedule(self):
"""Test referenced pulse Schedule object.
Referened object is naively converted into ScheduleBlock with AreaBarrier instructions.
Thus referenced Schedule is still QPY compatibile.
Referenced object is naively converted into ScheduleBlock with TimeBlockade instructions.
Thus referenced Schedule is still QPY compatible.
"""
refsched = Schedule()
refsched.insert(20, Play(Constant(100, 0.1), DriveChannel(0)))
Expand Down

0 comments on commit 1f1db8d

Please sign in to comment.