qat.experimental.conversion.pulse_to_q1.rewrite_patterns module
Rewrite patterns for the Pulse-to-Q1 phase legalisation and lowering stages.
- class LowerArithIntegerConstantToMoveOp
Bases:
ModulePass,RewritePatternLower
arith.constantwith an integer or index type toq1.ir.move.An
arith.constantwhose result type isIntegerTypeorIndexTypeis replaced by aq1.ir.moveinstruction that loads the same immediate value into a virtual register. Constants whose result type is not an integer or index (e.g. floating-point) are left unchanged.The immediate must fit in the 32-bit signed-or-unsigned range accepted by
q1.ir.move(SU32Imm:[-2**31, 2**32 - 1]). Values outside that range raisePassFailedException.- apply(ctx, op)
- Return type:
None
- match_and_rewrite(op: Operation, rewriter: PatternRewriter) None
Match an operation, and optionally perform a rewrite using the rewriter.
- Return type:
None
- name: ClassVar[str] = 'lower-arith-integer-constant-to-move'
- class RewritePhaseSetOp(target_data, rewrite_callable)
Bases:
RewritePatternMatch
pulse.phase_setand delegate stage policy torewrite_callable.The same matcher is used in legalisation and lowering. The callable decides whether the rewrite remains in Pulse or emits Q1 instructions.
- match_and_rewrite(op: Operation, rewriter: PatternRewriter) None
Match an operation, and optionally perform a rewrite using the rewriter.
- Return type:
None
- class RewritePhaseShiftOp(target_data, rewrite_callable)
Bases:
RewritePatternMatch
pulse.phase_shiftand delegate stage policy torewrite_callable.Mirrors
RewritePhaseSetOpin structure.- match_and_rewrite(op: Operation, rewriter: PatternRewriter) None
Match an operation, and optionally perform a rewrite using the rewriter.
- Return type:
None
- class RewritePreQ1AcquireOp(target_data)
Bases:
RewritePatternLower
PreQ1AcquireOpto a Q1 acquire instruction.AcquireImmRsImmOpwhen no integration weights are present.AcquireWeightedImmRsRsRsImmOpwhen aWeightsAttris present.
The acquisition, and any integration weights, are registered on the enclosing
SequenceOpand assigned hardware indices in encounter order. Q1 requires the bin and weight indices to be supplied in registers. Bin indices retain their upstream value, while static weight indices are materialised directly as Q1 moves to unallocated integer registers. A later register-allocation pass assigns concrete Q1 GPRs.- match_and_rewrite(op: Operation, rewriter: PatternRewriter) None
Match an operation, and optionally perform a rewrite using the rewriter.
- Return type:
None
- class RewritePulseOp(target_data)
Bases:
RewritePatternLowers a
pulse.pulseop to a Q1playinstruction.The pattern resolves the pulse’s sampled waveform, registers its real (I) and imaginary (Q) sample vectors in the enclosing sequence’s waveform table, and replaces the
pulse.pulseop with aPlayImmImmImmOpthat references the two table indices and the waveform duration. The now-unused waveformConstantOp[SampledWaveformAttr]is erased once no other op consumes it.Distinct sampled waveforms are assumed to have been folded and de-duplicated upstream, so identical waveforms share a single
ConstantOp. Each such op is therefore registered in the waveform table only once per sequence. Subsequent pulses referencing the same op reuse the cached table indices instead of re-comparing sample arrays.Initialise the pattern.
- Parameters:
target_data¶ (
QbloxTargetData) – Qblox target data used during lowering.
- match_and_rewrite(op: Operation, rewriter: PatternRewriter) None
Match an operation, and optionally perform a rewrite using the rewriter.
- Return type:
None
- class RewriteStartContinuousWaveformOp(target_data)
Bases:
RewritePatternLowers a
pulse.start_continuous_waveformop to a Q1 AWG offset.A continuous waveform is emitted on Q1 hardware by latching a constant AWG offset on both output paths. This pattern replaces the pulse op with a
SetAwgOffsImmImmOpcarrying the I and Q offsets scaled to the DAC range. Assumes Square waves have been legalised to StartContinuousWaveformOp, Delay, and StopContinuousWaveformOp.Initialise the pattern.
- Parameters:
target_data¶ (
QbloxTargetData) – Qblox target data used during lowering.
- match_and_rewrite(op: Operation, rewriter: PatternRewriter) None
Match an operation, and optionally perform a rewrite using the rewriter.
- Return type:
None
- class RewriteStopContinuousWaveformOp(target_data)
Bases:
RewritePatternLowers a
pulse.stop_continuous_waveformop to a Q1 AWG offset reset.Stopping a continuous waveform corresponds to clearing the latched AWG offset on both output paths, emitted as a
SetAwgOffsImmImmOpwith zero offsets. Assumes Square waves have been legalised to StartContinuousWaveformOp, Delay, and StopContinuousWaveformOp.Initialise the pattern.
- Parameters:
target_data¶ (
QbloxTargetData) – Qblox target data used during lowering.
- match_and_rewrite(op: Operation, rewriter: PatternRewriter) None
Match an operation, and optionally perform a rewrite using the rewriter.
- Return type:
None
- class RewriteWaitOp(target_data)
Bases:
RewritePatternLower
pulse.waitto one or moreq1.waitinstructions.The requested duration is converted from seconds to nanoseconds and aligned up to the sequencer grid time. Durations that exceed the maximum wait immediate are split into a chain of
q1.waitinstructions whose durations sum to the requested value. The frame carried bypulse.waitis forwarded to downstream operations.Register-driven durations that do not fold to a compile-time constant are left untouched. Those are handled elsewhere and are out of scope for this lowering.
- match_and_rewrite(op: Operation, rewriter: PatternRewriter) None
Match an operation, and optionally perform a rewrite using the rewriter.
- Return type:
None
- create_legalisation_patterns()
Create the rewrite set used by the legalisation stage.
Canonicalises
pulse.phase_setandpulse.phase_shiftoperands inside the Pulse dialect. New legalisation behaviour can be added here without touching the lowering factory.- Return type:
tuple[RewritePattern,...]- Returns:
Ordered pattern tuple for the legalisation pass.
- create_pulse_to_q1_lowering_patterns(target_data=QbloxTargetData(max_acquisitions=10000, default_shots=1000, QUBIT_DATA=QubitDescription(sample_time=1e-09, samples_per_clock_cycle=1, instruction_memory_size=50000, waveform_memory_size=1500, pulse_duration_min=6.4e-08, pulse_duration_max=0.001, pulse_channel_lo_freq_min=1000000, pulse_channel_lo_freq_max=10000000000, pulse_channel_if_freq_min=0, pulse_channel_if_freq_max=10000000000, passive_reset_time=0.001), RESONATOR_DATA=ResonatorDescription(sample_time=1e-09, samples_per_clock_cycle=1, instruction_memory_size=50000, waveform_memory_size=1500, pulse_duration_min=6.4e-08, pulse_duration_max=0.001, pulse_channel_lo_freq_min=1000000, pulse_channel_lo_freq_max=10000000000, pulse_channel_if_freq_min=0, pulse_channel_if_freq_max=10000000000), driver_version=SemanticVersion(major=1, minor=3, patch=1, prerelease=None, build=None), fw_version=SemanticVersion(major=0, minor=13, patch=0, prerelease=None, build=None), Q1ASM_DATA=Q1asmDescription(min_gain=-32768, max_gain=32767, min_offset=-32768, max_offset=32767, max_wait_time=65532, register_size=4294967295, loop_unroll_threshold=4), CONTROL_SEQUENCER_DATA=ControlSequencerDescription(grid_time=4, nco_min_freq=-500000000.0, nco_max_freq=500000000.0, nco_max_phase_steps=1000000000, nco_phase_steps_per_deg=2777777.777777778, nco_freq_steps_per_hz=4, nco_freq_limit_steps=2000000000.0, number_of_registers=64, min_acq_integration_length=4, max_acq_integration_length=16777212, min_acq_threshold=-16777212, max_acq_threshold=16777212, max_sample_size_waveforms=16384, max_num_instructions=16384, sample_rate=1000000000.0), READOUT_SEQUENCER_DATA=ReadoutSequencerDescription(grid_time=4, nco_min_freq=-500000000.0, nco_max_freq=500000000.0, nco_max_phase_steps=1000000000, nco_phase_steps_per_deg=2777777.777777778, nco_freq_steps_per_hz=4, nco_freq_limit_steps=2000000000.0, number_of_registers=64, min_acq_integration_length=4, max_acq_integration_length=16777212, min_acq_threshold=-16777212, max_acq_threshold=16777212, max_sample_size_waveforms=16384, max_num_instructions=12288, sample_rate=1000000000.0), QCM_DATA=QcmDescription(number_of_sequencers=6, min_qcm_offset_v=-2.5, max_qcm_offset_v=2.5, output_connections={0: [0, 1, 2, 3, 4, 5], 1: [0, 1, 2, 3, 4, 5], 2: [0, 1, 2, 3, 4, 5], 3: [0, 1, 2, 3, 4, 5]}), QCM_RF_DATA=QcmRfDescription(number_of_sequencers=6, min_qcm_rf_offset_mv=-84, max_qcm_rf_offset_mv=73, min_out_att_db=0, max_out_att_db=60, output_connections={0: [0, 1, 2, 3, 4, 5], 1: [0, 1, 2, 3, 4, 5]}), QRM_DATA=QrmDescription(number_of_sequencers=6, min_sample_size_scope_acquisitions=4, max_sample_size_scope_acquisitions=16384, max_binned_acquisitions=3000000, min_qrm_offset_v=-0.09, max_qrm_offset_v=0.09, output_connections={0: [0, 1, 2, 3, 4, 5], 1: [0, 1, 2, 3, 4, 5]}, input_connections={0: [0, 1, 2, 3, 4, 5], 1: [0, 1, 2, 3, 4, 5]}), QRM_RF_DATA=QrmRfDescription(number_of_sequencers=6, min_sample_size_scope_acquisitions=4, max_sample_size_scope_acquisitions=16384, max_binned_acquisitions=3000000, min_qrm_rf_offset_v=-0.09, max_qrm_rf_offset_v=0.09, min_out_att_db=0, max_out_att_db=60, min_in_att_db=0, max_in_att_db=30, output_connections={0: [0, 1, 2, 3, 4, 5]}, input_connections={0: [0, 1, 2, 3, 4, 5]}), QRC_DATA=QrcDescription(number_of_sequencers=12, min_sample_size_scope_acquisitions=4, max_sample_size_scope_acquisitions=16384, max_binned_acquisitions=7000000, number_of_readout_sequencers=8, number_of_control_sequencers=4, min_out_att_db=0.0, max_out_att_db=31.5, min_in_att_db=0.0, max_in_att_db=31.5, output_connections={0: [0, 1, 2, 3, 4, 5, 6, 7], 1: [0, 1, 2, 3, 4, 5, 6, 7], 2: [0, 4, 8, 9, 10, 11], 3: [1, 5, 8, 9, 10, 11], 4: [2, 6, 8, 9, 10, 11], 5: [3, 7, 8, 9, 10, 11]}, input_connections={0: [0, 1, 2, 3, 4, 5, 6, 7], 1: [0, 1, 2, 3, 4, 5, 6, 7]})))
Create the rewrite set used by the lowering stage.
Phase entries are configured with
PhaseLowering. Wait, finite pulse, continuous-waveform, and acquisition patterns lower their Pulse or pre-Q1 operations to Q1 instructions. Pulse preprocessing owns synchronization, while hardware configuration resolution owns initial NCO frequency.- Parameters:
target_data¶ (
QbloxTargetData) – Qblox limits used during lowering.- Return type:
tuple[RewritePattern,...]- Returns:
Ordered pattern tuple for the lowering pass.