Measurement sets

A measurement set encapsulates measurement results for zero or more qubits. It is therefore actually more like a map/dictionary than a set.

Constructing measurement sets

A measurement set can be constructed as follows.

dqcs_handle_t mset = dqcs_mset_new();
for (qubit, value = ...; ...; ...) {
    dqcs_handle_t meas = dqcs_meas_new(qubit, value);
    dqcs_mset_set(mset, meas);
    dqcs_handle_delete(meas);
}
dqcs_mset_new()

Creates a new set of qubit measurement results.

dqcs_handle_t dqcs_mset_new(void)

Returns the handle of the newly created set. The set is initially empty.

dqcs_mset_set()

Adds a measurement result to a measurement result set.

dqcs_return_t dqcs_mset_set(
    dqcs_handle_t mset,
    dqcs_handle_t meas
)

If there was already a measurement for the specified qubit, the previous measurement result is overwritten. The measurement result object is deleted if and only if the function succeeds.

Iterating over measurement sets

Destructive iteration can be performed as follows if needed.

dqcs_handle_t mset = ...;
while ((dqcs_handle_t meas = dqcs_mset_take_any(mset))) {
    dqcs_qubit_t qubit = dqcs_meas_qubit_get(meas);
    dqcs_measurement_t value = dqcs_meas_value_get(meas);
    dqcs_handle_delete(meas);
    ...
}

To iterate nondestructively, one would have to construct a new measurement set while iterating.

dqcs_mset_take_any()

Returns the measurement result for any of the qubits contained in a measurement result set and removes it from the set.

dqcs_handle_t dqcs_mset_take_any(dqcs_handle_t mset)

This is useful for iteration.

Note that insertion order is not preserved. Measurements can also be removed from a measurement set in a controlled order using the following functions.

dqcs_mset_take()

Returns the measurement result for the given qubit from a measurement result set and removes it from the set.

dqcs_handle_t dqcs_mset_take(
    dqcs_handle_t mset,
    dqcs_qubit_t qubit
)
dqcs_mset_remove()

Removes the measurement result for the given qubit from a measurement result set.

dqcs_return_t dqcs_mset_remove(
    dqcs_handle_t mset,
    dqcs_qubit_t qubit
)

Querying measurement sets

Measurement sets can be queried nondestructively using the following functions.

dqcs_mset_contains()

Returns whether the given qubit measurement set contains data for the given qubit.

dqcs_bool_return_t dqcs_mset_contains(
    dqcs_handle_t mset,
    dqcs_qubit_t qubit
)
dqcs_mset_get()

Returns a copy of the measurement result for the given qubit from a measurement result set.

dqcs_handle_t dqcs_mset_get(
    dqcs_handle_t mset,
    dqcs_qubit_t qubit
)
dqcs_mset_len()

Returns the number of qubits measurements in the given measurement set.

ssize_t dqcs_mset_len(dqcs_handle_t mset)

This function returns -1 to indicate failure.