Skip to content

Commit

Permalink
DAG Based Pulse IR (#11951)
Browse files Browse the repository at this point in the history
* Basic implementation

* Add align right, align sequential (sequence+schedule)

* Add draw, flatten

* Corrections

* Split into separate IR PR (temporary remove tests which rely on passes)

* Update qiskit/pulse/ir/ir.py

Co-authored-by: Naoki Kanazawa <nkanazawa1989@gmail.com>

* Corrections.

* Add to do.

* Fixes

* Disable lint

---------

Co-authored-by: Naoki Kanazawa <nkanazawa1989@gmail.com>
  • Loading branch information
TsafrirA and nkanazawa1989 committed Mar 8, 2024
1 parent 646e7ef commit 107aa13
Show file tree
Hide file tree
Showing 7 changed files with 656 additions and 565 deletions.
8 changes: 4 additions & 4 deletions qiskit/pulse/compiler/basepasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from qiskit.passmanager.base_tasks import GenericPass
from qiskit.transpiler.target import Target
from qiskit.pulse.ir import IrBlock
from qiskit.pulse.ir import SequenceIR


class TransformationPass(GenericPass, ABC):
Expand All @@ -42,8 +42,8 @@ def __init__(
@abstractmethod
def run(
self,
passmanager_ir: IrBlock,
) -> IrBlock:
passmanager_ir: SequenceIR,
) -> SequenceIR:
pass

def __hash__(self) -> int:
Expand Down Expand Up @@ -89,7 +89,7 @@ def __init__(
@abstractmethod
def run(
self,
passmanager_ir: IrBlock,
passmanager_ir: SequenceIR,
) -> None:
pass

Expand Down
24 changes: 12 additions & 12 deletions qiskit/pulse/compiler/passmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from typing import Any

from qiskit.passmanager import BasePassManager
from qiskit.pulse.ir import IrBlock, IrInstruction
from qiskit.pulse.ir import SequenceIR
from qiskit.pulse.schedule import ScheduleBlock


Expand Down Expand Up @@ -52,15 +52,15 @@ def _passmanager_frontend(
self,
input_program: ScheduleBlock,
**kwargs,
) -> IrBlock:
) -> SequenceIR:

def _wrap_recursive(_prog):
_ret = IrBlock(alignment=_prog.alignment_context)
_ret = SequenceIR(alignment=_prog.alignment_context)
for _elm in _prog.blocks:
if isinstance(_elm, ScheduleBlock):
_ret.add_element(_wrap_recursive(_elm))
_ret.append(_wrap_recursive(_elm))
else:
_ret.add_element(IrInstruction(instruction=_elm))
_ret.append(_elm)
return _ret

return _wrap_recursive(input_program)
Expand Down Expand Up @@ -121,16 +121,16 @@ def callback_func(**kwargs):
class BlockToIrCompiler(BasePulsePassManager):
"""A specialized pulse compiler for IR backend.
This compiler outputs :class:`.IrBlock`, which is an intermediate representation
This compiler outputs :class:`.SequenceIR`, which is an intermediate representation
of the pulse program in Qiskit.
"""

def _passmanager_backend(
self,
passmanager_ir: IrBlock,
passmanager_ir: SequenceIR,
in_program: ScheduleBlock,
**kwargs,
) -> IrBlock:
) -> SequenceIR:
return passmanager_ir


Expand All @@ -143,18 +143,18 @@ class BlockTranspiler(BasePulsePassManager):

def _passmanager_backend(
self,
passmanager_ir: IrBlock,
passmanager_ir: SequenceIR,
in_program: ScheduleBlock,
**kwargs,
) -> ScheduleBlock:

def _unwrap_recursive(_prog):
_ret = ScheduleBlock(alignment_context=_prog.alignment)
for _elm in _prog.elements:
if isinstance(_elm, IrBlock):
for _elm in _prog.elements():
if isinstance(_elm, SequenceIR):
_ret.append(_unwrap_recursive(_elm), inplace=True)
else:
_ret.append(_elm.instruction, inplace=True)
_ret.append(_elm, inplace=True)
return _ret

out_block = _unwrap_recursive(passmanager_ir)
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 @@ -59,7 +59,7 @@
from .acquire import Acquire
from .delay import Delay
from .directives import Directive, RelativeBarrier, TimeBlockade
from .instruction import Instruction
from .instruction import Instruction, FrameUpdate
from .frequency import SetFrequency, ShiftFrequency
from .phase import ShiftPhase, SetPhase
from .play import Play
Expand Down
3 changes: 1 addition & 2 deletions qiskit/pulse/ir/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@
=======================================
"""

from .ir import IrElement, IrBlock, IrInstruction
from .ir import SequenceIR
Loading

0 comments on commit 107aa13

Please sign in to comment.