qat.experimental.frontend.importer.purr module

class PurrImporter

Bases: BaseLinearImporter

Concrete BaseLinearImporter for the legacy Purr IR.

Walks a QuantumInstructionBuilder and emits an equivalent ModuleOp in the Pulse dialect. Pulse channels are lowered to FrameType SSA values which are then tracked via the _environment_variable map. Repeat / Sweep instructions are translated into scf.ForOps with SSA values appreciate flowing through them. Purr IR variables (and frames) are global.

Initialise an empty module with a main function and empty environment.

Creates a fresh ModuleOp containing a single func.FuncOp named main, sets the function body’s block as the current insertion point, and installs an empty bidict as the environment-variable map.

build(purr_ir)

Translate all instructions in purr_ir into the Pulse dialect.

Parameters:

purr_ir (QuantumInstructionBuilder) – A populated Purr instruction builder.

Return type:

ModuleOp

Returns:

An xDSL ModuleOp containing the translated Pulse-dialect operations.

create_frame(target, freq_op=None)

Create a new Pulse-dialect frame for target.

Emits a FrameType (and, when needed, a ConstantOp for the frequency and ``CreateFrameOp) in the current block.

Parameters:
  • target (PulseChannel) – The Purr pulse channel to create a frame for.

  • freq_op (Union[IRDLOperation, SSAValue, None]) – An optional pre-built op or SSA value carrying the frame’s frequency. When None a fresh ConstantOp is synthesised from target.frequency. When an IRDLOperation is supplied it is also inserted into the current block.

Return type:

SSAValue

Returns:

The SSA value representing the new frame.

static get_frame_key(quantum_target)

Return the environment-variable key used for quantum_target.

Pulse channel-derived key from Purr pulse channel id used as variable names for frames.

Parameters:

quantum_target (PulseChannel) – The Purr pulse channel.

Return type:

str

Returns:

A string key for a Pulse Channel.

get_frames(quantum_targets)

Look up or create Pulse-dialect frames for quantum_targets.

Searches the environment-variable map for an existing frame keyed by get_frame_key(). When no binding is found a new frame is created in the current block and registered in the environment.

Parameters:

quantum_targets (list[PulseChannel]) – Purr pulse channels to resolve.

Return type:

list[SSAValue]

Returns:

Ordered list of SSA frame values corresponding to each target.

translate(instruction)

Dispatch instruction to the appropriate Pulse-dialect emitter.

Uses functools.singledispatchmethod() to select a handler based on the concrete QuantumInstruction subclass.

Parameters:

instruction (QuantumInstruction) – The Purr instruction to translate.

Raises:

ValueError – If no handler is registered for the instruction type.

Return type:

None