[−][src]Function dqcsim::bindings::dqcs_pdef_set_modify_measurement_cb
#[no_mangle]pub extern "C" fn dqcs_pdef_set_modify_measurement_cb(
pdef: dqcs_handle_t,
callback: Option<extern "C" fn(user_data: *mut c_void, state: dqcs_plugin_state_t, meas: dqcs_handle_t) -> dqcs_handle_t>,
user_free: Option<extern "C" fn(user_data: *mut c_void)>,
user_data: *mut c_void
) -> dqcs_return_t
Sets the measurement modification callback for operators.
This callback is called for every measurement result received from the
downstream plugin, and returns the measurements that should be reported
to the upstream plugin. Note that the results from our plugin's
dqcs_plugin_get_measurement()
and friends are consistent with the
results received from downstream; they are not affected by this
function.
The callback takes a handle to a single qubit measurement object as an argument, and must return one of the following things:
- a valid handle to a measurement set, created using
dqcs_mset_new()
(this object is automatically deleted after the callback returns); - a valid handle to a single qubit measurement object, which may or may not be the supplied one (this object is automatically deleted after the callback returns); or
- 0 to report an error, after calling the error string using
dqcs_set_error()
.
This callback is somewhat special in that it is not allowed to call any plugin command other than logging and the pseudorandom number generator functions. This is because this function is called asynchronously with respect to the downstream functions, making the timing of these calls non-deterministic based on operating system scheduling.
Note that while this function is called for only a single measurement
at a time, it is allowed to produce a vector of measurements. This
allows you to cancel propagation of the measurement by returning an
empty vector, to just modify the measurement data itself, or to
generate additional measurements from a single measurement. However,
if you need to modify the qubit references for operators that remap
qubits, take care to only send measurement data upstream when these
were explicitly requested through the associated upstream gate
function's measured
list.
The default behavior for this callback is to return the measurement without modification.