Skip to content

Python Utils SHFQA Multistate

zhinst.utils.shfqa.multistate

Zurich Instruments Utility functions for multi-state discrimination.

DEVICE_MAX_INTEGRATION_LEN = 4096 module-attribute

DEVICE_MAX_STATES = 4 module-attribute

DEVICE_MIN_STATES = 2 module-attribute

IntegrationWeight(state_left, state_right)

Represents integration weights vectors for one-vs-one classification.

Differential weight vectors are defined as the complex conjugate of the difference between reference traces of two states. They are used for weighed integration in the multi-state discrimination units.

Parameters:

Name Type Description Default
state_left QuditState

The state corresponding to the reference trace used as the left side of the subtraction operator.

required
state_right QuditState

The state corresponding to the reference trace used as the right side of the subtraction operator.

required

_left_state = state_left instance-attribute

_right_state = state_right instance-attribute

_vector = np.conj(state_left.ref_trace - state_right.ref_trace) instance-attribute

left_state: QuditState property

The state corresponding to the left side of the subtraction.

right_state: QuditState property

The state corresponding to the right side of the subtraction.

threshold: float property writable

Get the threshold value used together with this weight.

vector: np.ndarray property

The vector of integration weights.

center_threshold(trace1, trace2)

Center the threshold value between trace1 and trace2.

This function computes the weighted integration results using trace1 and trace2 as input and then computes the arithmetic mean of the two results.

Parameters:

Name Type Description Default
trace1 ndarray

The first trace.

required
trace2 ndarray

The second trace.

required

Returns:

Type Description
None

The arithmetic mean of the weighted integration results between

None

trace1 and trace2.

center_threshold_ref()

Center the threshold value between the left and right reference traces.

scale(factor)

Scales the weight vector with a factor.

Parameters:

Name Type Description Default
factor float

Factor to scale the weight vector with.

required

QuditSettings(ref_traces)

Collection of qudit settings for multistate discrimination.

Qudit settings are the integration weights, thresholds, and the assignment vector for qudit state discrimination. These settings are initialized based on reference traces for each state, which need to be provided as input to the constructor of this class.

Parameters:

Name Type Description Default
ref_traces List[ndarray]

List of (complex-valued) reference traces, one vector per state. The reference traces are typically obtained by an averaged scope measurement of the readout resonator response when the qudit is prepared in a certain state.

required

_assignment_vec = self.calc_theoretical_assignment_vec() instance-attribute

_num_states = len(ref_traces) instance-attribute

_states = {} instance-attribute

_weights = [] instance-attribute

assignment_vec: np.ndarray property

Vector assigning state indices for each threshold comparison outcome.

The vector has 2**( d * (d - 1) / 2 ) elements, where d is the number of states of the qudit.

integration_len: int property

Length of the weight vectors as number of samples.

num_states: int property

Number of states (d) of the qudit.

states: t.Dict[int, QuditState] property

Dictionary of states of the qudit.

The dictionary keys are state indices and the values are State objects.

thresholds: t.List[float] property

Threshold values, one per weight vector, for one-vs-one classification.

weights: t.List[IntegrationWeight] property

List of weight vectors for one-vs-one classification.

calc_theoretical_assignment_vec()

Calculates the theoretical assignment vector.

The theoretical assignment vector is determined by the majority vote (winner takes all) principle.

normalize_weights()

Scales all weight vectors with a common factor.

The common factor is chosen such that maximum absolute weight value is 1.

reset_thresholds_to_center()

Resets the thresholds of each weight to the center.

The thresholds get centered between the results of the weighted integration using the reference traces of the corresponding pairs of states.

QuditState(index, label, ref_trace) dataclass

Qudit state with associated reference trace.

Parameters:

Name Type Description Default
index int

A unique identifier of the state.

required
label str

The label of the state.

required
ref_trace ndarray

The reference traces of the qudit. They are typically obtained by an averaged scope measurement of the qudit's response to a readout pulse when a certain state has been prepared.

required

index: int instance-attribute

label: str instance-attribute

ref_trace: np.ndarray instance-attribute

_ReslogSource

Bases: IntEnum

Values for the result/source node.

RESULT_OF_DISCRIMINATION = 3 class-attribute instance-attribute

RESULT_OF_INTEGRATION = 1 class-attribute instance-attribute

_get_base_path(dev, qa_channel)

Gets the base node tree path of the multistate discrimination feature.

Parameters:

Name Type Description Default
dev str

The device id.

required
qa_channel int

The QA channel index.

required

Returns:

Type Description
str

The path to the multistate node tree branch.

_get_qudit_base_path(dev, qa_channel, qudit_idx)

Gets the base node tree path of a particular qudit.

Parameters:

Name Type Description Default
dev str

The device id

required
qa_channel int

The QA channel index

required
qudit_idx int

The index of the qudit

required

Returns:

Type Description
str

The path to the qudit node tree branch.

compare_threshold(threshold, integration_result)

Compares an integration result with a threshold.

Parameters:

Name Type Description Default
threshold float

The threshold value

required
integration_result float

The integration result for the comparison

required

Returns:

Type Description
bool

True if the integration_result is greater than the threshold,

bool

False otherwise.

config_to_device(daq, dev, qa_channel, qudit_idx, qudit_settings, *, enable=True)

Configures the qudit settings to the device.

Parameters:

Name Type Description Default
daq ziDAQServer

An instance of core.ziDAQServer

required
dev str

The device id.

required
qa_channel int

The index of the QA channel

required
qudit_idx int

The index of the qudit to be configured

required
qudit_settings QuditSettings

The qudit settings to be configured

required
enable bool

Whether to enable the qudit (default: True)

True

get_qudits_results(daq, dev, qa_channel)

Downloads the qudit results from the device and group them by qudit.

Depending on the result logger source, this function accesses the multistate nodes to determine which integrators were used for which qudit to be able to group the results by qudit.

Parameters:

Name Type Description Default
daq ziDAQServer

An instance of the core.ziDAQServer class

required
dev str

The device id.

required
qa_channels

The index of the QA channel

required

Returns:

Type Description
Dict[int, ndarray]

A dictionary with the qudit index keys and result vector values.

get_settings_transaction(dev, qa_channel, qudit_idx, qudit_settings, *, enable=True)

Compiles a list of settings to apply to the device.

Parameters:

Name Type Description Default
dev str

The device id.

required
qa_channel int

The index of the QA channel

required
qudit_idx int

The index of the qudit to be configured

required
qudit_settings QuditSettings

The qudit settings to be configured

required
enable bool

Whether to enable the qudit (default: True)

True

Returns:

Type Description
List[Tuple[str, Any]]

List of settings defining a transaction. Each list entry is a tuple,

List[Tuple[str, Any]]

where the first entry specifies the node path and the second entry the

List[Tuple[str, Any]]

value to be configured to the respective node.

weighted_integration(weight_vec, signal)

Computes the weighted integration.

Parameters:

Name Type Description Default
weight_vec ndarray

Vector of integration weights

required
signal ndarray

Vector of input signal samples

required

Returns:

Type Description
float

The result of the weighted integration.