sf.tdm.reshape_samples¶

reshape_samples
(all_samples, modes, N, timebins)[source]¶ Reshapes the samples dict so that they have the expected correct shape.
Corrects the
all_samples
dictionary so that the measured modes are the ones defined to be measured in the circuit, instead of being spread over a larger number of modes due to the modeshifting occurring inTDMProgram
.The function iterates through samples obtained from the unrolled circuit to populate and return a new samples dictionary with the shape
{spatial mode: (shots, timebins)}
. E.g., this unrolled circuit:... MeasureHomodyne(0)  (q[0]) # shot 0, timebin 0, spatial mode 0 (sample 0) MeasureHomodyne(0)  (q[2]) # shot 0, timebin 0, spatial mode 2 (sample 1) ... MeasureHomodyne(0)  (q[0]) # shot 0, timebin 1, spatial mode 0 (sample 2) MeasureHomodyne(0)  (q[1]) # shot 0, timebin 1, spatial mode 2 (sample 3) ... MeasureHomodyne(0)  (q[0]) # shot 1, timebin 0, spatial mode 0 (sample 4) MeasureHomodyne(0)  (q[2]) # shot 1, timebin 0, spatial mode 2 (sample 5) ... MeasureHomodyne(0)  (q[0]) # shot 1, timebin 1, spatial mode 0 (sample 6) MeasureHomodyne(0)  (q[1]) # shot 1, timebin 1, spatial mode 2 (sample 7)
would return the dictionary
{ 0: np.array([(sample 0), (sample 2), (sample 4), (sample 6)]), 2: np.array([(sample 1), (sample 5)]), 1: np.array([(sample 3), (sample 7)]), }
which would then be reshaped, and returned, as follows:
{ 0: np.array([[(sample 0), (sample 2)], [(sample 4), (sample 6)]]), 2: np.array([[(sample 1), (sample 3)], [(sample 5), (sample 7)]]), }
 Parameters
all_samples (dict[int, list]) – the raw measured samples
modes (Sequence[int]) – the modes that are measured in the circuit
N (Sequence[int]) – the number of concurrent modes per belt/spatial modes
timebins (int) – the number of timebins/temporal modes in the program per shot
 Returns
 the reshaped samples, where each key correspond to a spatial
mode and the values have shape
(shots, timebins)
 Return type
dict[int, array]
Downloads