Go to the documentation of this file. 1 #ifndef _DQCSIM_H_INCLUDED_
2 #define _DQCSIM_H_INCLUDED_
22 #ifdef _DQCSIM_HDR_CPP_
23 #undef _DQCSIM_HDR_CPP_
1546 void (*key_free)(
void *key_data),
1549 void (*detector_user_free)(
void *user_data),
1550 void *detector_user_data,
1552 void (*constructor_user_free)(
void *user_data),
1553 void *constructor_user_data);
1610 void (*key_free)(
void *key_data),
1613 void (*detector_user_free)(
void *user_data),
1614 void *detector_user_data,
1616 void (*constructor_user_free)(
void *user_data),
1617 void *constructor_user_data);
1643 void (*key_free)(
void *key_data),
1646 intptr_t num_controls,
1648 bool ignore_gphase);
1671 void (*key_free)(
void *user_data),
1673 intptr_t num_measures,
1705 void (*key_free)(
void *user_data),
1708 intptr_t num_controls,
1710 bool ignore_gphase);
1733 void (*key_free)(
void *user_data),
1735 intptr_t num_targets,
1762 const void *key_data,
1775 const void *key_data,
1788 const void *key_data,
1803 const void *key_data,
1835 const void **key_data,
1904 bool (*key_cmp)(
const void*,
const void*),
1905 uint64_t (*key_hash)(
const void*));
1992 const char *message);
2026 bool ignore_gphase);
2121 bool ignore_gphase);
2201 bool ignore_global_phase,
2202 ssize_t **control_indices);
2382 const char *executable,
2383 const char *script);
2513 const char *version);
2531 void (*user_free)(
void *user_data),
2553 void (*user_free)(
void *user_data),
2571 void (*user_free)(
void *user_data),
2591 void (*user_free)(
void *user_data),
2641 void (*user_free)(
void *user_data),
2660 void (*user_free)(
void *user_data),
2683 void (*user_free)(
void *user_data),
2730 void (*user_free)(
void *user_data),
2758 void (*user_free)(
void *user_data),
2781 void (*user_free)(
void *user_data),
2827 uintptr_t num_qubits,
3091 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),
3092 void (*user_free)(
void *user_data),
3380 void (*callback)(
void *user_data,
const char *simulator),
3381 void (*user_free)(
void *user_data),
3411 #ifdef _DQCSIM_HDR_CPP_
3418 #ifdef _DQCSIM_HDR_CPP_
3419 #define _DQCSIM_STD_PREFIX_ ::std::
3421 #define _DQCSIM_STD_PREFIX_
3432 static void dqcs_log_format(
3440 #if defined(__GNUC__)
3441 __attribute__((format(printf,5,6)))
3444 static void dqcs_log_format(
3454 _DQCSIM_STD_PREFIX_ va_list ap;
3456 int size = _DQCSIM_STD_PREFIX_ vsnprintf(NULL, 0, fmt, ap) + 1;
3460 char *buffer = (
char*)_DQCSIM_STD_PREFIX_ malloc(size);
3461 if (buffer == NULL) {
3462 _DQCSIM_STD_PREFIX_ fprintf(stderr,
"Error: failed to allocate buffer for log message!\n");
3467 _DQCSIM_STD_PREFIX_ va_list ap2;
3469 _DQCSIM_STD_PREFIX_ vsnprintf(buffer, size, fmt, ap2);
3473 if (((
int)
dqcs_log_raw(level, module, file, line, buffer)) < 0) {
3474 _DQCSIM_STD_PREFIX_ fprintf(stderr,
"Error while trying to log: %s\n",
dqcs_error_get());
3475 _DQCSIM_STD_PREFIX_ fprintf(stderr,
"The message was: %s\n", buffer);
3476 _DQCSIM_STD_PREFIX_ fprintf(stderr,
"In %s, %s:%u\n", module, file, line);
3480 _DQCSIM_STD_PREFIX_ free(buffer);
3483 #undef _DQCSIM_STD_PREFIX_
3485 #ifdef _DQCSIM_HDR_CPP_
3495 #ifndef _DQCSIM_LANGUAGE_
3496 #ifdef _DQCSIM_HDR_CPP_
3497 #define _DQCSIM_LANGUAGE_ "CPP"
3499 #define _DQCSIM_LANGUAGE_ "C"
3505 #ifndef _DQCSIM_LOGLEVEL_PREFIX_
3506 #ifdef _DQCSIM_HDR_CPP_
3507 #define _DQCSIM_LOGLEVEL_PREFIX_ ::dqcsim::raw::dqcs_loglevel_t::
3509 #define _DQCSIM_LOGLEVEL_PREFIX_
3514 #ifndef dqcs_log_trace
3519 #define dqcs_log_trace(fmt, ...) \
3521 _DQCSIM_LOGLEVEL_PREFIX_ DQCS_LOG_TRACE, \
3522 _DQCSIM_LANGUAGE_, \
3530 #ifndef dqcs_log_debug
3535 #define dqcs_log_debug(fmt, ...) \
3537 _DQCSIM_LOGLEVEL_PREFIX_ DQCS_LOG_DEBUG, \
3538 _DQCSIM_LANGUAGE_, \
3546 #ifndef dqcs_log_info
3551 #define dqcs_log_info(fmt, ...) \
3553 _DQCSIM_LOGLEVEL_PREFIX_ DQCS_LOG_INFO, \
3554 _DQCSIM_LANGUAGE_, \
3562 #ifndef dqcs_log_note
3567 #define dqcs_log_note(fmt, ...) \
3569 _DQCSIM_LOGLEVEL_PREFIX_ DQCS_LOG_NOTE, \
3570 _DQCSIM_LANGUAGE_, \
3578 #ifndef dqcs_log_warn
3583 #define dqcs_log_warn(fmt, ...) \
3585 _DQCSIM_LOGLEVEL_PREFIX_ DQCS_LOG_WARN, \
3586 _DQCSIM_LANGUAGE_, \
3594 #ifndef dqcs_log_error
3599 #define dqcs_log_error(fmt, ...) \
3601 _DQCSIM_LOGLEVEL_PREFIX_ DQCS_LOG_ERROR, \
3602 _DQCSIM_LANGUAGE_, \
3610 #ifndef dqcs_log_fatal
3615 #define dqcs_log_fatal(fmt, ...) \
3617 _DQCSIM_LOGLEVEL_PREFIX_ DQCS_LOG_FATAL, \
3618 _DQCSIM_LANGUAGE_, \
3630 #ifdef _DQCSIM_HDR_CPP_
3631 #undef _DQCSIM_HDR_CPP_
dqcs_path_style_t
Reproduction file path style.
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_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.
dqcs_handle_t dqcs_qbset_copy(dqcs_handle_t qbset)
Returns a copy of the given qubit set, intended for non-destructive iteration.
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_plugin_run(dqcs_handle_t pdef, const char *simulator)
Executes a plugin in the current thread.
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_set(dqcs_handle_t pcfg, const char *key, const char *value)
Overrides an environment variable for the plugin process.
dqcs_return_t dqcs_plugin_send(dqcs_plugin_state_t plugin, dqcs_handle_t arb)
Sends a message to the host.
@ DQCS_GATE_TYPE_INVALID
Invalid gate type.
dqcs_handle_t dqcs_gate_matrix(dqcs_handle_t gate)
Returns a copy of the unitary matrix associated with this gate, if one exists.
void dqcs_error_set(const char *msg)
Sets the latest error message string.
@ DQCS_GATE_U2
Any two-qubit unitary gate, parameterized as a full unitary matrix.
@ DQCS_HTYPE_MEAS_SET
Indicates that the given handle belongs to a set of qubit measurement results.
@ DQCS_GATE_RY_180
Ry(180°) gate.
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_arb_clear(dqcs_handle_t arb)
Clears the unstructured argument list.
char * dqcs_sim_get_author_idx(dqcs_handle_t sim, ssize_t index)
Queries the author of a plugin, referenced by index.
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.
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_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_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_measurement_t dqcs_meas_value_get(dqcs_handle_t meas)
Returns the measurement value associated with a measurement object.
ssize_t dqcs_arb_len(dqcs_handle_t arb)
Returns the number of unstructured arguments, or -1 to indicate failure.
@ DQCS_HTYPE_GATE_MAP
Indicates that the given handle belongs to a gate map.
dqcs_handle_t dqcs_gate_new_prep(dqcs_handle_t targets, dqcs_handle_t matrix)
Constructs a new prep gate.
@ DQCS_GATE_RX_M90
Rx(-90°) gate.
char * dqcs_cmd_oper_get(dqcs_handle_t cmd)
Returns the operation ID of an ArbCmd.
dqcs_gate_type_t dqcs_gate_type(dqcs_handle_t gate)
Returns the gate type of the given gate.
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_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_HTYPE_INVALID
Indicates that the given handle is invalid.
@ DQCS_HTYPE_GATE
Indicates that the given handle belongs to a quantum gate description.
@ DQCS_GATE_RX_90
Rx(90°) gate.
@ DQCS_GATE_S
The S matrix, also known as a 90 degree Z rotation.
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.
@ DQCS_GATE_RX_180
Rx(180°) gate.
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_HTYPE_ARB_CMD_QUEUE
Indicates that the given handle belongs to a queue of ArbCmd object.
dqcs_return_t dqcs_handle_leak_check(void)
Succeeds only if there are no live handles in the current thread.
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.
ssize_t dqcs_mset_len(dqcs_handle_t mset)
Returns the number of qubits measurements in the given measurement set.
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_BOOL_FAILURE
The function has failed.
long long dqcs_cycle_t
Type for a simulation cycle timestamp.
@ DQCS_GATE_S_DAG
The S-dagger matrix, also known as a negative 90 degree Z rotation.
dqcs_bool_return_t dqcs_gate_has_measures(dqcs_handle_t gate)
Returns whether the specified gate measures any qubits.
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.
char * dqcs_gate_name(dqcs_handle_t gate)
Returns the name of a custom gate.
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_BASIS_X
The X basis.
@ DQCS_GATE_RX
The matrix for an arbitrary X rotation.
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_return_t
Default return type for functions that don't need to return anything.
ssize_t dqcs_cq_len(dqcs_handle_t cq)
Returns the number of ArbCmd objects in the given ArbCmd queue.
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_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_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.
dqcs_return_t dqcs_scfg_push_plugin(dqcs_handle_t scfg, dqcs_handle_t xcfg)
Appends a plugin to a simulation configuration.
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_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_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...
ssize_t dqcs_mat_len(dqcs_handle_t mat)
Returns the number of complex entries in the given matrix.
dqcs_handle_type_t
Enumeration of types that can be associated with a handle.
@ DQCS_LOG_ERROR
This loglevel is to be used for reporting or propagating a non-fatal error caused by the API caller d...
@ DQCS_SUCCESS
The function did what it was supposed to.
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.
unsigned long long dqcs_qubit_t
Type for a qubit reference.
@ DQCS_HTYPE_FRONT_PROCESS_CONFIG
Indicates that the given handle belongs to a frontend plugin process configuration object.
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_PTYPE_BACK
Backend plugin.
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_handle_t dqcs_qbset_new(void)
Creates a new set of qubit references.
dqcs_bool_return_t dqcs_gate_has_name(dqcs_handle_t gate)
Returns whether the specified gate has a name.
dqcs_return_t dqcs_sim_start(dqcs_handle_t sim, dqcs_handle_t data)
Starts a program on the simulated accelerator.
dqcs_bool_return_t dqcs_gate_has_matrix(dqcs_handle_t gate)
Returns whether a unitary matrix is associated with this gate.
@ DQCS_LOG_OFF
Turns logging off.
dqcs_return_t dqcs_handle_delete_all(void)
Deletes all handles for the current thread.
dqcs_handle_t dqcs_arb_new(void)
Creates a new ArbData object.
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_repro_disable(dqcs_handle_t scfg)
Disables the reproduction logging system.
dqcs_measurement_t
Qubit measurement value.
@ DQCS_HTYPE_OPER_PROCESS_CONFIG
Indicates that the given handle belongs to an operator plugin process configuration object.
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_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_loglevel_t dqcs_pcfg_stderr_mode_get(dqcs_handle_t pcfg)
Returns the configured stderr capture mode for the specified plugin process.
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.
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_GATE_TYPE_PREP
Prep gates have one or more target qubits and a 2x2 unitary matrix representing the basis.
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_handle_t dqcs_gate_new_measurement(dqcs_handle_t measures, dqcs_handle_t matrix)
Constructs a new measurement gate.
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.
@ DQCS_PTYPE_FRONT
Frontend plugin.
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.
char * dqcs_sim_get_name(dqcs_handle_t sim, const char *name)
Queries the implementation name of a plugin, referenced by instance name.
char * dqcs_tcfg_name(dqcs_handle_t tcfg)
Returns the configured name for the given plugin thread.
ssize_t dqcs_mat_dimension(dqcs_handle_t mat)
Returns the dimension (number of rows == number of columns) of the given matrix.
dqcs_return_t dqcs_cq_push(dqcs_handle_t cq, dqcs_handle_t cmd)
Pushes an ArbCmd object into the given ArbCmd queue.
@ DQCS_GATE_U1
Any single-qubit unitary gate, parameterized as a full unitary matrix.
dqcs_plugin_type_t dqcs_tcfg_type(dqcs_handle_t tcfg)
Returns the type of the given plugin thread configuration.
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_PTYPE_INVALID
Invalid plugin type.
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_return_t dqcs_plugin_gate(dqcs_plugin_state_t plugin, dqcs_handle_t gate)
Tells the downstream plugin to execute a gate.
@ DQCS_GATE_TYPE_MEASUREMENT
Measurement gates have one or more measured qubits and a 2x2 unitary matrix representing the basis.
void * dqcs_plugin_state_t
Type for a plugin state.
@ DQCS_MEAS_INVALID
Error value used to indicate that something went wrong.
@ DQCS_HTYPE_FRONT_DEF
Indicates that the given handle belongs to a frontend plugin definition object.
@ DQCS_HTYPE_PLUGIN_JOIN
Indicates that the given handle belongs to a plugin thread join handle.
@ DQCS_HTYPE_MEAS
Indicates that the given handle belongs to a qubit measurement result.
const char * dqcs_error_get()
Returns a pointer to the latest error message.
dqcs_return_t dqcs_arb_remove(dqcs_handle_t arb, ssize_t index)
Removes the specified unstructured string argument from the list.
@ DQCS_HTYPE_MATRIX
Indicates that the given handle belongs to a matrix.
uint64_t dqcs_scfg_seed_get(dqcs_handle_t scfg)
Returns the configured random seed.
@ DQCS_LOG_PASS
This is intended to be used when configuring the stdout/stderr capture mode for a plugin process.
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_LOG_TRACE
This loglevel is to be used for reporting debugging information useful for debugging the internals of...
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.
char * dqcs_pcfg_work_get(dqcs_handle_t pcfg)
Returns the configured working directory for the given plugin process.
char * dqcs_pdef_author(dqcs_handle_t pdef)
Returns the plugin author for the given plugin definition object.
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_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_bool_return_t dqcs_gate_has_controls(dqcs_handle_t gate)
Returns whether the specified gate has control qubits.
@ DQCS_PTYPE_OPER
Operator plugin.
dqcs_handle_t dqcs_plugin_recv(dqcs_plugin_state_t plugin)
Waits for a message from the host.
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_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_loglevel_t dqcs_tcfg_verbosity_get(dqcs_handle_t tcfg)
Returns the configured verbosity for the given plugin thread.
dqcs_return_t dqcs_plugin_free(dqcs_plugin_state_t plugin, dqcs_handle_t qbset)
Free the given downstream qubits.
dqcs_handle_t dqcs_meas_new(dqcs_qubit_t qubit, dqcs_measurement_t value)
Constructs a new measurement object.
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_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_MEAS_UNDEFINED
Indicates that the measurement value is unknown for whatever reason.
@ DQCS_TRUE
The function did what it was supposed to and returned true.
unsigned long long dqcs_handle_t
Type for a handle.
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_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_PATH_STYLE_KEEP
Specifies that paths should be saved the same way they were specified on the command line.
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.
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_handle_t dqcs_mat_add_controls(dqcs_handle_t mat, size_t number_of_controls)
Constructs a controlled matrix from the given matrix.
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.
dqcs_loglevel_t dqcs_scfg_stderr_verbosity_get(dqcs_handle_t scfg)
Returns the configured stderr sink verbosity for a simulation.
@ DQCS_GATE_TYPE_CUSTOM
Custom gates perform a user-defined mixed quantum-classical operation, identified by a name.
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_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_handle_t dqcs_cq_new(void)
Creates a new ArbCmd queue object.
@ DQCS_LOG_DEBUG
This loglevel is to be used for reporting debugging information useful for debugging the user of the ...
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_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.
@ DQCS_GATE_RZ_M90
Rz(-90°) gate.
dqcs_return_t dqcs_meas_value_set(dqcs_handle_t meas, dqcs_measurement_t value)
Sets the measurement value associated with a measurement object.
double dqcs_pcfg_shutdown_timeout_get(dqcs_handle_t pcfg)
Returns the configured timeout for the plugin process to shut down gracefully.
dqcs_bool_return_t dqcs_mat_approx_unitary(dqcs_handle_t matrix, double epsilon)
Returns whether the matrix is approximately unitary.
dqcs_return_t dqcs_qbset_push(dqcs_handle_t qbset, dqcs_qubit_t qubit)
Pushes a qubit reference into a qubit reference set.
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.
char * dqcs_pcfg_name(dqcs_handle_t pcfg)
Returns the configured name for the given plugin process.
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.
char * dqcs_handle_dump(dqcs_handle_t handle)
Returns a debug dump of the object associated with the given handle.
@ DQCS_BASIS_Z
The Z basis.
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.
double dqcs_pcfg_accept_timeout_get(dqcs_handle_t pcfg)
Returns the configured timeout for the plugin process to connect to DQCsim.
@ DQCS_GATE_PAULI_I
The identity gate for a single qubit.
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_GATE_RY
The matrix for an arbitrary Y 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_HTYPE_FRONT_THREAD_CONFIG
Indicates that the given handle belongs to a frontend plugin thread 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_mset_set(dqcs_handle_t mset, dqcs_handle_t meas)
Adds a measurement result to a measurement result set.
@ 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_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_predefined_gate_t
Enumeration of gates defined by DQCsim.
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_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_tcfg_new(dqcs_handle_t pdef, const char *name)
Creates a new plugin thread configuration object from a plugin definition.
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_handle_t dqcs_sim_new(dqcs_handle_t scfg)
Constructs a DQCsim simulation.
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_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_GATE_PAULI_Z
The Pauli Z matrix.
ssize_t dqcs_qbset_len(dqcs_handle_t qbset)
Returns the number of qubits in the given set.
dqcs_plugin_type_t dqcs_pdef_type(dqcs_handle_t pdef)
Returns the plugin type for the given plugin definition object.
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_HTYPE_OPER_DEF
Indicates that the given handle belongs to an operator plugin definition object.
@ DQCS_FALSE
The function did what it was supposed to and returned false.
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.
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_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_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.
double dqcs_plugin_random_f64(dqcs_plugin_state_t plugin)
Generates a random floating point number using the simulator random seed.
@ 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,...
char * dqcs_cmd_iface_get(dqcs_handle_t cmd)
Returns the interface ID of an ArbCmd.
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_PATH_STYLE_RELATIVE
Specifies that all paths should be saved relative to DQCsim's working directory.
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_handle_t dqcs_gate_new_unitary(dqcs_handle_t targets, dqcs_handle_t controls, dqcs_handle_t matrix)
Constructs a new unitary gate.
@ DQCS_GATE_T_DAG
The T-dagger matrix, also known as a negative 45 degree Z rotation.
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_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.
char * dqcs_sim_get_version_idx(dqcs_handle_t sim, ssize_t index)
Queries the version of a plugin, referenced by index.
ssize_t dqcs_mat_num_qubits(dqcs_handle_t mat)
Returns the number of qubits targeted by the given matrix.
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_GATE_RZ_90
Rz(90°) gate.
dqcs_loglevel_t
Enumeration of loglevels and logging modes.
@ DQCS_PATH_STYLE_ABSOLUTE
Specifies that all paths should be saved canonically, i.e.
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_RY_M90
Ry(-90°) gate.
dqcs_handle_t dqcs_scfg_new(void)
Constructs an empty simulation configuration.
@ DQCS_GATE_PHASE_K
The matrix for a Z rotation with angle π/2^k.
dqcs_bool_return_t
Return type for functions that normally return a boolean but can also fail.
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_plugin_start(dqcs_handle_t pdef, const char *simulator)
Executes a plugin in a worker thread.
@ DQCS_BASIS_INVALID
Invalid basis.
@ DQCS_GATE_PAULI_Y
The Pauli Y matrix.
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_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.
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.
@ DQCS_GATE_U3
Any three-qubit unitary gate, parameterized as a full unitary matrix.
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.
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.
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_GATE_SWAP
The swap gate matrix.
char * dqcs_sim_get_name_idx(dqcs_handle_t sim, ssize_t index)
Queries the implementation name of a plugin, referenced by index.
@ DQCS_HTYPE_SIM_CONFIG
Indicates that the given handle belongs to a simulator configuration object.
dqcs_loglevel_t dqcs_pcfg_stdout_mode_get(dqcs_handle_t pcfg)
Returns the configured stdout capture mode for the specified plugin process.
dqcs_bool_return_t dqcs_gate_has_targets(dqcs_handle_t gate)
Returns whether the specified gate has target qubits.
dqcs_handle_t dqcs_mset_new(void)
Creates a new set of qubit measurement results.
dqcs_plugin_type_t
Enumeration of the three types of plugins.
dqcs_handle_t dqcs_sim_wait(dqcs_handle_t sim)
Waits for the simulated accelerator to finish its current program.
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.
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_loglevel_t dqcs_pcfg_verbosity_get(dqcs_handle_t pcfg)
Returns the configured verbosity for the given plugin process.
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.
char * dqcs_arb_pop_str(dqcs_handle_t arb)
Pops an unstructured string argument from the back of the list.
dqcs_return_t dqcs_cq_next(dqcs_handle_t cq)
Advances an ArbCmd queue to the next command.
@ DQCS_LOG_WARN
This loglevel is to be used for reporting that a called API/function is telling us we did something w...
dqcs_handle_t dqcs_sim_recv(dqcs_handle_t sim)
Waits for the simulated accelerator to send a message to us.
@ DQCS_GATE_INVALID
Invalid gate.
dqcs_return_t dqcs_pcfg_work_set(dqcs_handle_t pcfg, const char *work)
Overrides the working directory for the plugin process.
@ DQCS_LOG_INVALID
Invalid loglevel.
@ DQCS_GATE_H
The hadamard gate matrix.
dqcs_gate_type_t
Types of DQCsim gates.
@ DQCS_GATE_RY_90
Ry(90°) gate.
@ DQCS_BASIS_Y
The Y basis.
char * dqcs_pdef_name(dqcs_handle_t pdef)
Returns the plugin name for the given plugin definition object.
@ DQCS_GATE_RZ_180
Rz(180°) gate.
char * dqcs_pcfg_script(dqcs_handle_t pcfg)
Returns the configured script path for the given plugin process.
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_qubit_t dqcs_meas_qubit_get(dqcs_handle_t meas)
Returns the qubit reference associated with a measurement object.
dqcs_handle_t dqcs_cmd_new(const char *iface, const char *oper)
Creates a new ArbCmd object.
@ 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_GATE_TYPE_UNITARY
Unitary gates have one or more target qubits, zero or more control qubits, and a unitary matrix,...
dqcs_handle_t dqcs_plugin_arb(dqcs_plugin_state_t plugin, dqcs_handle_t cmd)
Sends an arbitrary command downstream.
@ DQCS_HTYPE_BACK_PROCESS_CONFIG
Indicates that the given handle belongs to a backend plugin process configuration object.
char * dqcs_pdef_version(dqcs_handle_t pdef)
Returns the plugin version for the given plugin definition object.
@ DQCS_GATE_PHASE
The matrix for an arbitrary Z rotation.
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_return_t dqcs_arb_assign(dqcs_handle_t dest, dqcs_handle_t src)
Copies the data from one object to another.
dqcs_return_t dqcs_sim_send(dqcs_handle_t sim, dqcs_handle_t data)
Sends a message to the simulated accelerator.
dqcs_handle_t dqcs_mat_new(size_t num_qubits, const double *matrix)
Constructs a new gate matrix.
@ 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.
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_return_t dqcs_scfg_seed_set(dqcs_handle_t scfg, uint64_t seed)
Configures the random seed that the simulation should use.
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.
dqcs_plugin_type_t dqcs_pcfg_type(dqcs_handle_t pcfg)
Returns the type of the given plugin process configuration.
dqcs_return_t dqcs_sim_yield(dqcs_handle_t sim)
Yields to the simulator.
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.
char * dqcs_sim_get_version(dqcs_handle_t sim, const char *name)
Queries the version of a plugin, referenced by instance name.
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_handle_delete(dqcs_handle_t handle)
Destroys the object associated with a handle.
dqcs_return_t dqcs_plugin_wait(dqcs_handle_t pjoin)
Waits for a plugin worker thread to finish executing.
@ DQCS_GATE_SQRT_SWAP
The square-root of a swap gate matrix.
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_qubit_t dqcs_qbset_pop(dqcs_handle_t qbset)
Pops a qubit reference off of a qubit reference set.
@ 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.
double * dqcs_mat_get(dqcs_handle_t mat)
Returns a copy of the contained matrix as a C array.
dqcs_return_t dqcs_arb_pop(dqcs_handle_t arb)
Pops an unstructured argument from the back of the list without returning it.
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_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_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_basis_t
Enumeration of Pauli bases.
dqcs_handle_type_t dqcs_handle_type(dqcs_handle_t handle)
Returns the type of object associated with the given handle.
const char * dqcs_error_get(void)
Returns a pointer to the latest error message.
@ DQCS_LOG_INFO
This loglevel is to be used for reporting information NOT specifically requested by the user/API call...
@ DQCS_FAILURE
The function has failed.
@ DQCS_HTYPE_BACK_DEF
Indicates that the given handle belongs to a backend plugin definition object.
@ DQCS_HTYPE_SIM
Indicates that the given handle belongs to a simulator instance.