qat.experimental.frontend.importer.purr module
- class PurrImporter
Bases:
BaseLinearImporterConcrete
BaseLinearImporterfor the legacy Purr IR.Walks a
QuantumInstructionBuilderand emits an equivalentModuleOpin the Pulse dialect. Pulse channels are lowered toFrameTypeSSA values which are then tracked via the_environment_variablemap.Repeat/Sweepinstructions 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
mainfunction and empty environment.Creates a fresh
ModuleOpcontaining a singlefunc.FuncOpnamedmain, sets the function body’s block as the current insertion point, and installs an emptybidictas 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
ModuleOpcontaining 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, aConstantOpfor 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. WhenNonea freshConstantOpis synthesised fromtarget.frequency. When anIRDLOperationis 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 concreteQuantumInstructionsubclass.- Parameters:
instruction¶ (
QuantumInstruction) – The Purr instruction to translate.- Raises:
ValueError – If no handler is registered for the instruction type.
- Return type:
None