qat.middleend.passes.transform module

class BatchedShots(target_data)

Bases: TransformPass

Determines how shots should be grouped when the total number exceeds that maximum allowed.

The target machine might have an allowed number of shots that can be executed by a single execution call. To execute a number of shots greater than this value, shots can be batched, with each batch executed by its own “execute” call on the target machine. For example, if the maximum number of shots for a target machine is 2000, but you required 4000 shots, then this could be done as [2000, 2000] shots.

Now consider the more complex scenario where 4001 shots are required. Clearly this can be done in three batches. While it is tempting to do this in batches of [2000, 2000, 1], for some target machines, specification of the number of shots can only be achieved at compilation (as opposed to runtime). Batching as described above would result in us needing to compile two separate programs. Instead, it makes more sense to batch the shots as three lots of 1334 shots, which gives a total of 4002 shots. The extra two shots can just be discarded at run time.

Warning

This pass makes certain assumptions about the IR, including that there is only at most one Repeat instruction that contributes to the number of readouts, and there is at most one readout per shot. It will change the number of shots in the Repeat instruction to the decided batch size, and store the total required shots in the IR, which is less than ideal. It would be nice to save this as an analysis result, but an unfortante side effect of the decoupled nature of the middle- and back-end is that the results manager might not necessarily be passed along.

Parameters:

target_data (TargetData) – Target-related information.

run(ir, *args, **kwargs)
Parameters:

ir (InstructionBuilder) – The list of instructions stored in an InstructionBuilder.

class InstructionLengthSanitisation(target_data)

Bases: TransformPass

Checks if quantum instructions are too long and splits if necessary.

Parameters:

duration_limit – The maximum allowed clock cycles per instruction.

Warning

The pass will assume that the durations of instructions are sanitised to the granularity of the pulse channels. If instructions that do not meet the criteria are provided, it might produce incorrect instructions (i.e., instructions that are shorter than the clock cycle). This can be enforced using the InstructionGranularitySanitisation pass.

run(ir, *args, **kwargs)
Parameters:

ir (InstructionBuilder) – The list of instructions stored in an InstructionBuilder.

class PhaseOptimisation

Bases: TransformPass

Iterates through the list of instructions and compresses contiguous PhaseShift instructions.

run(ir, res_mgr, met_mgr, *args, **kwargs)
Parameters:
  • ir (InstructionBuilder) – The list of instructions stored in an InstructionBuilder.

  • res_mgr (ResultManager) – The result manager to save the analysis results.

  • met_mgr (MetricsManager) – The metrics manager to store the number of instructions after optimisation.

class PostProcessingSanitisation

Bases: TransformPass

Checks that the PostProcessing instructions that follow an acquisition are suitable for the acquisition mode, and removes them if not.

Extracted from qat.purr.backends.live.LiveDeviceEngine.optimize().

run(ir, _, met_mgr, *args, **kwargs)
Parameters:
  • ir (InstructionBuilder) – The list of instructions stored in an InstructionBuilder.

  • met_mgr (MetricsManager) – The metrics manager to store the number of instructions after optimisation.

PydBatchedShots

alias of BatchedShots

PydInstructionLengthSanitisation

alias of InstructionLengthSanitisation

PydPhaseOptimisation

alias of PhaseOptimisation

PydPostProcessingSanitisation

alias of PostProcessingSanitisation

PydRepeatTranslation

alias of RepeatTranslation

PydResetsToDelays

alias of ResetsToDelays

PydReturnSanitisation

alias of ReturnSanitisation

PydScopeSanitisation

alias of ScopeSanitisation

PydSquashDelaysOptimisation

alias of SquashDelaysOptimisation

class RepeatTranslation(target_data)

Bases: TransformPass

Transform Repeat instructions so that they are replaced with: Variable, Assign, and Label instructions at the start, and Assign and Jump instructions at the end.

run(ir, *args, **kwargs)
Parameters:

ir (InstructionBuilder) – The list of instructions stored in an InstructionBuilder.

Return type:

InstructionBuilder

class RepeatTranslationHandler

Bases: object

Handler used by PydRepeatTranslation to manage the translation of Repeat and EndRepeat instructions.

close_repeats()
run(instruction)

Default handler for instructions that do not have a specific repeat translation.

class ResetsToDelays(model, target_data)

Bases: TransformPass

Transforms Reset operations to :class:`Delay`s.

Note that the delays do not necessarily agree with the granularity of the underlying target machine. This can be enforced using the InstructionGranularitySanitisation pass.

Parameters:
  • model (PhysicalHardwareModel) – The hardware model that holds calibrated information on the qubits on the QPU.

  • target_data (TargetData) – Target-related information.

run(ir, res_mgr, *args, **kwargs)
Parameters:
Return type:

InstructionBuilder

class ReturnSanitisation

Bases: TransformPass

Squashes all Return instructions into a single one. Adds a Return with all acquisitions if none is found.

run(ir, *args, **kwargs)
Parameters:

ir (InstructionBuilder) – The list of instructions stored in an InstructionBuilder.

class ScopeSanitisation

Bases: TransformPass

Bubbles up all sweeps and repeats to the beginning of the list and adds delimiter instructions to the repeats and sweeps signifying the end of their scopes.

Warning

This pass is intended for use with legacy builders that do not use EndRepeat and EndSweep instructions. It will add a delimiter instruction for each Repeat and Sweep found in the IR.

run(ir, *args, **kwargs)
Parameters:

ir (InstructionBuilder) – The list of instructions stored in an InstructionBuilder.

class SquashDelaysOptimisation

Bases: TransformPass

Looks for consecutive Delay instructions on a pulse channel and squashes them into a single instruction.

Because Synchronize instructions across multiple pulse channels are used so frequently to ensure pulses play at the correct timings, it means we can have sequences of many delays. Reducing the number of delays will simplify timing analysis later in the compilation.

Delay instructions commute with phase related instructions, so the only instructions that separate delays in a meaningful way are: Pulse:, CustomPulse and Acquire instructions. We also need to be careful to not squash delays that contain a variable time.

run(ir, res_mgr, met_mgr, *args, **kwargs)
Parameters:
  • ir (InstructionBuilder) – The list of instructions stored in an InstructionBuilder.

  • res_mgr (ResultManager) – The result manager to save the analysis results.

  • met_mgr (MetricsManager) – The metrics manager to store the number of instructions after optimisation.