Readout scheme as sequence wide property.

This commit is contained in:
jupfi 2024-07-12 14:58:21 +02:00
parent 9057b7245f
commit 40a2ecc029
4 changed files with 56 additions and 23 deletions

View file

@ -16,7 +16,7 @@ class PhaseTable:
"""Initializes the phase table."""
self.quackseq = quackseq
self.readout_scheme = ReadoutScheme(self)
self.phase_array = self.generate_phase_array()
self.generate_phase_array()
def generate_phase_array(self):
"""Generate a list of phases for each phasecycle in the sequence.
@ -183,14 +183,12 @@ class PhaseTable:
logger.info(phase_array)
# First set the phase array
self.phase_array = phase_array
# Then update the readout scheme (always reset it)
self.readout_scheme.update_readout_scheme()
return phase_array
def update_phase_array(self):
"""Update the phase array of the sequence."""
self.phase_array = self.generate_phase_array()
@property
def phase_array(self) -> np.array:
"""The phase array of the sequence."""
@ -209,23 +207,58 @@ class PhaseTable:
def n_parameters(self) -> int:
"""The number of TX pulse parameters in the sequence."""
return self.phase_array.shape[1]
class ReadoutScheme():
class ReadoutScheme:
"""Readout Scheme for the phase table.
The rows are the phase cycles of the sequence.
The columns have two different types of options:
- The phase value of the phase cycle.
- The function that is applied to the phase cycle. Usually this is just +1, -1 or 0.
"""
def __init__(self, phase_table : PhaseTable) -> None:
def __init__(self, phase_table: PhaseTable) -> None:
"""Initializes the ReadoutOption."""
self.phase_table = phase_table
def update_readout_scheme(self):
"""Update the readout scheme of the sequence."""
"""Update the readout scheme of the sequence. Whenever the phase array is updated it will be reset."""
self.readout_scheme = np.zeros(
(self.phase_table.n_phase_cycles, self.phase_table.n_parameters)
)
def set_phase_cycle(
self, phase_cycle: int, phase_shift: float, function: str
) -> None:
"""Sets the phase shift and function of a phase cycle.
Args:
phase_cycle (int): The phase cycle.
phase_shift (float): The phase shift.
function (str): The function.
"""
self.readout_scheme[phase_cycle] = [phase_shift, function]
@property
def readout_scheme(self) -> np.array:
"""The readout scheme of the sequence."""
return self._readout_scheme
@readout_scheme.setter
def readout_scheme(self, readout_scheme: list) -> None:
"""Sets the readout scheme of the sequence.
Args:
readout_scheme (list): The readout scheme.
"""
# Sanity check
if len(readout_scheme) != self.phase_table.n_phase_cycles:
raise ValueError(
f"Length of readout scheme ({len(readout_scheme)}) does not match the number of phase cycles ({self.phase_table.n_phase_cycles})"
)
self._readout_scheme = readout_scheme

View file

@ -15,7 +15,6 @@ from quackseq.options import (
FunctionOption,
NumericOption,
Option,
ReadoutOption,
)
from quackseq.functions import (
RectFunction,
@ -169,7 +168,6 @@ class RXReadout(PulseParameter):
"""
RX = "Enable RX Readout"
READOUT_SCHEME = "Readout Scheme"
def __init__(self, name) -> None:
"""Initializes the RX Readout PulseParameter.
@ -179,8 +177,6 @@ class RXReadout(PulseParameter):
super().__init__(name)
self.add_option(BooleanOption(self.RX, False))
self.add_option(ReadoutOption(self.READOUT_SCHEME))
class Gate(PulseParameter):
"""Basic PulseParameter for the Gate. It includes an option for the Gate state.

View file

@ -401,7 +401,7 @@ class QuackSequence(PulseSequence):
event = self.get_event_by_name(event)
# Check that the readout scheme is valid
self.phase_table.update_phase_array()
self.phase_table.generate_phase_array()
n_cycles = self.phase_table.n_phase_cycles
rows = len(readout_scheme)
@ -411,6 +411,9 @@ class QuackSequence(PulseSequence):
f"Readout scheme needs to have {n_cycles} cycles, but has {rows}"
)
event.parameters[self.RX_READOUT].get_option_by_name(
RXReadout.READOUT_SCHEME
).value = readout_scheme
# Old way - implement the sequence wide readout scheme here
#event.parameters[self.RX_READOUT].get_option_by_name(
# RXReadout.READOUT_SCHEME
#).value = readout_scheme
self.phase_table.readout_scheme.readout_scheme = readout_scheme

View file

@ -55,7 +55,8 @@ class SpectrometerController:
[event.duration for event in previous_events]
)
rx_duration = event.duration
readout_scheme = parameter.get_option_by_name(RXReadout.READOUT_SCHEME).value
# This is fugly
readout_scheme = sequence.phase_table.readout_scheme.readout_scheme
rx_begin = float(previous_events_duration)
if rx_duration: