Go to the documentation of this file.
3 #ifndef _CDQCSIM_INCLUDED_
4 #define _CDQCSIM_INCLUDED_
24 #ifndef _DQCSIM_HDR_CPP_
25 #define _DQCSIM_HDR_CPP_
1262 void (*key_free)(
void *key_data),
1265 void (*detector_user_free)(
void *user_data),
1266 void *detector_user_data,
1268 void (*constructor_user_free)(
void *user_data),
1269 void *constructor_user_data);
1324 void (*key_free)(
void *key_data),
1327 void (*detector_user_free)(
void *user_data),
1328 void *detector_user_data,
1330 void (*constructor_user_free)(
void *user_data),
1331 void *constructor_user_data);
1355 void (*key_free)(
void *key_data),
1358 intptr_t num_controls,
1360 bool ignore_gphase);
1381 void (*key_free)(
void *user_data),
1383 intptr_t num_measures,
1413 void (*key_free)(
void *user_data),
1416 intptr_t num_controls,
1418 bool ignore_gphase);
1439 void (*key_free)(
void *user_data),
1441 intptr_t num_targets,
1466 const void *key_data,
1477 const void *key_data,
1488 const void *key_data,
1501 const void *key_data,
1531 const void **key_data,
1598 bool (*key_cmp)(
const void*,
const void*),
1599 uint64_t (*key_hash)(
const void*));
1674 const char *message);
1704 bool ignore_gphase);
1787 bool ignore_gphase);
1857 bool ignore_global_phase,
1858 ssize_t **control_indices);
1994 const char *executable,
1995 const char *script);
2093 const char *version);
2109 void (*user_free)(
void *user_data),
2129 void (*user_free)(
void *user_data),
2145 void (*user_free)(
void *user_data),
2163 void (*user_free)(
void *user_data),
2211 void (*user_free)(
void *user_data),
2228 void (*user_free)(
void *user_data),
2249 void (*user_free)(
void *user_data),
2294 void (*user_free)(
void *user_data),
2320 void (*user_free)(
void *user_data),
2341 void (*user_free)(
void *user_data),
2379 uintptr_t num_qubits,
2597 void (*callback)(
void *user_data,
const char *message,
const char *logger,
dqcs_loglevel_t level,
const char *module,
const char *file, uint32_t line, uint64_t time_s, uint32_t time_ns, uint32_t pid, uint64_t tid),
2598 void (*user_free)(
void *user_data),
2828 void (*callback)(
void *user_data,
const char *simulator),
2829 void (*user_free)(
void *user_data),
2856 #ifdef _DQCSIM_HDR_CPP_
2863 #ifdef _DQCSIM_HDR_CPP_
2864 #define _DQCSIM_STD_PREFIX_ ::std::
2866 #define _DQCSIM_STD_PREFIX_
2877 static void dqcs_log_format(
2885 #if defined(__GNUC__)
2886 __attribute__((format(printf,5,6)))
2889 static void dqcs_log_format(
2899 _DQCSIM_STD_PREFIX_ va_list ap;
2901 int size = _DQCSIM_STD_PREFIX_ vsnprintf(NULL, 0, fmt, ap) + 1;
2905 char *buffer = (
char*)_DQCSIM_STD_PREFIX_ malloc(size);
2906 if (buffer == NULL) {
2907 _DQCSIM_STD_PREFIX_ fprintf(stderr,
"Error: failed to allocate buffer for log message!\n");
2912 _DQCSIM_STD_PREFIX_ va_list ap2;
2914 _DQCSIM_STD_PREFIX_ vsnprintf(buffer, size, fmt, ap2);
2918 if (((
int)
dqcs_log_raw(level, module, file, line, buffer)) < 0) {
2919 _DQCSIM_STD_PREFIX_ fprintf(stderr,
"Error while trying to log: %s\n",
dqcs_error_get());
2920 _DQCSIM_STD_PREFIX_ fprintf(stderr,
"The message was: %s\n", buffer);
2921 _DQCSIM_STD_PREFIX_ fprintf(stderr,
"In %s, %s:%u\n", module, file, line);
2925 _DQCSIM_STD_PREFIX_ free(buffer);
2928 #undef _DQCSIM_STD_PREFIX_
2930 #ifdef _DQCSIM_HDR_CPP_
2940 #ifndef _DQCSIM_LANGUAGE_
2941 #ifdef _DQCSIM_HDR_CPP_
2942 #define _DQCSIM_LANGUAGE_ "CPP"
2944 #define _DQCSIM_LANGUAGE_ "C"
2950 #ifndef _DQCSIM_LOGLEVEL_PREFIX_
2951 #ifdef _DQCSIM_HDR_CPP_
2952 #define _DQCSIM_LOGLEVEL_PREFIX_ ::dqcsim::raw::dqcs_loglevel_t::
2954 #define _DQCSIM_LOGLEVEL_PREFIX_
2959 #ifndef dqcs_log_trace
2964 #define dqcs_log_trace(fmt, ...) \
2966 _DQCSIM_LOGLEVEL_PREFIX_ DQCS_LOG_TRACE, \
2967 _DQCSIM_LANGUAGE_, \
2975 #ifndef dqcs_log_debug
2980 #define dqcs_log_debug(fmt, ...) \
2982 _DQCSIM_LOGLEVEL_PREFIX_ DQCS_LOG_DEBUG, \
2983 _DQCSIM_LANGUAGE_, \
2991 #ifndef dqcs_log_info
2996 #define dqcs_log_info(fmt, ...) \
2998 _DQCSIM_LOGLEVEL_PREFIX_ DQCS_LOG_INFO, \
2999 _DQCSIM_LANGUAGE_, \
3007 #ifndef dqcs_log_note
3012 #define dqcs_log_note(fmt, ...) \
3014 _DQCSIM_LOGLEVEL_PREFIX_ DQCS_LOG_NOTE, \
3015 _DQCSIM_LANGUAGE_, \
3023 #ifndef dqcs_log_warn
3028 #define dqcs_log_warn(fmt, ...) \
3030 _DQCSIM_LOGLEVEL_PREFIX_ DQCS_LOG_WARN, \
3031 _DQCSIM_LANGUAGE_, \
3039 #ifndef dqcs_log_error
3044 #define dqcs_log_error(fmt, ...) \
3046 _DQCSIM_LOGLEVEL_PREFIX_ DQCS_LOG_ERROR, \
3047 _DQCSIM_LANGUAGE_, \
3055 #ifndef dqcs_log_fatal
3060 #define dqcs_log_fatal(fmt, ...) \
3062 _DQCSIM_LOGLEVEL_PREFIX_ DQCS_LOG_FATAL, \
3063 _DQCSIM_LANGUAGE_, \
3075 #ifdef _DQCSIM_HDR_CPP_
3076 #undef _DQCSIM_HDR_CPP_
dqcs_bool_return_t dqcs_mset_contains(dqcs_handle_t mset, dqcs_qubit_t qubit)
Returns whether the given qubit measurement set contains data for the given qubit.
ssize_t dqcs_cq_len(dqcs_handle_t cq)
Returns the number of ArbCmd objects in the given ArbCmd queue.
dqcs_return_t dqcs_meas_value_set(dqcs_handle_t meas, dqcs_measurement_t value)
Sets the measurement value associated with a measurement object.
dqcs_handle_t dqcs_sim_new(dqcs_handle_t scfg)
Constructs a DQCsim simulation.
@ DQCS_GATE_TYPE_INVALID
Invalid gate type.
@ DQCS_GATE_U2
Any two-qubit unitary gate, parameterized as a full unitary matrix.
dqcs_handle_t dqcs_sim_recv(dqcs_handle_t sim)
Waits for the simulated accelerator to send a message to us.
dqcs_handle_t dqcs_gate_new_custom(const char *name, dqcs_handle_t targets, dqcs_handle_t controls, dqcs_handle_t measures, dqcs_handle_t matrix)
Constructs a new custom gate.
unsigned long long dqcs_handle_t
Type for a handle.
char * dqcs_tcfg_name(dqcs_handle_t tcfg)
Returns the configured name for the given plugin thread.
@ DQCS_HTYPE_MEAS_SET
Indicates that the given handle belongs to a set of qubit measurement results.
dqcs_return_t dqcs_pdef_set_upstream_arb_cb(dqcs_handle_t pdef, dqcs_handle_t(*callback)(void *user_data, dqcs_plugin_state_t state, dqcs_handle_t cmd), void(*user_free)(void *user_data), void *user_data)
Sets the callback function for handling an arb from upstream for operators and backends.
dqcs_handle_t dqcs_mat_predef(dqcs_predefined_gate_t gate_type, dqcs_handle_t param_data)
Constructs a new gate matrix for one of DQCsim's predefined gates.
ssize_t dqcs_arb_cbor_get(dqcs_handle_t arb, void *obj, size_t obj_size)
Returns the JSON/CBOR object of an ArbData object in the form of a CBOR object.
@ DQCS_GATE_RY_180
Ry(180°) gate.
dqcs_bool_return_t dqcs_cmd_iface_cmp(dqcs_handle_t cmd, const char *iface)
Compares the interface ID of an ArbCmd with the given string.
dqcs_return_t dqcs_handle_leak_check()
Succeeds only if there are no live handles in the current thread.
dqcs_handle_t dqcs_gate_targets(dqcs_handle_t gate)
Returns a handle to a new qubit reference set containing the qubits targeted by this gate.
dqcs_handle_t dqcs_mat_basis(dqcs_basis_t basis)
Constructs a matrix with the eigenvectors of one of the Pauli matrices as column vectors.
@ DQCS_HTYPE_GATE_MAP
Indicates that the given handle belongs to a gate map.
@ DQCS_GATE_RX_M90
Rx(-90°) gate.
dqcs_return_t dqcs_arb_assign(dqcs_handle_t dest, dqcs_handle_t src)
Copies the data from one object to another.
@ DQCS_HTYPE_INVALID
Indicates that the given handle is invalid.
@ DQCS_HTYPE_GATE
Indicates that the given handle belongs to a quantum gate description.
dqcs_bool_return_t dqcs_mat_basis_approx_eq(dqcs_handle_t a, dqcs_handle_t b, double epsilon)
Approximately compares two basis matrices.
@ DQCS_GATE_RX_90
Rx(90°) gate.
dqcs_return_t dqcs_pdef_set_drop_cb(dqcs_handle_t pdef, dqcs_return_t(*callback)(void *user_data, dqcs_plugin_state_t state), void(*user_free)(void *user_data), void *user_data)
Sets the user logic drop/cleanup callback.
@ DQCS_GATE_S
The S matrix, also known as a 90 degree Z rotation.
dqcs_handle_t dqcs_gate_new_prep(dqcs_handle_t targets, dqcs_handle_t matrix)
Constructs a new prep gate.
dqcs_handle_t dqcs_plugin_recv(dqcs_plugin_state_t plugin)
Waits for a message from the host.
@ DQCS_GATE_RX_180
Rx(180°) gate.
@ DQCS_HTYPE_ARB_CMD_QUEUE
Indicates that the given handle belongs to a queue of ArbCmd object.
char * dqcs_pdef_name(dqcs_handle_t pdef)
Returns the plugin name for the given plugin definition object.
dqcs_return_t dqcs_sim_send(dqcs_handle_t sim, dqcs_handle_t data)
Sends a message to the simulated accelerator.
dqcs_return_t dqcs_sim_start(dqcs_handle_t sim, dqcs_handle_t data)
Starts a program on the simulated accelerator.
@ DQCS_BOOL_FAILURE
The function has failed.
ssize_t dqcs_qbset_len(dqcs_handle_t qbset)
Returns the number of qubits in the given set.
dqcs_return_t dqcs_pdef_set_host_arb_cb(dqcs_handle_t pdef, dqcs_handle_t(*callback)(void *user_data, dqcs_plugin_state_t state, dqcs_handle_t cmd), void(*user_free)(void *user_data), void *user_data)
Sets the callback function function for handling an arb from the host.
@ DQCS_GATE_S_DAG
The S-dagger matrix, also known as a negative 90 degree Z rotation.
dqcs_handle_type_t
Enumeration of types that can be associated with a handle.
@ DQCS_BASIS_X
The X basis.
dqcs_return_t dqcs_arb_remove(dqcs_handle_t arb, ssize_t index)
Removes the specified unstructured string argument from the list.
@ DQCS_GATE_RX
The matrix for an arbitrary X rotation.
dqcs_loglevel_t
Enumeration of loglevels and logging modes.
@ DQCS_GATE_INVALID
Invalid gate. Used as an error return value.
dqcs_handle_t dqcs_pcfg_new(dqcs_plugin_type_t typ, const char *name, const char *spec)
Creates a new plugin process configuration object using sugared syntax.
char * dqcs_sim_get_author_idx(dqcs_handle_t sim, ssize_t index)
Queries the author of a plugin, referenced by index.
dqcs_return_t dqcs_plugin_gate(dqcs_plugin_state_t plugin, dqcs_handle_t gate)
Tells the downstream plugin to execute a gate.
dqcs_loglevel_t dqcs_pcfg_stdout_mode_get(dqcs_handle_t pcfg)
Returns the configured stdout capture mode for the specified plugin process.
dqcs_return_t dqcs_pcfg_work_set(dqcs_handle_t pcfg, const char *work)
Overrides the working directory for the plugin process.
dqcs_return_t dqcs_pdef_set_free_cb(dqcs_handle_t pdef, dqcs_return_t(*callback)(void *user_data, dqcs_plugin_state_t state, dqcs_handle_t qubits), void(*user_free)(void *user_data), void *user_data)
Sets the qubit deallocation callback for operators and backends.
dqcs_handle_t dqcs_cq_new()
Creates a new ArbCmd queue object.
@ DQCS_LOG_ERROR
This loglevel is to be used for reporting or propagating a non-fatal error caused by the API caller d...
dqcs_handle_t dqcs_mat_strip_control(dqcs_handle_t mat, double epsilon, bool ignore_global_phase, ssize_t **control_indices)
Splits a controlled matrix into its non-controlled submatrix and the indices of the control qubits.
ssize_t dqcs_mat_len(dqcs_handle_t mat)
Returns the number of complex entries in the given matrix.
dqcs_loglevel_t dqcs_pcfg_stderr_mode_get(dqcs_handle_t pcfg)
Returns the configured stderr capture mode for the specified plugin process.
dqcs_return_t dqcs_mset_set(dqcs_handle_t mset, dqcs_handle_t meas)
Adds a measurement result to a measurement result set.
ssize_t dqcs_arb_len(dqcs_handle_t arb)
Returns the number of unstructured arguments, or -1 to indicate failure.
char * dqcs_sim_get_version(dqcs_handle_t sim, const char *name)
Queries the version of a plugin, referenced by instance name.
@ DQCS_HTYPE_FRONT_PROCESS_CONFIG
Indicates that the given handle belongs to a frontend plugin process configuration object.
dqcs_return_t dqcs_plugin_run(dqcs_handle_t pdef, const char *simulator)
Executes a plugin in the current thread.
dqcs_handle_t dqcs_gate_matrix(dqcs_handle_t gate)
Returns a copy of the unitary matrix associated with this gate, if one exists.
dqcs_plugin_type_t dqcs_tcfg_type(dqcs_handle_t tcfg)
Returns the type of the given plugin thread configuration.
dqcs_handle_t dqcs_mset_take_any(dqcs_handle_t mset)
Returns the measurement result for any of the qubits contained in a measurement result set and remove...
dqcs_handle_t dqcs_gate_new_predef_two(dqcs_predefined_gate_t gate_type, dqcs_qubit_t qa, dqcs_qubit_t qb, dqcs_handle_t param_data)
Constructs a new predefined unitary two-qubit gate.
ssize_t dqcs_arb_get_raw(dqcs_handle_t arb, ssize_t index, void *obj, size_t obj_size)
Returns the unstructured string argument at the specified index.
dqcs_return_t dqcs_cq_next(dqcs_handle_t cq)
Advances an ArbCmd queue to the next command.
dqcs_return_t
Default return type for functions that don't need to return anything.
dqcs_bool_return_t dqcs_mat_approx_unitary(dqcs_handle_t matrix, double epsilon)
Returns whether the matrix is approximately unitary.
char * dqcs_sim_get_author(dqcs_handle_t sim, const char *name)
Queries the author of a plugin, referenced by instance name.
dqcs_return_t dqcs_meas_qubit_set(dqcs_handle_t meas, dqcs_qubit_t qubit)
Sets the qubit reference associated with a measurement object.
@ DQCS_LOG_OFF
Turns logging off.
@ DQCS_GATE_TYPE_INVALID
Invalid gate type. Used as an error return value.
dqcs_return_t dqcs_pdef_set_gate_cb(dqcs_handle_t pdef, dqcs_handle_t(*callback)(void *user_data, dqcs_plugin_state_t state, dqcs_handle_t gate), void(*user_free)(void *user_data), void *user_data)
Sets the gate execution callback for operators and backends.
dqcs_handle_t dqcs_arb_new()
Creates a new ArbData object.
@ DQCS_HTYPE_OPER_PROCESS_CONFIG
Indicates that the given handle belongs to an operator plugin process configuration object.
dqcs_cycle_t dqcs_plugin_get_cycle(dqcs_plugin_state_t plugin)
Returns the current value of the downstream cycle counter.
dqcs_return_t dqcs_pcfg_accept_timeout_set(dqcs_handle_t pcfg, double timeout)
Configures the timeout for the plugin process to connect to DQCsim.
dqcs_bool_return_t dqcs_mat_is_predef(dqcs_handle_t mat, dqcs_predefined_gate_t gate_type, dqcs_handle_t *param_data, double epsilon, bool ignore_gphase)
Returns whether this matrix is of the given predefined form and, if it is, any parameters needed to d...
dqcs_return_t dqcs_handle_delete_all()
Deletes all handles for the current thread.
dqcs_return_t dqcs_scfg_stderr_verbosity_set(dqcs_handle_t scfg, dqcs_loglevel_t level)
Configures the stderr sink verbosity for a simulation.
@ DQCS_GATE_TYPE_PREP
Prep gates have one or more target qubits and a 2x2 unitary matrix representing the basis.
dqcs_return_t dqcs_plugin_send(dqcs_plugin_state_t plugin, dqcs_handle_t arb)
Sends a message to the host.
@ DQCS_FAILURE
The function has failed.
dqcs_gate_type_t
Types of DQCsim gates.
@ DQCS_PTYPE_FRONT
Frontend plugin.
dqcs_handle_t dqcs_mset_new()
Creates a new set of qubit measurement results.
dqcs_return_t dqcs_arb_push_raw(dqcs_handle_t arb, const void *obj, size_t obj_size)
Pushes an unstructured raw argument to the back of the list.
@ DQCS_GATE_U1
Any single-qubit unitary gate, parameterized as a full unitary matrix.
dqcs_return_t dqcs_pdef_set_initialize_cb(dqcs_handle_t pdef, dqcs_return_t(*callback)(void *user_data, dqcs_plugin_state_t state, dqcs_handle_t init_cmds), void(*user_free)(void *user_data), void *user_data)
Sets the user logic initialization callback.
@ DQCS_PTYPE_INVALID
Invalid plugin type.
dqcs_loglevel_t dqcs_scfg_stderr_verbosity_get(dqcs_handle_t scfg)
Returns the configured stderr sink verbosity for a simulation.
@ DQCS_GATE_TYPE_MEASUREMENT
Measurement gates have one or more measured qubits and a 2x2 unitary matrix representing the basis.
dqcs_return_t dqcs_tcfg_verbosity_set(dqcs_handle_t tcfg, dqcs_loglevel_t level)
Configures the logging verbosity for the given plugin thread.
@ DQCS_MEAS_INVALID
Error value used to indicate that something went wrong.
dqcs_bool_return_t dqcs_cmd_oper_cmp(dqcs_handle_t cmd, const char *oper)
Compares the operation ID of an ArbCmd with the given string.
@ DQCS_HTYPE_FRONT_DEF
Indicates that the given handle belongs to a frontend plugin definition object.
@ DQCS_PATH_STYLE_INVALID
Error value used to indicate that something went wrong.
dqcs_measurement_t dqcs_meas_value_get(dqcs_handle_t meas)
Returns the measurement value associated with a measurement object.
@ DQCS_HTYPE_MEAS
Indicates that the given handle belongs to a qubit measurement result.
dqcs_handle_t dqcs_gate_new_predef_one(dqcs_predefined_gate_t gate_type, dqcs_qubit_t qa, dqcs_handle_t param_data)
Constructs a new predefined unitary one-qubit gate.
dqcs_return_t dqcs_arb_cbor_set(dqcs_handle_t arb, const void *obj, size_t obj_size)
Sets the JSON/CBOR object of an ArbData object by means of a CBOR object.
dqcs_return_t dqcs_scfg_repro_path_style_set(dqcs_handle_t scfg, dqcs_path_style_t path_style)
Sets the path style used when writing reproduction files.
dqcs_return_t dqcs_arb_clear(dqcs_handle_t arb)
Clears the unstructured argument list.
dqcs_handle_t dqcs_mat_add_controls(dqcs_handle_t mat, size_t number_of_controls)
Constructs a controlled matrix from the given matrix.
const char * dqcs_error_get()
Returns a pointer to the latest error message.
@ DQCS_HTYPE_MATRIX
Indicates that the given handle belongs to a matrix.
dqcs_loglevel_t dqcs_scfg_dqcsim_verbosity_get(dqcs_handle_t scfg)
Returns the configured verbosity for DQCsim's own messages.
dqcs_handle_t dqcs_gm_construct_three(dqcs_handle_t gm, const void *key_data, dqcs_qubit_t qa, dqcs_qubit_t qb, dqcs_qubit_t qc, dqcs_handle_t param_data)
Uses a gate map object to construct a three-qubit DQCsim gate from the plugin's representation.
@ DQCS_LOG_TRACE
This loglevel is to be used for reporting debugging information useful for debugging the internals of...
dqcs_handle_t dqcs_gate_new_predef(dqcs_predefined_gate_t gate_type, dqcs_handle_t qubits, dqcs_handle_t param_data)
Constructs a new predefined unitary gate.
dqcs_handle_t dqcs_gate_controls(dqcs_handle_t gate)
Returns a handle to a new qubit reference set containing the qubits that control this gate.
dqcs_return_t dqcs_pcfg_stdout_mode_set(dqcs_handle_t pcfg, dqcs_loglevel_t level)
Configures the capture mode for the stdout stream of the specified plugin process.
dqcs_return_t dqcs_pcfg_stderr_mode_set(dqcs_handle_t pcfg, dqcs_loglevel_t level)
Configures the capture mode for the stderr stream of the specified plugin process.
dqcs_basis_t
Enumeration of Pauli bases.
@ DQCS_PTYPE_OPER
Operator plugin.
dqcs_return_t dqcs_arb_set_raw(dqcs_handle_t arb, ssize_t index, const void *obj, size_t obj_size)
Replaces the unstructured argument at the specified index with the specified raw object.
dqcs_return_t dqcs_pdef_set_run_cb(dqcs_handle_t pdef, dqcs_handle_t(*callback)(void *user_data, dqcs_plugin_state_t state, dqcs_handle_t args), void(*user_free)(void *user_data), void *user_data)
Sets the run callback for frontends.
dqcs_plugin_type_t dqcs_pcfg_type(dqcs_handle_t pcfg)
Returns the type of the given plugin process configuration.
dqcs_bool_return_t dqcs_gate_has_controls(dqcs_handle_t gate)
Returns whether the specified gate has control qubits.
dqcs_handle_t dqcs_qbset_new()
Creates a new set of qubit references.
dqcs_handle_t dqcs_gm_new(bool strip_qubit_refs, bool strip_data, bool(*key_cmp)(const void *, const void *), uint64_t(*key_hash)(const void *))
Constructs a new gate map.
dqcs_gate_type_t dqcs_gate_type(dqcs_handle_t gate)
Returns the gate type of the given gate.
@ DQCS_PATH_STYLE_KEEP
Specifies that paths should be saved the same way they were specified on the command line.
char * dqcs_pdef_version(dqcs_handle_t pdef)
Returns the plugin version for the given plugin definition object.
unsigned long long dqcs_qubit_t
Type for a qubit reference.
char * dqcs_gate_name(dqcs_handle_t gate)
Returns the name of a custom gate.
dqcs_return_t dqcs_tcfg_init_cmd(dqcs_handle_t tcfg, dqcs_handle_t cmd)
Appends an ArbCmd to the list of initialization commands of a plugin thread.
dqcs_return_t dqcs_pcfg_env_unset(dqcs_handle_t pcfg, const char *key)
Removes/unsets an environment variable for the plugin process.
dqcs_return_t dqcs_arb_pop(dqcs_handle_t arb)
Pops an unstructured argument from the back of the list without returning it.
dqcs_qubit_t dqcs_qbset_pop(dqcs_handle_t qbset)
Pops a qubit reference off of a qubit reference set.
dqcs_return_t dqcs_pdef_set_modify_measurement_cb(dqcs_handle_t pdef, dqcs_handle_t(*callback)(void *user_data, dqcs_plugin_state_t state, dqcs_handle_t meas), void(*user_free)(void *user_data), void *user_data)
Sets the measurement modification callback for operators.
double dqcs_pcfg_accept_timeout_get(dqcs_handle_t pcfg)
Returns the configured timeout for the plugin process to connect to DQCsim.
dqcs_return_t dqcs_pdef_set_advance_cb(dqcs_handle_t pdef, dqcs_return_t(*callback)(void *user_data, dqcs_plugin_state_t state, dqcs_cycle_t cycles), void(*user_free)(void *user_data), void *user_data)
Sets the callback for advancing time for operators and backends.
dqcs_return_t dqcs_arb_push_str(dqcs_handle_t arb, const char *s)
Pushes an unstructured string argument to the back of the list.
dqcs_return_t dqcs_pcfg_shutdown_timeout_set(dqcs_handle_t pcfg, double timeout)
Configures the timeout for the plugin process to shut down gracefully.
dqcs_handle_t dqcs_gate_measures(dqcs_handle_t gate)
Returns a handle to a new qubit reference set containing the qubits measured by this gate.
dqcs_return_t dqcs_gm_add_custom(dqcs_handle_t gm, void(*key_free)(void *key_data), void *key_data, dqcs_bool_return_t(*detector)(const void *user_data, dqcs_handle_t gate, dqcs_handle_t *qubits, dqcs_handle_t *param_data), void(*detector_user_free)(void *user_data), void *detector_user_data, dqcs_handle_t(*constructor)(const void *user_data, dqcs_handle_t qubits, dqcs_handle_t param_data), void(*constructor_user_free)(void *user_data), void *constructor_user_data)
Adds a fully customizable gate mapping to the given gate map.
long long dqcs_cycle_t
Type for a simulation cycle timestamp.
dqcs_return_t dqcs_sim_yield(dqcs_handle_t sim)
Yields to the simulator.
dqcs_handle_t dqcs_sim_arb(dqcs_handle_t sim, const char *name, dqcs_handle_t cmd)
Sends an ArbCmd message to one of the plugins, referenced by name.
@ DQCS_LOG_DEBUG
This loglevel is to be used for reporting debugging information useful for debugging the user of the ...
dqcs_return_t dqcs_arb_insert_str(dqcs_handle_t arb, ssize_t index, const char *s)
Inserts an unstructured string argument into the list at the specified index.
@ DQCS_GATE_RZ_M90
Rz(-90°) gate.
dqcs_bool_return_t dqcs_gm_detect(dqcs_handle_t gm, dqcs_handle_t gate, const void **key_data, dqcs_handle_t *qubits, dqcs_handle_t *param_data)
Uses a gate map object to convert an incoming DQCsim gate to the plugin's representation.
char * dqcs_arb_pop_str(dqcs_handle_t arb)
Pops an unstructured string argument from the back of the list.
dqcs_return_t dqcs_pcfg_env_set(dqcs_handle_t pcfg, const char *key, const char *value)
Overrides an environment variable for the plugin process.
dqcs_handle_t dqcs_tcfg_new(dqcs_handle_t pdef, const char *name)
Creates a new plugin thread configuration object from a plugin definition.
dqcs_bool_return_t dqcs_gate_has_measures(dqcs_handle_t gate)
Returns whether the specified gate measures any qubits.
dqcs_cycle_t dqcs_plugin_advance(dqcs_plugin_state_t plugin, dqcs_cycle_t cycles)
Tells the downstream plugin to run for the specified number of cycles.
dqcs_return_t dqcs_arb_insert_raw(dqcs_handle_t arb, ssize_t index, const void *obj, size_t obj_size)
Inserts an unstructured raw argument into the list at the specified index.
@ DQCS_GATE_PAULI_I
The identity gate for a single qubit.
char * dqcs_cmd_iface_get(dqcs_handle_t cmd)
Returns the interface ID of an ArbCmd.
dqcs_return_t dqcs_sim_write_reproduction_file(dqcs_handle_t sim, const char *filename)
Writes a reproduction file for the simulation so far.
dqcs_handle_t dqcs_mat_new(size_t num_qubits, const double *matrix)
Constructs a new gate matrix.
@ DQCS_GATE_RY
The matrix for an arbitrary Y rotation.
char * dqcs_pcfg_executable(dqcs_handle_t pcfg)
Returns the configured executable path for the given plugin process.
dqcs_return_t dqcs_gm_add_custom_unitary(dqcs_handle_t gm, void(*key_free)(void *key_data), void *key_data, dqcs_bool_return_t(*detector)(const void *user_data, dqcs_handle_t matrix, size_t num_controls, dqcs_handle_t *param_data), void(*detector_user_free)(void *user_data), void *detector_user_data, dqcs_handle_t(*constructor)(const void *user_data, dqcs_handle_t *param_data, intptr_t *num_controls), void(*constructor_user_free)(void *user_data), void *constructor_user_data)
Adds a custom unitary gate mapping to the given gate map.
dqcs_handle_t dqcs_pdef_new(dqcs_plugin_type_t typ, const char *name, const char *author, const char *version)
Creates a new PluginDefinition object.
dqcs_return_t dqcs_qbset_push(dqcs_handle_t qbset, dqcs_qubit_t qubit)
Pushes a qubit reference into a qubit reference set.
dqcs_handle_t dqcs_qbset_copy(dqcs_handle_t qbset)
Returns a copy of the given qubit set, intended for non-destructive iteration.
@ DQCS_HTYPE_INVALID
Indicates that the given handle is invalid.
dqcs_bool_return_t dqcs_gate_has_matrix(dqcs_handle_t gate)
Returns whether a unitary matrix is associated with this gate.
@ DQCS_HTYPE_FRONT_THREAD_CONFIG
Indicates that the given handle belongs to a frontend plugin thread configuration object.
dqcs_handle_t dqcs_plugin_arb(dqcs_plugin_state_t plugin, dqcs_handle_t cmd)
Sends an arbitrary command downstream.
@ DQCS_HTYPE_OPER_THREAD_CONFIG
Indicates that the given handle belongs to an operator plugin thread configuration object.
@ DQCS_HTYPE_ARB_CMD
Indicates that the given handle belongs to an ArbCmd object.
dqcs_handle_t dqcs_gate_expand_control(dqcs_handle_t gate)
Utility function that expands a gate matrix to account for all control qubits.
@ DQCS_HTYPE_QUBIT_SET
Indicates that the given handle belongs to a set of qubit references.
@ DQCS_LOG_FATAL
This loglevel is to be used for reporting a fatal error, resulting from the owner of the logger getti...
dqcs_handle_t dqcs_sim_wait(dqcs_handle_t sim)
Waits for the simulated accelerator to finish its current program.
ssize_t dqcs_mat_dimension(dqcs_handle_t mat)
Returns the dimension (number of rows == number of columns) of the given matrix.
dqcs_cycle_t dqcs_plugin_get_cycles_between_measures(dqcs_plugin_state_t plugin, dqcs_qubit_t qubit)
Returns the number of downstream cycles between the last two measurements of the given downstream qub...
dqcs_handle_t dqcs_gm_construct_two(dqcs_handle_t gm, const void *key_data, dqcs_qubit_t qa, dqcs_qubit_t qb, dqcs_handle_t param_data)
Uses a gate map object to construct a two-qubit DQCsim gate from the plugin's representation.
dqcs_return_t dqcs_scfg_log_callback(dqcs_handle_t scfg, dqcs_loglevel_t verbosity, void(*callback)(void *user_data, const char *message, const char *logger, dqcs_loglevel_t level, const char *module, const char *file, uint32_t line, uint64_t time_s, uint32_t time_ns, uint32_t pid, uint64_t tid), void(*user_free)(void *user_data), void *user_data)
Configures DQCsim to also output its log messages to callback function.
dqcs_bool_return_t
Return type for functions that normally return a boolean but can also fail.
dqcs_predefined_gate_t
Enumeration of gates defined by DQCsim.
@ DQCS_GATE_PAULI_Z
The Pauli Z matrix.
dqcs_qubit_t dqcs_meas_qubit_get(dqcs_handle_t meas)
Returns the qubit reference associated with a measurement object.
@ DQCS_HTYPE_OPER_DEF
Indicates that the given handle belongs to an operator plugin definition object.
dqcs_measurement_t
Qubit measurement value.
@ DQCS_FALSE
The function did what it was supposed to and returned false.
@ DQCS_LOG_INVALID
Invalid loglevel.
dqcs_return_t dqcs_log_raw(dqcs_loglevel_t level, const char *module, const char *file, uint32_t line_nr, const char *message)
Primitive API for sending a log message using the current logger.
@ DQCS_GATE_T
The T matrix, also known as a 45 degree Z rotation.
@ DQCS_LOG_NOTE
This loglevel is to be used for reporting information specifically requested by the user/API caller,...
dqcs_handle_t dqcs_plugin_allocate(dqcs_plugin_state_t plugin, uintptr_t num_qubits, dqcs_handle_t cq)
Allocate the given number of downstream qubits.
dqcs_return_t dqcs_arb_set_str(dqcs_handle_t arb, ssize_t index, const char *s)
Replaces the unstructured argument at the specified index with the specified string.
char * dqcs_pcfg_script(dqcs_handle_t pcfg)
Returns the configured script path for the given plugin process.
dqcs_return_t dqcs_plugin_free(dqcs_plugin_state_t plugin, dqcs_handle_t qbset)
Free the given downstream qubits.
@ DQCS_PATH_STYLE_RELATIVE
Specifies that all paths should be saved relative to DQCsim's working directory.
uint64_t dqcs_scfg_seed_get(dqcs_handle_t scfg)
Returns the configured random seed.
dqcs_handle_type_t dqcs_handle_type(dqcs_handle_t handle)
Returns the type of object associated with the given handle.
char * dqcs_pdef_author(dqcs_handle_t pdef)
Returns the plugin author for the given plugin definition object.
dqcs_cycle_t dqcs_plugin_get_cycles_since_measure(dqcs_plugin_state_t plugin, dqcs_qubit_t qubit)
Returns the number of downstream cycles since the latest measurement of the given downstream qubit.
dqcs_handle_t dqcs_gm_construct_one(dqcs_handle_t gm, const void *key_data, dqcs_qubit_t qa, dqcs_handle_t param_data)
Uses a gate map object to construct a one-qubit DQCsim gate from the plugin's representation.
ssize_t dqcs_mat_num_qubits(dqcs_handle_t mat)
Returns the number of qubits targeted by the given matrix.
@ DQCS_GATE_T_DAG
The T-dagger matrix, also known as a negative 45 degree Z rotation.
dqcs_handle_t dqcs_mset_take(dqcs_handle_t mset, dqcs_qubit_t qubit)
Returns the measurement result for the given qubit from a measurement result set and removes it from ...
@ DQCS_BASIS_INVALID
Invalid basis. Used as an error return value.
ssize_t dqcs_arb_get_size(dqcs_handle_t arb, ssize_t index)
Returns the size in bytes of the unstructured string argument at the specified index.
dqcs_path_style_t
Reproduction file path style.
@ DQCS_GATE_RZ_90
Rz(90°) gate.
dqcs_loglevel_t
Enumeration of loglevels and logging modes.
dqcs_handle_t dqcs_cmd_new(const char *iface, const char *oper)
Creates a new ArbCmd object.
@ DQCS_GATE_RY_M90
Ry(-90°) gate.
@ DQCS_GATE_PHASE_K
The matrix for a Z rotation with angle π/2^k.
dqcs_return_t dqcs_gm_add_measure(dqcs_handle_t gm, void(*key_free)(void *user_data), void *key_data, intptr_t num_measures, dqcs_handle_t basis, double epsilon)
Adds a measurement gate mapping to the given gate map.
dqcs_plugin_type_t
Enumeration of the three types of plugins.
ssize_t dqcs_arb_pop_raw(dqcs_handle_t arb, void *obj, size_t obj_size)
Pops an unstructured raw argument from the back of the list.
dqcs_handle_t dqcs_pcfg_new_raw(dqcs_plugin_type_t typ, const char *name, const char *executable, const char *script)
Creates a new plugin process configuration object using raw paths.
dqcs_handle_t dqcs_plugin_get_measurement(dqcs_plugin_state_t plugin, dqcs_qubit_t qubit)
Returns the latest measurement of the given downstream qubit.
dqcs_handle_t dqcs_mset_get(dqcs_handle_t mset, dqcs_qubit_t qubit)
Returns a copy of the measurement result for the given qubit from a measurement result set.
char * dqcs_sim_get_name_idx(dqcs_handle_t sim, ssize_t index)
Queries the implementation name of a plugin, referenced by index.
@ DQCS_BASIS_INVALID
Invalid basis.
void dqcs_error_set(const char *msg)
Sets the latest error message string.
char * dqcs_pcfg_work_get(dqcs_handle_t pcfg)
Returns the configured working directory for the given plugin process.
@ DQCS_GATE_PAULI_Y
The Pauli Y matrix.
dqcs_handle_t dqcs_plugin_random_u64(dqcs_plugin_state_t plugin)
Generates a random unsigned 64-bit number using the simulator random seed.
dqcs_handle_t dqcs_sim_arb_idx(dqcs_handle_t sim, ssize_t index, dqcs_handle_t cmd)
Sends an ArbCmd message to one of the plugins, referenced by index.
char * dqcs_sim_get_name(dqcs_handle_t sim, const char *name)
Queries the implementation name of a plugin, referenced by instance name.
double dqcs_plugin_random_f64(dqcs_plugin_state_t plugin)
Generates a random floating point number using the simulator random seed.
@ DQCS_GATE_SWAP
The swap gate matrix.
@ DQCS_HTYPE_SIM_CONFIG
Indicates that the given handle belongs to a simulator configuration object.
dqcs_handle_t dqcs_tcfg_new_raw(dqcs_plugin_type_t plugin_type, const char *name, void(*callback)(void *user_data, const char *simulator), void(*user_free)(void *user_data), void *user_data)
Creates a new plugin thread configuration object from a callback.
dqcs_return_t dqcs_gm_add_predef_unitary(dqcs_handle_t gm, void(*key_free)(void *user_data), void *key_data, dqcs_predefined_gate_t gate, intptr_t num_controls, double epsilon, bool ignore_gphase)
Adds a unitary gate mapping for the given DQCsim-defined gate to the given gate map.
dqcs_return_t dqcs_scfg_repro_disable(dqcs_handle_t scfg)
Disables the reproduction logging system.
dqcs_handle_t dqcs_plugin_start(dqcs_handle_t pdef, const char *simulator)
Executes a plugin in a worker thread.
@ DQCS_MEAS_INVALID
Error value used to indicate that something went wrong.
@ DQCS_LOG_WARN
This loglevel is to be used for reporting that a called API/function is telling us we did something w...
dqcs_return_t dqcs_cq_push(dqcs_handle_t cq, dqcs_handle_t cmd)
Pushes an ArbCmd object into the given ArbCmd queue.
dqcs_return_t dqcs_scfg_dqcsim_verbosity_set(dqcs_handle_t scfg, dqcs_loglevel_t level)
Configures the logging verbosity for DQCsim's own messages.
@ DQCS_PTYPE_INVALID
Invalid plugin type.
dqcs_return_t dqcs_tcfg_tee(dqcs_handle_t tcfg, dqcs_loglevel_t verbosity, const char *filename)
Configures a plugin thread to also output its log messages to a file.
char * dqcs_pcfg_name(dqcs_handle_t pcfg)
Returns the configured name for the given plugin process.
dqcs_handle_t dqcs_scfg_new()
Constructs an empty simulation configuration.
@ DQCS_GATE_INVALID
Invalid gate.
dqcs_return_t dqcs_gm_add_prep(dqcs_handle_t gm, void(*key_free)(void *user_data), void *key_data, intptr_t num_targets, dqcs_handle_t basis, double epsilon)
Adds a prep gate mapping to the given gate map.
char * dqcs_arb_json_get(dqcs_handle_t arb)
Returns the JSON/CBOR object of an ArbData object in the form of a JSON string.
@ DQCS_LOG_INVALID
Invalid loglevel.
@ DQCS_GATE_H
The hadamard gate matrix.
@ DQCS_GATE_RY_90
Ry(90°) gate.
@ DQCS_BASIS_Y
The Y basis.
@ DQCS_GATE_RZ_180
Rz(180°) gate.
dqcs_handle_t dqcs_gm_construct(dqcs_handle_t gm, const void *key_data, dqcs_handle_t qubits, dqcs_handle_t param_data)
Uses a gate map object to construct a multi-qubit DQCsim gate from the plugin's representation.
dqcs_bool_return_t dqcs_qbset_contains(dqcs_handle_t qbset, dqcs_qubit_t qubit)
Returns whether the given qubit set contains the given qubit.
dqcs_path_style_t dqcs_scfg_repro_path_style_get(dqcs_handle_t scfg)
Returns the path style used when writing reproduction files.
dqcs_return_t dqcs_gm_add_fixed_unitary(dqcs_handle_t gm, void(*key_free)(void *key_data), void *key_data, dqcs_handle_t matrix, intptr_t num_controls, double epsilon, bool ignore_gphase)
Adds a unitary gate mapping for the given gate matrix to the given gate map.
char * dqcs_sim_get_version_idx(dqcs_handle_t sim, ssize_t index)
Queries the version of a plugin, referenced by index.
double * dqcs_mat_get(dqcs_handle_t mat)
Returns a copy of the contained matrix as a C array.
dqcs_handle_t dqcs_gate_new_predef_three(dqcs_predefined_gate_t gate_type, dqcs_qubit_t qa, dqcs_qubit_t qb, dqcs_qubit_t qc, dqcs_handle_t param_data)
Constructs a new predefined unitary three-qubit gate.
dqcs_return_t dqcs_plugin_wait(dqcs_handle_t pjoin)
Waits for a plugin worker thread to finish executing.
dqcs_return_t dqcs_handle_delete(dqcs_handle_t handle)
Destroys the object associated with a handle.
dqcs_handle_t dqcs_gate_new_measurement(dqcs_handle_t measures, dqcs_handle_t matrix)
Constructs a new measurement gate.
dqcs_return_t dqcs_pcfg_verbosity_set(dqcs_handle_t pcfg, dqcs_loglevel_t level)
Configures the logging verbosity for the given plugin process.
@ DQCS_MEAS_ZERO
Indicates that the qubit was measured to be zero.
@ DQCS_GATE_R
Arbitrary rotation matrix.
@ DQCS_GATE_PAULI_X
The Pauli X matrix.
dqcs_bool_return_t dqcs_gate_has_targets(dqcs_handle_t gate)
Returns whether the specified gate has target qubits.
@ DQCS_GATE_TYPE_UNITARY
Unitary gates have one or more target qubits, zero or more control qubits, and a unitary matrix,...
@ DQCS_HTYPE_BACK_PROCESS_CONFIG
Indicates that the given handle belongs to a backend plugin process configuration object.
@ DQCS_GATE_PHASE
The matrix for an arbitrary Z rotation.
char * dqcs_handle_dump(dqcs_handle_t handle)
Returns a debug dump of the object associated with the given handle.
dqcs_return_t dqcs_pdef_set_allocate_cb(dqcs_handle_t pdef, dqcs_return_t(*callback)(void *user_data, dqcs_plugin_state_t state, dqcs_handle_t qubits, dqcs_handle_t alloc_cmds), void(*user_free)(void *user_data), void *user_data)
Sets the qubit allocation callback for operators and backends.
@ DQCS_MEAS_ONE
Indicates that the qubit was measured to be one.
@ DQCS_PATH_STYLE_INVALID
Error value used to indicate that something went wrong.
@ DQCS_HTYPE_ARB_DATA
Indicates that the given handle belongs to an ArbData object.
void * dqcs_plugin_state_t
Type for a plugin state.
dqcs_loglevel_t dqcs_pcfg_verbosity_get(dqcs_handle_t pcfg)
Returns the configured verbosity for the given plugin process.
char * dqcs_arb_get_str(dqcs_handle_t arb, ssize_t index)
Returns the unstructured string argument at the specified index.
dqcs_return_t dqcs_scfg_tee(dqcs_handle_t scfg, dqcs_loglevel_t verbosity, const char *filename)
Configures DQCsim to also output its log messages to a file.
dqcs_return_t dqcs_scfg_seed_set(dqcs_handle_t scfg, uint64_t seed)
Configures the random seed that the simulation should use.
dqcs_loglevel_t dqcs_tcfg_verbosity_get(dqcs_handle_t tcfg)
Returns the configured verbosity for the given plugin thread.
ssize_t dqcs_mset_len(dqcs_handle_t mset)
Returns the number of qubits measurements in the given measurement set.
dqcs_return_t dqcs_mset_remove(dqcs_handle_t mset, dqcs_qubit_t qubit)
Removes the measurement result for the given qubit from a measurement result set.
dqcs_handle_t dqcs_gate_new_unitary(dqcs_handle_t targets, dqcs_handle_t controls, dqcs_handle_t matrix)
Constructs a new unitary gate.
dqcs_return_t dqcs_pcfg_tee(dqcs_handle_t pcfg, dqcs_loglevel_t verbosity, const char *filename)
Configures a plugin process to also output its log messages to a file.
dqcs_handle_t dqcs_meas_new(dqcs_qubit_t qubit, dqcs_measurement_t value)
Constructs a new measurement object.
@ DQCS_GATE_SQRT_SWAP
The square-root of a swap gate matrix.
dqcs_plugin_type_t dqcs_pdef_type(dqcs_handle_t pdef)
Returns the plugin type for the given plugin definition object.
dqcs_bool_return_t dqcs_mat_approx_eq(dqcs_handle_t a, dqcs_handle_t b, double epsilon, bool ignore_gphase)
Approximately compares two matrices.
@ DQCS_HTYPE_BACK_THREAD_CONFIG
Indicates that the given handle belongs to a backend plugin thread configuration object.
@ DQCS_GATE_RZ
The matrix for an arbitrary Z rotation.
dqcs_bool_return_t dqcs_gate_has_name(dqcs_handle_t gate)
Returns whether the specified gate has a name.
char * dqcs_cmd_oper_get(dqcs_handle_t cmd)
Returns the operation ID of an ArbCmd.
double dqcs_pcfg_shutdown_timeout_get(dqcs_handle_t pcfg)
Returns the configured timeout for the plugin process to shut down gracefully.
dqcs_return_t dqcs_pcfg_init_cmd(dqcs_handle_t pcfg, dqcs_handle_t cmd)
Appends an ArbCmd to the list of initialization commands of a plugin process.
dqcs_return_t dqcs_scfg_push_plugin(dqcs_handle_t scfg, dqcs_handle_t xcfg)
Appends a plugin to a simulation configuration.
@ DQCS_LOG_INFO
This loglevel is to be used for reporting information NOT specifically requested by the user/API call...
dqcs_handle_t dqcs_gate_reduce_control(dqcs_handle_t gate, double epsilon, bool ignore_gphase)
Utility function that detects control qubits in the targets list of the gate by means of the gate mat...
@ DQCS_BOOL_FAILURE
The function has failed.
@ DQCS_FAILURE
The function has failed.
@ DQCS_HTYPE_BACK_DEF
Indicates that the given handle belongs to a backend plugin definition object.
dqcs_return_t dqcs_arb_json_set(dqcs_handle_t arb, const char *json)
Sets the JSON/CBOR object of an ArbData object by means of a JSON string.
@ DQCS_HTYPE_SIM
Indicates that the given handle belongs to a simulator instance.