qat.runtime.post_processing module
Runtime post-processing utilities.
This module provides helpers to map raw IQ readout arrays into processed
forms expected by higher-level code. It implements the supported legacy
PostProcessType operations (mean, linear map, discriminate), plus the
granular post-processing pipeline functions (apply_equalise(),
apply_discriminate_instruction(), apply_post_select()) and small helpers
for axis bookkeeping.
For a full description of the granular pipeline and how each step fits together, see the post_processing_pipeline guide.
The legacy LINEAR_MAP_COMPLEX_TO_REAL path is preserved unchanged for
backward compatibility.
- apply_discriminate_instruction(response, instr, axes)
Runtime implementation of
qat.ir.measure.Discriminate.Discriminate equalised values to integer state keys using a
Discriminateinstruction.For the threshold path (
instr.threshold is not None) values above the threshold map to0and values at or below map to1.For the ML path (
instr.methodis set) normalised Gaussian likelihoods are computed using a single globalnoise_est; the state with the highest likelihood wins and its dict key (the integer fromMaxLikelihoodMethod.states) is returned directly. Likelihoods are computed in log-domain with log-sum-exp stabilisation to avoid underflow. Whenp_min > 0, shots below the minimum confidence threshold are assignedBG_KEY.- Parameters:
response¶ (
ndarray) – Equalised (real or complex) readout array.instr¶ (
Discriminate) – TheDiscriminateinstruction.axes¶ (
dict[ProcessAxis,int]) – Current axis map.
- Return type:
tuple[ndarray,dict[ProcessAxis,int]]- Returns:
Integer state-key array and unchanged axis map.
- apply_equalise(response, instr, axes)
Runtime implementation of
qat.ir.measure.Equalise.Applies the affine
[I', Q'] = A @ [I, Q] + btransform to the complex readout array and returns the result as a complex arrayI' + j Q'.- Parameters:
- Return type:
tuple[ndarray,dict[ProcessAxis,int]]- Returns:
Complex-valued transformed data and unchanged axis map.
- Raises:
ValueError – If
instr.transformis not shape(2, 2)orinstr.offsetis not shape(2,).
- apply_post_processing(response, post_processing, axes)
Applies software post processing to the results.
Uses the information in the
PostProcessinginstruction to determine what method to apply.- Parameters:
response¶ (
ndarray) – Readout results from an execution engine.post_processing¶ (
PostProcessing) – The post processing instruction.axes¶ (
dict[ProcessAxis,int]) – A dictionary containing which axes contain the shots and which contain time series.
- Return type:
tuple[ndarray,dict[ProcessAxis,int]]- Returns:
The processed results as an array and the axis map.
- apply_post_select(state_keys, instr, axes)
Runtime implementation of
qat.ir.measure.PostSelect.Build a per-shot validity mask from a
PostSelectinstruction.A shot is marked
False(invalid) when either:Its integer state key is negative — negative keys encode disallowed states and the
p_minbackground sentinel (BG_KEY), orIts integer state key appears in
additional_disallowed— used by the pre-selection pass to reject specific non-negative states without re-keying theDiscriminatemethod.
- Parameters:
state_keys¶ (
ndarray) – Integer state-key array produced by aDiscriminatestep.instr¶ (
PostSelect) – ThePostSelectinstruction.axes¶ (
dict[ProcessAxis,int]) – Current axis map (not used; present for interface consistency).
- Return type:
tuple[ndarray,ndarray]- Returns:
A tuple of
(state_keys, validity_mask)wherevalidity_maskis a boolean ndarray with the same shape asstate_keys.
- discriminate(response, axes, threshold)
Discriminates a real value to a classical bit by comparison to a supplied discrimination threshold.
- Parameters:
- Returns:
The processed results as an array and the axis map.
- get_axis_map(mode, response)
Given the acquisition mode, determine what each axis corresponds to.
The way the results are returned are defined by the acquisition mode: this could be averaged over shots, averaged over time, or neither. We must determine how to unpack the results.
- linear_map_complex_to_real(response, axes, multiplier, constant)
Maps complex values onto a real z-projection using a provided linear mapping.
- Parameters:
response¶ (np.ndarray) – Readout results from an execution engine.
axes¶ (dict[ProcessAxis, Int]) – A dictionary containing which axes contain the shots and which contain time series.
multiplier¶ (numbers.Number) – Coeffecient for the linear map.
constant¶ (numbers.Number) – Constant for the linear map.
- Returns:
The processed results as an array and the axis map.
- mean(response, axes, target_axes)
Calculates the mean over the given axes.
- Parameters:
- Returns:
The processed results as an array and the axis map.