DQCsim
dqcsim
Go to the documentation of this file.
1 // <dqcsim> -*- C++ -*-
2 
3 #ifndef _DQCSIM_INCLUDED_
4 #define _DQCSIM_INCLUDED_
6 
40 #include <stdexcept>
41 #include <string>
42 #include <vector>
43 #include <cstring>
44 #include <iostream>
45 #include <complex>
46 #include <functional>
47 #include <memory>
48 #include <cmath>
49 #include <limits>
50 #include <chrono>
51 #include <cdqcsim>
52 
56 namespace dqcsim {
57 
84 namespace wrap {
85 
96 
109 
116 
124  inline void check(raw::dqcs_return_t code) {
125  if (code == raw::dqcs_return_t::DQCS_FAILURE) {
126  throw std::runtime_error(raw::dqcs_error_get());
127  }
128  }
129 
138  inline bool check(raw::dqcs_bool_return_t code) {
140  throw std::runtime_error(raw::dqcs_error_get());
141  } else if (code == raw::dqcs_bool_return_t::DQCS_TRUE) {
142  return true;
143  } else {
144  return false;
145  }
146  }
147 
156  inline unsigned long long check(unsigned long long handle) {
157  if (handle == 0) {
158  throw std::runtime_error(raw::dqcs_error_get());
159  }
160  return handle;
161  }
162 
171  inline Cycle check(Cycle cycle) {
172  if (cycle == -1) {
173  throw std::runtime_error(raw::dqcs_error_get());
174  }
175  return cycle;
176  }
177 
186  inline size_t check(ssize_t size) {
187  if (size < 0) {
188  throw std::runtime_error(raw::dqcs_error_get());
189  }
190  return static_cast<size_t>(size);
191  }
192 
201  inline double check(double value) {
202  if (value < 0.0) {
203  throw std::runtime_error(raw::dqcs_error_get());
204  }
205  return value;
206  }
207 
214  enum class HandleType {
215 
219  ArbData = 100,
220 
224  ArbCmd = 101,
225 
229  ArbCmdQueue = 102,
230 
234  QubitSet = 103,
235 
239  Gate = 104,
240 
244  Measurement = 105,
245 
249  MeasurementSet = 106,
250 
254  Matrix = 107,
255 
259  GateMap = 108,
260 
265  FrontendProcessConfig = 200,
266 
271  OperatorProcessConfig = 201,
272 
277  BackendProcessConfig = 203,
278 
283  FrontendThreadConfig = 204,
284 
289  OperatorThreadConfig = 205,
290 
295  BackendThreadConfig = 206,
296 
300  SimulationConfig = 207,
301 
305  Simulation = 208,
306 
310  FrontendDefinition = 300,
311 
315  OperatorDefinition = 301,
316 
320  BackendDefinition = 302,
321 
325  PluginJoinHandle = 303
326  };
327 
334  inline raw::dqcs_handle_type_t to_raw(HandleType type) noexcept {
335  switch (type) {
345  case HandleType::FrontendProcessConfig: return raw::dqcs_handle_type_t::DQCS_HTYPE_FRONT_PROCESS_CONFIG;
346  case HandleType::OperatorProcessConfig: return raw::dqcs_handle_type_t::DQCS_HTYPE_OPER_PROCESS_CONFIG;
347  case HandleType::BackendProcessConfig: return raw::dqcs_handle_type_t::DQCS_HTYPE_BACK_PROCESS_CONFIG;
348  case HandleType::FrontendThreadConfig: return raw::dqcs_handle_type_t::DQCS_HTYPE_FRONT_THREAD_CONFIG;
349  case HandleType::OperatorThreadConfig: return raw::dqcs_handle_type_t::DQCS_HTYPE_OPER_THREAD_CONFIG;
350  case HandleType::BackendThreadConfig: return raw::dqcs_handle_type_t::DQCS_HTYPE_BACK_THREAD_CONFIG;
351  case HandleType::SimulationConfig: return raw::dqcs_handle_type_t::DQCS_HTYPE_SIM_CONFIG;
353  case HandleType::FrontendDefinition: return raw::dqcs_handle_type_t::DQCS_HTYPE_FRONT_DEF;
354  case HandleType::OperatorDefinition: return raw::dqcs_handle_type_t::DQCS_HTYPE_OPER_DEF;
355  case HandleType::BackendDefinition: return raw::dqcs_handle_type_t::DQCS_HTYPE_BACK_DEF;
357  }
358  std::cerr << "unknown handle type" << std::endl;
359  std::terminate();
360  }
361 
372  switch (type) {
382  case raw::dqcs_handle_type_t::DQCS_HTYPE_FRONT_PROCESS_CONFIG: return HandleType::FrontendProcessConfig;
383  case raw::dqcs_handle_type_t::DQCS_HTYPE_OPER_PROCESS_CONFIG: return HandleType::OperatorProcessConfig;
384  case raw::dqcs_handle_type_t::DQCS_HTYPE_BACK_PROCESS_CONFIG: return HandleType::BackendProcessConfig;
385  case raw::dqcs_handle_type_t::DQCS_HTYPE_FRONT_THREAD_CONFIG: return HandleType::FrontendThreadConfig;
386  case raw::dqcs_handle_type_t::DQCS_HTYPE_OPER_THREAD_CONFIG: return HandleType::OperatorThreadConfig;
387  case raw::dqcs_handle_type_t::DQCS_HTYPE_BACK_THREAD_CONFIG: return HandleType::BackendThreadConfig;
388  case raw::dqcs_handle_type_t::DQCS_HTYPE_SIM_CONFIG: return HandleType::SimulationConfig;
390  case raw::dqcs_handle_type_t::DQCS_HTYPE_FRONT_DEF: return HandleType::FrontendDefinition;
391  case raw::dqcs_handle_type_t::DQCS_HTYPE_OPER_DEF: return HandleType::OperatorDefinition;
392  case raw::dqcs_handle_type_t::DQCS_HTYPE_BACK_DEF: return HandleType::BackendDefinition;
394  case raw::dqcs_handle_type_t::DQCS_HTYPE_INVALID: throw std::runtime_error(raw::dqcs_error_get());
395  }
396  throw std::invalid_argument("unknown handle type");
397  }
398 
407  enum class Loglevel {
408 
412  Off = 0,
413 
420  Fatal = 1,
421 
427  Error = 2,
428 
438  Warn = 3,
439 
446  Note = 4,
447 
453  Info = 5,
454 
459  Debug = 6,
460 
467  Trace = 7,
468 
477  Pass = 8
478 
479  };
480 
487  inline raw::dqcs_loglevel_t to_raw(Loglevel loglevel) noexcept {
488  switch (loglevel) {
489  case Loglevel::Off: return raw::dqcs_loglevel_t::DQCS_LOG_OFF;
490  case Loglevel::Fatal: return raw::dqcs_loglevel_t::DQCS_LOG_FATAL;
491  case Loglevel::Error: return raw::dqcs_loglevel_t::DQCS_LOG_ERROR;
492  case Loglevel::Warn: return raw::dqcs_loglevel_t::DQCS_LOG_WARN;
493  case Loglevel::Note: return raw::dqcs_loglevel_t::DQCS_LOG_NOTE;
494  case Loglevel::Info: return raw::dqcs_loglevel_t::DQCS_LOG_INFO;
495  case Loglevel::Debug: return raw::dqcs_loglevel_t::DQCS_LOG_DEBUG;
496  case Loglevel::Trace: return raw::dqcs_loglevel_t::DQCS_LOG_TRACE;
498  }
499  std::cerr << "unknown loglevel" << std::endl;
500  std::terminate();
501  }
502 
513  switch (loglevel) {
514  case raw::dqcs_loglevel_t::DQCS_LOG_OFF: return Loglevel::Off;
515  case raw::dqcs_loglevel_t::DQCS_LOG_FATAL: return Loglevel::Fatal;
516  case raw::dqcs_loglevel_t::DQCS_LOG_ERROR: return Loglevel::Error;
517  case raw::dqcs_loglevel_t::DQCS_LOG_WARN: return Loglevel::Warn;
518  case raw::dqcs_loglevel_t::DQCS_LOG_NOTE: return Loglevel::Note;
519  case raw::dqcs_loglevel_t::DQCS_LOG_INFO: return Loglevel::Info;
520  case raw::dqcs_loglevel_t::DQCS_LOG_DEBUG: return Loglevel::Debug;
521  case raw::dqcs_loglevel_t::DQCS_LOG_TRACE: return Loglevel::Trace;
523  case raw::dqcs_loglevel_t::DQCS_LOG_INVALID: throw std::runtime_error(raw::dqcs_error_get());
524  }
525  throw std::invalid_argument("unknown loglevel");
526  }
527 
534  enum class MeasurementValue {
535 
539  Zero = 0,
540 
544  One = 1,
545 
551  Undefined = 2
552 
553  };
554 
561  inline raw::dqcs_measurement_t to_raw(MeasurementValue measurement) noexcept {
562  switch (measurement) {
563  case MeasurementValue::Zero: return raw::dqcs_measurement_t::DQCS_MEAS_ZERO;
564  case MeasurementValue::One: return raw::dqcs_measurement_t::DQCS_MEAS_ONE;
566  }
567  std::cerr << "unknown measurement value" << std::endl;
568  std::terminate();
569  }
570 
581  switch (measurement) {
582  case raw::dqcs_measurement_t::DQCS_MEAS_ZERO: return MeasurementValue::Zero;
583  case raw::dqcs_measurement_t::DQCS_MEAS_ONE: return MeasurementValue::One;
585  case raw::dqcs_measurement_t::DQCS_MEAS_INVALID: throw std::runtime_error(raw::dqcs_error_get());
586  }
587  throw std::invalid_argument("unknown measurement value");
588  }
589 
597  enum class PathStyle {
598 
603  Keep = 0,
604 
609  Relative = 1,
610 
615  Absolute = 2
616 
617  };
618 
625  inline raw::dqcs_path_style_t to_raw(PathStyle style) noexcept {
626  switch (style) {
627  case PathStyle::Keep: return raw::dqcs_path_style_t::DQCS_PATH_STYLE_KEEP;
628  case PathStyle::Relative: return raw::dqcs_path_style_t::DQCS_PATH_STYLE_RELATIVE;
630  }
631  std::cerr << "unknown path style" << std::endl;
632  std::terminate();
633  }
634 
645  switch (style) {
646  case raw::dqcs_path_style_t::DQCS_PATH_STYLE_KEEP: return PathStyle::Keep;
647  case raw::dqcs_path_style_t::DQCS_PATH_STYLE_RELATIVE: return PathStyle::Relative;
650  }
651  throw std::invalid_argument("unknown path style");
652  }
653 
660  enum class PluginType {
661 
665  Frontend = 0,
666 
670  Operator = 1,
671 
675  Backend = 2
676 
677  };
678 
685  inline raw::dqcs_plugin_type_t to_raw(PluginType type) noexcept {
686  switch (type) {
690  }
691  std::cerr << "unknown plugin type" << std::endl;
692  std::terminate();
693  }
694 
705  switch (type) {
709  case raw::dqcs_plugin_type_t::DQCS_PTYPE_INVALID: throw std::runtime_error(raw::dqcs_error_get());
710  }
711  throw std::invalid_argument("unknown plugin type");
712  }
713 
720  enum class GateType {
721 
734  Unitary = 1,
735 
754  Measurement = 2,
755 
772  Prep = 3,
773 
789  Custom = 4
790 
791  };
792 
799  inline raw::dqcs_gate_type_t to_raw(GateType type) noexcept {
800  switch (type) {
801  case GateType::Unitary: return raw::dqcs_gate_type_t::DQCS_GATE_TYPE_UNITARY;
803  case GateType::Prep: return raw::dqcs_gate_type_t::DQCS_GATE_TYPE_PREP;
805  }
806  std::cerr << "unknown gate type" << std::endl;
807  std::terminate();
808  }
809 
820  switch (type) {
821  case raw::dqcs_gate_type_t::DQCS_GATE_TYPE_UNITARY: return GateType::Unitary;
823  case raw::dqcs_gate_type_t::DQCS_GATE_TYPE_PREP: return GateType::Prep;
825  case raw::dqcs_gate_type_t::DQCS_GATE_TYPE_INVALID: throw std::runtime_error(raw::dqcs_error_get());
826  }
827  throw std::invalid_argument("unknown gate type");
828  }
829 
836  enum class PauliBasis {
837 
848  X = 1,
849 
860  Y = 2,
861 
872  Z = 3
873 
874  };
875 
882  inline raw::dqcs_basis_t to_raw(PauliBasis type) noexcept {
883  switch (type) {
884  case PauliBasis::X: return raw::dqcs_basis_t::DQCS_BASIS_X;
885  case PauliBasis::Y: return raw::dqcs_basis_t::DQCS_BASIS_Y;
887  }
888  std::cerr << "unknown basis" << std::endl;
889  std::terminate();
890  }
891 
902  switch (type) {
903  case raw::dqcs_basis_t::DQCS_BASIS_X: return PauliBasis::X;
904  case raw::dqcs_basis_t::DQCS_BASIS_Y: return PauliBasis::Y;
906  case raw::dqcs_basis_t::DQCS_BASIS_INVALID: throw std::runtime_error(raw::dqcs_error_get());
907  }
908  throw std::invalid_argument("unknown basis");
909  }
910 
917  enum class PredefinedGate {
918 
929  I = 100,
930 
941  X = 101,
942 
953  Y = 102,
954 
965  Z = 103,
966 
978  H = 104,
979 
990  S = 105,
991 
1002  S_DAG = 106,
1003 
1014  T = 107,
1015 
1026  T_DAG = 108,
1027 
1038  RX_90 = 109,
1039 
1050  RX_M90 = 110,
1051 
1066  RX_180 = 111,
1067 
1078  RY_90 = 112,
1079 
1090  RY_M90 = 113,
1091 
1106  RY_180 = 114,
1107 
1122  RZ_90 = 115,
1123 
1138  RZ_M90 = 116,
1139 
1154  RZ_180 = 117,
1155 
1170  RX = 150,
1171 
1186  RY = 151,
1187 
1202  RZ = 152,
1203 
1218  PhaseK = 153,
1219 
1240  Phase = 154,
1241 
1250  U1 = 190,
1251 
1277  R = 191,
1278 
1291  Swap = 200,
1292 
1305  SqSwap = 201,
1306 
1315  U2 = 290,
1316 
1325  U3 = 390,
1326 
1327  };
1328 
1336  switch (type) {
1337  case PredefinedGate::I: return raw::dqcs_predefined_gate_t::DQCS_GATE_PAULI_I;
1338  case PredefinedGate::X: return raw::dqcs_predefined_gate_t::DQCS_GATE_PAULI_X;
1339  case PredefinedGate::Y: return raw::dqcs_predefined_gate_t::DQCS_GATE_PAULI_Y;
1340  case PredefinedGate::Z: return raw::dqcs_predefined_gate_t::DQCS_GATE_PAULI_Z;
1341  case PredefinedGate::H: return raw::dqcs_predefined_gate_t::DQCS_GATE_H;
1342  case PredefinedGate::S: return raw::dqcs_predefined_gate_t::DQCS_GATE_S;
1343  case PredefinedGate::S_DAG: return raw::dqcs_predefined_gate_t::DQCS_GATE_S_DAG;
1344  case PredefinedGate::T: return raw::dqcs_predefined_gate_t::DQCS_GATE_T;
1345  case PredefinedGate::T_DAG: return raw::dqcs_predefined_gate_t::DQCS_GATE_T_DAG;
1346  case PredefinedGate::RX_90: return raw::dqcs_predefined_gate_t::DQCS_GATE_RX_90;
1347  case PredefinedGate::RX_M90: return raw::dqcs_predefined_gate_t::DQCS_GATE_RX_M90;
1348  case PredefinedGate::RX_180: return raw::dqcs_predefined_gate_t::DQCS_GATE_RX_180;
1349  case PredefinedGate::RY_90: return raw::dqcs_predefined_gate_t::DQCS_GATE_RY_90;
1350  case PredefinedGate::RY_M90: return raw::dqcs_predefined_gate_t::DQCS_GATE_RY_M90;
1351  case PredefinedGate::RY_180: return raw::dqcs_predefined_gate_t::DQCS_GATE_RY_180;
1352  case PredefinedGate::RZ_90: return raw::dqcs_predefined_gate_t::DQCS_GATE_RZ_90;
1353  case PredefinedGate::RZ_M90: return raw::dqcs_predefined_gate_t::DQCS_GATE_RZ_M90;
1354  case PredefinedGate::RZ_180: return raw::dqcs_predefined_gate_t::DQCS_GATE_RZ_180;
1355  case PredefinedGate::RX: return raw::dqcs_predefined_gate_t::DQCS_GATE_RX;
1356  case PredefinedGate::RY: return raw::dqcs_predefined_gate_t::DQCS_GATE_RY;
1357  case PredefinedGate::RZ: return raw::dqcs_predefined_gate_t::DQCS_GATE_RZ;
1358  case PredefinedGate::PhaseK: return raw::dqcs_predefined_gate_t::DQCS_GATE_PHASE_K;
1359  case PredefinedGate::Phase: return raw::dqcs_predefined_gate_t::DQCS_GATE_PHASE;
1360  case PredefinedGate::U1: return raw::dqcs_predefined_gate_t::DQCS_GATE_U1;
1361  case PredefinedGate::R: return raw::dqcs_predefined_gate_t::DQCS_GATE_R;
1362  case PredefinedGate::Swap: return raw::dqcs_predefined_gate_t::DQCS_GATE_SWAP;
1363  case PredefinedGate::SqSwap: return raw::dqcs_predefined_gate_t::DQCS_GATE_SQRT_SWAP;
1364  case PredefinedGate::U2: return raw::dqcs_predefined_gate_t::DQCS_GATE_U2;
1366  }
1367  std::cerr << "unknown plugin type" << std::endl;
1368  std::terminate();
1369  }
1370 
1381  switch (type) {
1382  case raw::dqcs_predefined_gate_t::DQCS_GATE_PAULI_I: return PredefinedGate::I;
1383  case raw::dqcs_predefined_gate_t::DQCS_GATE_PAULI_X: return PredefinedGate::X;
1384  case raw::dqcs_predefined_gate_t::DQCS_GATE_PAULI_Y: return PredefinedGate::Y;
1385  case raw::dqcs_predefined_gate_t::DQCS_GATE_PAULI_Z: return PredefinedGate::Z;
1386  case raw::dqcs_predefined_gate_t::DQCS_GATE_H: return PredefinedGate::H;
1387  case raw::dqcs_predefined_gate_t::DQCS_GATE_S: return PredefinedGate::S;
1388  case raw::dqcs_predefined_gate_t::DQCS_GATE_S_DAG: return PredefinedGate::S_DAG;
1389  case raw::dqcs_predefined_gate_t::DQCS_GATE_T: return PredefinedGate::T;
1390  case raw::dqcs_predefined_gate_t::DQCS_GATE_T_DAG: return PredefinedGate::T_DAG;
1391  case raw::dqcs_predefined_gate_t::DQCS_GATE_RX_90: return PredefinedGate::RX_90;
1392  case raw::dqcs_predefined_gate_t::DQCS_GATE_RX_M90: return PredefinedGate::RX_M90;
1393  case raw::dqcs_predefined_gate_t::DQCS_GATE_RX_180: return PredefinedGate::RX_180;
1394  case raw::dqcs_predefined_gate_t::DQCS_GATE_RY_90: return PredefinedGate::RY_90;
1395  case raw::dqcs_predefined_gate_t::DQCS_GATE_RY_M90: return PredefinedGate::RY_M90;
1396  case raw::dqcs_predefined_gate_t::DQCS_GATE_RY_180: return PredefinedGate::RY_180;
1397  case raw::dqcs_predefined_gate_t::DQCS_GATE_RZ_90: return PredefinedGate::RZ_90;
1398  case raw::dqcs_predefined_gate_t::DQCS_GATE_RZ_M90: return PredefinedGate::RZ_M90;
1399  case raw::dqcs_predefined_gate_t::DQCS_GATE_RZ_180: return PredefinedGate::RZ_180;
1400  case raw::dqcs_predefined_gate_t::DQCS_GATE_RX: return PredefinedGate::RX;
1401  case raw::dqcs_predefined_gate_t::DQCS_GATE_RY: return PredefinedGate::RY;
1402  case raw::dqcs_predefined_gate_t::DQCS_GATE_RZ: return PredefinedGate::RZ;
1403  case raw::dqcs_predefined_gate_t::DQCS_GATE_PHASE_K: return PredefinedGate::PhaseK;
1404  case raw::dqcs_predefined_gate_t::DQCS_GATE_PHASE: return PredefinedGate::Phase;
1405  case raw::dqcs_predefined_gate_t::DQCS_GATE_U1: return PredefinedGate::U1;
1406  case raw::dqcs_predefined_gate_t::DQCS_GATE_R: return PredefinedGate::R;
1407  case raw::dqcs_predefined_gate_t::DQCS_GATE_SWAP: return PredefinedGate::Swap;
1408  case raw::dqcs_predefined_gate_t::DQCS_GATE_SQRT_SWAP: return PredefinedGate::SqSwap;
1409  case raw::dqcs_predefined_gate_t::DQCS_GATE_U2: return PredefinedGate::U2;
1411  case raw::dqcs_predefined_gate_t::DQCS_GATE_INVALID: throw std::runtime_error(raw::dqcs_error_get());
1412  }
1413  throw std::invalid_argument("unknown plugin type");
1414  }
1415 
1424  template <typename T>
1425  inline T *check(T *pointer) {
1426  if (pointer == nullptr) {
1427  throw std::runtime_error(raw::dqcs_error_get());
1428  }
1429  return pointer;
1430  }
1431 
1458  template<typename... Args>
1459  inline void log(
1460  wrap::Loglevel level,
1461  const std::string &module,
1462  const std::string &file,
1463  unsigned int line_nr,
1464  const std::string &format,
1465  Args... args
1466  ) noexcept {
1467  raw::dqcs_log_format(
1468  to_raw(level),
1469  module.c_str(),
1470  file.c_str(),
1471  line_nr,
1472  format.c_str(),
1473  args...
1474  );
1475  }
1476 
1495  inline bool log_raw(
1496  wrap::Loglevel level,
1497  const std::string &module,
1498  const std::string &file,
1499  unsigned int line_nr,
1500  const std::string &message
1501  ) noexcept {
1502  return raw::dqcs_log_raw(
1503  to_raw(level),
1504  module.c_str(),
1505  file.c_str(),
1506  line_nr,
1507  message.c_str()
1509  }
1510 
1519  #define DQCSIM_LOG(level, fmt, ...) \
1520  ::dqcsim::wrap::log( \
1521  level, "C++", __FILE__, __LINE__, \
1522  fmt, ##__VA_ARGS__)
1523 
1531  #define DQCSIM_TRACE(fmt, ...) DQCSIM_LOG(::dqcsim::wrap::Loglevel::Trace, fmt, ##__VA_ARGS__)
1532 
1540  #define DQCSIM_DEBUG(fmt, ...) DQCSIM_LOG(::dqcsim::wrap::Loglevel::Debug, fmt, ##__VA_ARGS__)
1541 
1549  #define DQCSIM_INFO(fmt, ...) DQCSIM_LOG(::dqcsim::wrap::Loglevel::Info, fmt, ##__VA_ARGS__)
1550 
1558  #define DQCSIM_NOTE(fmt, ...) DQCSIM_LOG(::dqcsim::wrap::Loglevel::Note, fmt, ##__VA_ARGS__)
1559 
1567  #define DQCSIM_WARN(fmt, ...) DQCSIM_LOG(::dqcsim::wrap::Loglevel::Warn, fmt, ##__VA_ARGS__)
1568 
1576  #define DQCSIM_WARNING(fmt, ...) DQCSIM_LOG(::dqcsim::wrap::Loglevel::Warn, fmt, ##__VA_ARGS__)
1577 
1585  #define DQCSIM_ERROR(fmt, ...) DQCSIM_LOG(::dqcsim::wrap::Loglevel::Error, fmt, ##__VA_ARGS__)
1586 
1594  #define DQCSIM_FATAL(fmt, ...) DQCSIM_LOG(::dqcsim::wrap::Loglevel::Fatal, fmt, ##__VA_ARGS__)
1595 
1618  class Handle {
1619  protected:
1620 
1625 
1626  public:
1627 
1634  Handle() noexcept : handle(0) {
1635  }
1636 
1646  }
1647 
1651  virtual ~Handle() noexcept {
1652  if (handle) {
1653  // NOTE: no check; ignore errors (because destructors should be
1654  // noexcept).
1656  }
1657  }
1658 
1668  void free() {
1670  handle = 0;
1671  }
1672 
1678  bool is_valid() const noexcept {
1679  try {
1681  } catch (std::runtime_error) {
1682  return false;
1683  }
1684  }
1685 
1691  HandleIndex get_handle() const noexcept {
1692  return handle;
1693  }
1694 
1704  HandleIndex h = handle;
1705  handle = 0;
1706  return h;
1707  }
1708 
1709  // Handles cannot usually be copied, so delete the copy constructor and
1710  // copy assignment operator.
1711  Handle(const Handle&) = delete;
1712  void operator=(const Handle&) = delete;
1713 
1726  Handle(Handle &&src) : handle(src.handle) {
1727  src.handle = 0;
1728  }
1729 
1749  if (handle) {
1750  free();
1751  }
1752  handle = src.handle;
1753  src.handle = 0;
1754  return *this;
1755  }
1756 
1770  std::string dump() const {
1771  char *dump_c = check(raw::dqcs_handle_dump(handle));
1772  std::string dump(dump_c);
1773  std::free(dump_c);
1774  return dump;
1775  }
1776 
1788  friend std::ostream& operator<<(std::ostream &out, const Handle &handle) {
1789  out << handle.dump();
1790  return out;
1791  }
1792 
1799  HandleType type() const {
1801  }
1802 
1803  };
1804 
1810  class Arb : public Handle {
1811  public:
1812 
1822  }
1823 
1830  std::string get_arb_json_string() const {
1831  char *json_c = check(raw::dqcs_arb_json_get(handle));
1832  std::string json(json_c);
1833  std::free(json_c);
1834  return json;
1835  }
1836 
1849  void set_arb_json_string(const std::string &json) {
1850  check(raw::dqcs_arb_json_set(handle, json.c_str()));
1851  }
1852 
1865  std::string get_arb_cbor_string() const {
1866  size_t size = check(raw::dqcs_arb_cbor_get(handle, nullptr, 0));
1867  std::string cbor;
1868  cbor.resize(size);
1869  check(raw::dqcs_arb_cbor_get(handle, &cbor.front(), size));
1870  return cbor;
1871  }
1872 
1880  void set_arb_cbor_string(const std::string &cbor) {
1881  check(raw::dqcs_arb_cbor_set(handle, cbor.data(), cbor.size()));
1882  }
1883 
1902  template <class JSON>
1903  JSON get_arb_json() const {
1904  size_t size = check(raw::dqcs_arb_cbor_get(handle, nullptr, 0));
1905  std::vector<uint8_t> cbor;
1906  cbor.resize(size);
1907  check(raw::dqcs_arb_cbor_get(handle, &cbor.front(), size));
1908  return JSON::from_cbor(cbor);
1909  }
1910 
1923  template <class JSON>
1924  void set_arb_json(const JSON &json) {
1925  std::vector<uint8_t> cbor = JSON::to_cbor(json);
1926  check(raw::dqcs_arb_cbor_set(handle, cbor.data(), cbor.size()));
1927  }
1928 
1939  std::string get_arb_arg_string(ssize_t index) const {
1940  size_t size = check(raw::dqcs_arb_get_size(handle, index));
1941  std::string data;
1942  data.resize(size);
1943  check(raw::dqcs_arb_get_raw(handle, index, &data.front(), size));
1944  return data;
1945  }
1946 
1963  template <typename T>
1964  T get_arb_arg_as(ssize_t index) const {
1965  size_t size = check(raw::dqcs_arb_get_size(handle, index));
1966  if (size != sizeof(T)) {
1967  throw std::runtime_error(
1968  "Arbitrary argument has incorrect size: "
1969  "found " + std::to_string(size) + " bytes, "
1970  "expected " + std::to_string(sizeof(T)) + " bytes");
1971  }
1972  T data;
1973  check(raw::dqcs_arb_get_raw(handle, index, &data, sizeof(data)));
1974  return data;
1975  }
1976 
1985  template <typename T>
1986  void set_arb_arg_strings(const T &strings) {
1987  clear_arb_args();
1988  for (const std::string &string : strings) {
1989  push_arb_arg_string(string);
1990  }
1991  }
1992 
2002  void set_arb_arg_string(ssize_t index, const std::string &data) {
2003  check(raw::dqcs_arb_set_raw(handle, index, data.data(), data.size()));
2004  }
2005 
2021  template <typename T>
2022  void set_arb_arg(ssize_t index, const T &data) {
2023  check(raw::dqcs_arb_set_raw(handle, index, &data, sizeof(data)));
2024  }
2025 
2033  void push_arb_arg_string(const std::string &data) {
2034  check(raw::dqcs_arb_push_raw(handle, data.data(), data.size()));
2035  }
2036 
2049  template <typename T>
2050  void push_arb_arg(const T &data) {
2051  check(raw::dqcs_arb_push_raw(handle, &data, sizeof(data)));
2052  }
2053 
2062  std::string pop_arb_arg_string() {
2063  size_t size = check(raw::dqcs_arb_get_size(handle, -1));
2064  std::string data;
2065  data.resize(size);
2066  check(raw::dqcs_arb_pop_raw(handle, &data.front(), size));
2067  return data;
2068  }
2069 
2086  template <typename T>
2087  T pop_arb_arg_as() const {
2088  size_t size = check(raw::dqcs_arb_get_size(handle, -1));
2089  if (size != sizeof(T)) {
2090  throw std::runtime_error(
2091  "Arbitrary argument has incorrect size: "
2092  "found " + std::to_string(size) + " bytes, "
2093  "expected " + std::to_string(sizeof(T)) + " bytes");
2094  }
2095  T data;
2096  check(raw::dqcs_arb_pop_raw(handle, &data, sizeof(data)));
2097  return data;
2098  }
2099 
2110  void insert_arb_arg_string(ssize_t index, const std::string &data) {
2111  check(raw::dqcs_arb_insert_raw(handle, index, data.data(), data.size()));
2112  }
2113 
2130  template <typename T>
2131  void insert_arb_arg(ssize_t index, const T &data) {
2132  check(raw::dqcs_arb_insert_raw(handle, index, &data, sizeof(data)));
2133  }
2134 
2143  void remove_arb_arg(ssize_t index) {
2145  }
2146 
2153  size_t get_arb_arg_count() const {
2154  return check(raw::dqcs_arb_len(handle));
2155  }
2156 
2164  }
2165 
2172  void set_arb(const Arb &src) {
2174  }
2175 
2176  };
2177 
2202  class ArbData : public Arb {
2203  public:
2204 
2214  }
2215 
2223  }
2224 
2233  ArbData(const Arb &src) : Arb(check(raw::dqcs_arb_new())) {
2234  set_arb(src);
2235  }
2236 
2244  ArbData(const ArbData &src) : Arb(check(raw::dqcs_arb_new())) {
2245  set_arb(src);
2246  }
2247 
2254  void operator=(const ArbData &src) {
2255  set_arb(src);
2256  }
2257 
2261  ArbData(ArbData&&) = default;
2262 
2266  ArbData &operator=(ArbData&&) = default;
2267 
2268  // Include builder pattern functions.
2272  #define ARB_BUILDER_SUBCLASS ArbData
2273 
2283  ARB_BUILDER_SUBCLASS &with_json_string(const std::string &json) {
2284  set_arb_json_string(json);
2285  return *this;
2286  }
2287 
2297  ARB_BUILDER_SUBCLASS &with_cbor_string(const std::string &cbor) {
2298  set_arb_cbor_string(cbor);
2299  return *this;
2300  }
2301 
2313  template <class JSON>
2314  ARB_BUILDER_SUBCLASS &with_json(const JSON &json) {
2315  set_arb_json(json);
2316  return *this;
2317  }
2318 
2328  ARB_BUILDER_SUBCLASS &with_arg_string(const std::string &data) {
2329  push_arb_arg_string(data);
2330  return *this;
2331  }
2332 
2347  template <typename T>
2348  ARB_BUILDER_SUBCLASS &with_arg(const T &data) {
2349  push_arb_arg(data);
2350  return *this;
2351  }
2352 
2353  #undef ARB_BUILDER_SUBCLASS
2354 
2355  };
2356 
2362  class Cmd : public Arb {
2363  public:
2364 
2374  }
2375 
2382  std::string get_iface() const {
2383  char *iface_c = check(raw::dqcs_cmd_iface_get(handle));
2384  std::string iface(iface_c);
2385  std::free(iface_c);
2386  return iface;
2387  }
2388 
2396  bool is_iface(const std::string &iface) const {
2397  return check(raw::dqcs_cmd_iface_cmp(handle, iface.c_str()));
2398  }
2399 
2406  std::string get_oper() const {
2407  char *oper_c = check(raw::dqcs_cmd_oper_get(handle));
2408  std::string oper(oper_c);
2409  std::free(oper_c);
2410  return oper;
2411  }
2412 
2420  bool is_oper(const std::string &oper) const {
2421  return check(raw::dqcs_cmd_oper_cmp(handle, oper.c_str()));
2422  }
2423 
2424  };
2425 
2456  class ArbCmd : public Cmd {
2457  public:
2458 
2468  }
2469 
2478  ArbCmd(const std::string &iface, const std::string &oper) : Cmd(check(raw::dqcs_cmd_new(
2479  iface.c_str(), oper.c_str()
2480  ))) {
2481  }
2482 
2491  ArbCmd(const Cmd &src) : Cmd(check(raw::dqcs_cmd_new(
2492  src.get_iface().c_str(), src.get_oper().c_str()
2493  ))) {
2494  set_arb(src);
2495  }
2496 
2504  ArbCmd(const ArbCmd &src) : Cmd(check(raw::dqcs_cmd_new(
2505  src.get_iface().c_str(), src.get_oper().c_str()
2506  ))) {
2507  set_arb(src);
2508  }
2509 
2517  void operator=(const ArbCmd &src) {
2518  // The C API doesn't allow `ArbCmd`s to be copied natively, so we need to
2519  // make a new one and drop the old handle. We make the copy before
2520  // exchanging the handles to avoid changing our state if the copy
2521  // operation throws an error for some reason.
2522  ArbCmd copy(src);
2523  free();
2524  handle = copy.take_handle();
2525  }
2526 
2530  ArbCmd(ArbCmd&&) = default;
2531 
2535  ArbCmd &operator=(ArbCmd&&) = default;
2536 
2537  // Include builder pattern functions.
2541  #define ARB_BUILDER_SUBCLASS ArbCmd
2542 
2552  ARB_BUILDER_SUBCLASS &with_json_string(const std::string &json) {
2553  set_arb_json_string(json);
2554  return *this;
2555  }
2556 
2566  ARB_BUILDER_SUBCLASS &with_cbor_string(const std::string &cbor) {
2567  set_arb_cbor_string(cbor);
2568  return *this;
2569  }
2570 
2582  template <class JSON>
2583  ARB_BUILDER_SUBCLASS &with_json(const JSON &json) {
2584  set_arb_json(json);
2585  return *this;
2586  }
2587 
2597  ARB_BUILDER_SUBCLASS &with_arg_string(const std::string &data) {
2598  push_arb_arg_string(data);
2599  return *this;
2600  }
2601 
2616  template <typename T>
2617  ARB_BUILDER_SUBCLASS &with_arg(const T &data) {
2618  push_arb_arg(data);
2619  return *this;
2620  }
2621 
2622  #undef ARB_BUILDER_SUBCLASS
2623 
2624  };
2625 
2652  class ArbCmdQueue : public Cmd {
2653  public:
2654 
2664  }
2665 
2673  }
2674 
2681  void push(ArbCmd &&cmd) {
2682  check(raw::dqcs_cq_push(handle, cmd.get_handle()));
2683  }
2684 
2692  void push(const Cmd &cmd) {
2693  push(ArbCmd(cmd));
2694  }
2695 
2706  template <class T>
2707  static ArbCmdQueue from_iter(T &&cmds) {
2708  ArbCmdQueue result;
2709  for (Cmd &cmd : cmds) {
2710  result.push(std::move(cmd));
2711  }
2712  return result;
2713  }
2714 
2724  template <class T>
2725  static ArbCmdQueue from_iter(const T &cmds) {
2726  ArbCmdQueue result;
2727  for (const Cmd &cmd : cmds) {
2728  result.push(cmd);
2729  }
2730  return result;
2731  }
2732 
2741  push(std::move(cmd));
2742  return std::move(*this);
2743  }
2744 
2753  ArbCmdQueue &&with(const Cmd &cmd) {
2754  push(cmd);
2755  return std::move(*this);
2756  }
2757 
2765  void next() {
2767  }
2768 
2775  size_t size() const {
2776  return check(raw::dqcs_cq_len(handle));
2777  }
2778 
2786  std::vector<ArbCmd> drain_into_vector() {
2787  std::vector<ArbCmd> cmds;
2788  for (; size() > 0; next()) {
2789  cmds.emplace_back(*this);
2790  }
2791  return cmds;
2792  }
2793 
2806  std::vector<ArbCmd> copy_into_vector() {
2807  std::vector<ArbCmd> cmds = drain_into_vector();
2808  free();
2810  return cmds;
2811  }
2812 
2826  }
2827 
2841  free();
2843  return *this;
2844  }
2845 
2849  ArbCmdQueue(ArbCmdQueue&&) = default;
2850 
2855 
2856  };
2857 
2874  class QubitRef {
2875  private:
2876 
2880  QubitIndex index;
2881 
2882  public:
2883 
2890  QubitRef(QubitIndex index) : index(index) {
2891  if (index == 0) {
2892  throw std::runtime_error("Qubit indices cannot be zero in DQCsim");
2893  }
2894  }
2895 
2899  QubitRef(const QubitRef&) = default;
2900 
2904  QubitRef &operator=(const QubitRef&) = default;
2905 
2909  QubitRef(QubitRef&&) = default;
2910 
2914  QubitRef &operator=(QubitRef&&) = default;
2915 
2922  bool operator==(const QubitRef &other) const noexcept {
2923  return index == other.index;
2924  }
2925 
2932  bool operator!=(const QubitRef &other) const noexcept {
2933  return index != other.index;
2934  }
2935 
2943  friend std::ostream& operator<<(std::ostream &out, const QubitRef &qubit) {
2944  out << 'q' << qubit.index;
2945  return out;
2946  }
2947 
2953  QubitIndex get_index() const noexcept {
2954  return index;
2955  }
2956 
2957  };
2958 
2962  inline QubitRef operator "" _q(unsigned long long int qubit) {
2963  return QubitRef(qubit);
2964  }
2965 
2982  class QubitSet : public Handle {
2983  public:
2984 
2994  }
2995 
3003  }
3004 
3012  template <class T>
3013  static QubitSet from_iter(const T &qubits) {
3014  QubitSet result;
3015  for (const QubitRef &qubit : qubits) {
3016  result.push(qubit);
3017  }
3018  return result;
3019  }
3020 
3028  QubitSet(const QubitSet &src) : Handle(check(raw::dqcs_qbset_copy(src.handle))) {
3029  }
3030 
3039  void operator=(const QubitSet &src) {
3040  QubitSet copy(src);
3041  free();
3042  handle = copy.take_handle();
3043  }
3044 
3048  QubitSet(QubitSet&&) = default;
3049 
3053  QubitSet &operator=(QubitSet&&) = default;
3054 
3062  void push(const QubitRef &qubit) {
3064  }
3065 
3074  QubitSet &&with(const QubitRef &qubit) {
3075  push(qubit);
3076  return std::move(*this);
3077  }
3078 
3088  }
3089 
3096  size_t size() const {
3097  return check(raw::dqcs_qbset_len(handle));
3098  }
3099 
3107  bool contains(const QubitRef &qubit) const {
3108  return check(raw::dqcs_qbset_contains(handle, qubit.get_index()));
3109  }
3110 
3122  std::vector<QubitRef> drain_into_vector() {
3123  std::vector<QubitRef> qubits;
3124  while (size()) {
3125  qubits.emplace_back(pop());
3126  }
3127  return qubits;
3128  }
3129 
3141  std::vector<QubitRef> copy_into_vector() const {
3142  QubitSet copy(*this);
3143  return copy.drain_into_vector();
3144  }
3145 
3146  };
3147 
3151  using complex = std::complex<double>;
3152 
3160  class Matrix : public Handle {
3161  public:
3162 
3172  }
3173 
3186  Matrix(size_t num_qubits, const complex *matrix)
3187  : Handle(check(raw::dqcs_mat_new(num_qubits, (const double *)matrix))) {
3188  }
3189 
3202  Matrix(size_t num_qubits, const double *matrix)
3203  : Handle(check(raw::dqcs_mat_new(num_qubits, matrix))) {
3204  }
3205 
3215  : Handle(check(raw::dqcs_mat_predef(to_raw(gate), 0))) {
3216  }
3217 
3242  Matrix(PredefinedGate gate, ArbData &&parameters)
3243  : Handle(check(raw::dqcs_mat_predef(to_raw(gate), parameters.get_handle()))) {
3244  }
3245 
3256  Matrix(PredefinedGate gate, const ArbData &parameters)
3257  : Handle(check(raw::dqcs_mat_predef(to_raw(gate), ArbData(parameters).get_handle()))) {
3258  }
3259 
3268  : Handle(check(raw::dqcs_mat_basis(to_raw(basis)))) {
3269  }
3270 
3278  Matrix(const Matrix &src)
3279  : Handle(check(raw::dqcs_mat_add_controls(src.get_handle(), 0))) {
3280  }
3281 
3290  void operator=(const Matrix &src) {
3291  Matrix copy(src);
3292  free();
3293  handle = copy.take_handle();
3294  }
3295 
3299  Matrix(Matrix&&) = default;
3300 
3304  Matrix &operator=(Matrix&&) = default;
3305 
3312  size_t size() const {
3313  return check(raw::dqcs_mat_len(handle));
3314  }
3315 
3322  size_t dimension() const {
3324  }
3325 
3332  size_t num_qubits() const {
3334  }
3335 
3343  std::vector<complex> get() const {
3344  size_t s = size();
3345  std::vector<complex> vec(s);
3346  double *data = check(raw::dqcs_mat_get(handle));
3347  std::memcpy(vec.data(), data, s * sizeof(complex));
3348  return vec;
3349  }
3350 
3358  std::vector<double> get_as_doubles() const {
3359  size_t s = size();
3360  std::vector<double> vec(s * 2);
3361  double *data = check(raw::dqcs_mat_get(handle));
3362  std::memcpy(vec.data(), data, 2 * s * sizeof(double));
3363  return vec;
3364  }
3365 
3383  const Matrix &other,
3384  double epsilon = 0.000001,
3385  bool ignore_global_phase = true
3386  ) const {
3387  return check(raw::dqcs_mat_approx_eq(handle, other.get_handle(), epsilon, ignore_global_phase));
3388  }
3389 
3408  const Matrix &other,
3409  double epsilon = 0.000001
3410  ) const {
3411  return check(raw::dqcs_mat_basis_approx_eq(handle, other.get_handle(), epsilon));
3412  }
3413 
3425  bool approx_unitary(double epsilon = 0.000001) const {
3426  return check(raw::dqcs_mat_approx_unitary(handle, epsilon));
3427  }
3428 
3450  PredefinedGate gate,
3451  double epsilon = 0.000001,
3452  bool ignore_global_phase = true,
3453  ArbData *parameters = nullptr
3454  ) const {
3455  if (parameters) {
3456  raw::dqcs_handle_t param_data = 0;
3457  bool match = check(raw::dqcs_mat_is_predef(handle, to_raw(gate), &param_data, epsilon, ignore_global_phase));
3458  if (!match) return false;
3459  *parameters = ArbData(param_data);
3460  return true;
3461  }
3462  return check(raw::dqcs_mat_is_predef(handle, to_raw(gate), nullptr, epsilon, ignore_global_phase));
3463  }
3464 
3473  Matrix add_controls(size_t number_of_controls) const {
3474  return Matrix(check(raw::dqcs_mat_add_controls(handle, number_of_controls)));
3475  }
3476 
3495  std::pair<std::vector<size_t>, Matrix> strip_control(double epsilon, bool ignore_global_phase) const {
3496  ssize_t *indices = nullptr;
3497  std::pair<std::vector<size_t>, Matrix> result(
3498  std::vector<size_t>(),
3499  check(raw::dqcs_mat_strip_control(handle, epsilon, ignore_global_phase, &indices))
3500  );
3501  while (*indices != -1) {
3502  result.first.push_back(*indices++);
3503  }
3504  return result;
3505  }
3506 
3507  };
3508 
3552  class Gate : public Arb {
3553  public:
3554 
3564  }
3565 
3566  // Delete copy construct/assign.
3567  Gate(const Gate&) = delete;
3568  void operator=(const Gate&) = delete;
3569 
3573  Gate(Gate&&) = default;
3574 
3578  Gate &operator=(Gate&&) = default;
3579 
3597  static Gate predefined(PredefinedGate gate, QubitSet &&qubits, ArbData &&parameters) {
3599  to_raw(gate),
3600  qubits.get_handle(),
3601  parameters.get_handle()
3602  )));
3603  }
3604 
3622  static Gate predefined(PredefinedGate gate, const QubitSet &qubits, const ArbData &parameters) {
3623  return predefined(gate, QubitSet(qubits), ArbData(parameters));
3624  }
3625 
3639  static Gate predefined(PredefinedGate gate, QubitSet &&qubits) {
3641  to_raw(gate),
3642  qubits.get_handle(),
3643  0
3644  )));
3645  }
3646 
3660  static Gate predefined(PredefinedGate gate, const QubitSet &qubits) {
3661  return predefined(gate, QubitSet(qubits));
3662  }
3663 
3674  static Gate unitary(QubitSet &&targets, const Matrix &matrix) {
3676  targets.get_handle(),
3677  0,
3678  matrix.get_handle()
3679  )));
3680  }
3681 
3693  static Gate unitary(const QubitSet &targets, const Matrix &matrix) {
3694  return unitary(QubitSet(targets), matrix);
3695  }
3696 
3711  static Gate unitary(QubitSet &&targets, QubitSet &&controls, const Matrix &matrix) {
3713  targets.get_handle(),
3714  controls.get_handle(),
3715  matrix.get_handle()
3716  )));
3717  }
3718 
3734  static Gate unitary(const QubitSet &targets, const QubitSet &controls, const Matrix &matrix) {
3735  return unitary(QubitSet(targets), QubitSet(controls), matrix);
3736  }
3737 
3749  static Gate measure(QubitSet &&measures) {
3750  return Gate(check(raw::dqcs_gate_new_measurement(measures.get_handle(), 0)));
3751  }
3752 
3764  static Gate measure(const QubitSet &measures) {
3765  return measure(QubitSet(measures));
3766  }
3767 
3780  static Gate measure(QubitSet &&measures, PauliBasis basis) {
3781  return Gate(check(raw::dqcs_gate_new_measurement(measures.get_handle(), Matrix(basis).get_handle())));
3782  }
3783 
3796  static Gate measure(const QubitSet &measures, PauliBasis basis) {
3797  return measure(QubitSet(measures), basis);
3798  }
3799 
3813  static Gate measure(QubitSet &&measures, Matrix &&basis) {
3814  return Gate(check(raw::dqcs_gate_new_measurement(measures.get_handle(), basis.get_handle())));
3815  }
3816 
3830  static Gate measure(const QubitSet &measures, const Matrix &basis) {
3831  return measure(QubitSet(measures), Matrix(basis));
3832  }
3833 
3842  static Gate prep(QubitSet &&targets) {
3843  return Gate(check(raw::dqcs_gate_new_prep(targets.get_handle(), 0)));
3844  }
3845 
3854  static Gate prep(const QubitSet &targets) {
3855  return prep(QubitSet(targets));
3856  }
3857 
3868  static Gate prep(QubitSet &&targets, PauliBasis basis) {
3869  return Gate(check(raw::dqcs_gate_new_prep(targets.get_handle(), Matrix(basis).get_handle())));
3870  }
3871 
3882  static Gate prep(const QubitSet &targets, PauliBasis basis) {
3883  return prep(QubitSet(targets), basis);
3884  }
3885 
3896  static Gate prep(QubitSet &&targets, Matrix &&basis) {
3897  return Gate(check(raw::dqcs_gate_new_prep(targets.get_handle(), basis.get_handle())));
3898  }
3899 
3910  static Gate prep(const QubitSet &targets, const Matrix &basis) {
3911  return prep(QubitSet(targets), Matrix(basis));
3912  }
3913 
3914  // also TODO: gatemap prep and measure
3915 
3937  static Gate custom(
3938  const std::string &name,
3939  QubitSet &&targets,
3940  QubitSet &&controls,
3941  QubitSet &&measures,
3942  const Matrix &matrix
3943  ) {
3945  name.c_str(),
3946  targets.get_handle(),
3947  controls.get_handle(),
3948  measures.get_handle(),
3949  matrix.get_handle()
3950  )));
3951  }
3952 
3975  static Gate custom(
3976  const std::string &name,
3977  const QubitSet &targets,
3978  const QubitSet &controls,
3979  const QubitSet &measures,
3980  const Matrix &matrix
3981  ) {
3982  return custom(
3983  name,
3984  QubitSet(targets),
3985  QubitSet(controls),
3986  QubitSet(measures),
3987  matrix
3988  );
3989  }
3990 
4008  static Gate custom(
4009  const std::string &name,
4010  QubitSet &&targets,
4011  QubitSet &&controls,
4012  QubitSet &&measures
4013  ) {
4015  name.c_str(),
4016  targets.get_handle(),
4017  controls.get_handle(),
4018  measures.get_handle(),
4019  0
4020  )));
4021  }
4022 
4041  static Gate custom(
4042  const std::string &name,
4043  const QubitSet &targets,
4044  const QubitSet &controls,
4045  const QubitSet &measures
4046  ) {
4047  return custom(
4048  name,
4049  QubitSet(targets),
4050  QubitSet(controls),
4051  QubitSet(measures)
4052  );
4053  }
4054 
4072  static Gate custom(
4073  const std::string &name,
4074  QubitSet &&targets,
4075  QubitSet &&controls,
4076  const Matrix &matrix
4077  ) {
4079  name.c_str(),
4080  targets.get_handle(),
4081  controls.get_handle(),
4082  0,
4083  matrix.get_handle()
4084  )));
4085  }
4086 
4105  static Gate custom(
4106  const std::string &name,
4107  const QubitSet &targets,
4108  const QubitSet &controls,
4109  const Matrix &matrix
4110  ) {
4111  return custom(
4112  name,
4113  QubitSet(targets),
4114  QubitSet(controls),
4115  matrix
4116  );
4117  }
4118 
4131  static Gate custom(
4132  const std::string &name,
4133  QubitSet &&targets,
4134  QubitSet &&controls
4135  ) {
4137  name.c_str(),
4138  targets.get_handle(),
4139  controls.get_handle(),
4140  0,
4141  0
4142  )));
4143  }
4144 
4158  static Gate custom(
4159  const std::string &name,
4160  const QubitSet &targets,
4161  const QubitSet &controls
4162  ) {
4163  return custom(
4164  name,
4165  QubitSet(targets),
4166  QubitSet(controls)
4167  );
4168  }
4169 
4182  static Gate custom(
4183  const std::string &name,
4184  QubitSet &&targets,
4185  const Matrix &matrix
4186  ) {
4188  name.c_str(),
4189  targets.get_handle(),
4190  0,
4191  0,
4192  matrix.get_handle()
4193  )));
4194  }
4195 
4209  static Gate custom(
4210  const std::string &name,
4211  const QubitSet &targets,
4212  const Matrix &matrix
4213  ) {
4214  return custom(
4215  name,
4216  QubitSet(targets),
4217  matrix
4218  );
4219  }
4220 
4231  static Gate custom(
4232  const std::string &name,
4233  QubitSet &&targets
4234  ) {
4236  name.c_str(),
4237  targets.get_handle(),
4238  0,
4239  0,
4240  0
4241  )));
4242  }
4243 
4255  static Gate custom(
4256  const std::string &name,
4257  const QubitSet &targets
4258  ) {
4259  return custom(
4260  name,
4261  QubitSet(targets)
4262  );
4263  }
4264 
4274  static Gate custom(
4275  const std::string &name
4276  ) {
4278  name.c_str(),
4279  0,
4280  0,
4281  0,
4282  0
4283  )));
4284  }
4285 
4292  GateType get_type() const {
4293  return check(raw::dqcs_gate_type(handle));
4294  }
4295 
4305  }
4306 
4313  bool has_targets() const {
4315  }
4316 
4326  }
4327 
4334  bool has_controls() const {
4336  }
4337 
4349  }
4350 
4357  bool has_measures() const {
4359  }
4360 
4368  Matrix get_matrix() const {
4370  }
4371 
4378  bool has_matrix() const {
4380  }
4381 
4388  std::string get_name() const {
4389  char *data = check(raw::dqcs_gate_name(handle));
4390  std::string name(data);
4391  std::free(data);
4392  return name;
4393  }
4394 
4401  bool has_name() const {
4403  }
4404 
4405  // Include `ArbData` builder pattern functions.
4409  #define ARB_BUILDER_SUBCLASS Gate
4410 
4420  ARB_BUILDER_SUBCLASS &with_json_string(const std::string &json) {
4421  set_arb_json_string(json);
4422  return *this;
4423  }
4424 
4434  ARB_BUILDER_SUBCLASS &with_cbor_string(const std::string &cbor) {
4435  set_arb_cbor_string(cbor);
4436  return *this;
4437  }
4438 
4450  template <class JSON>
4451  ARB_BUILDER_SUBCLASS &with_json(const JSON &json) {
4452  set_arb_json(json);
4453  return *this;
4454  }
4455 
4465  ARB_BUILDER_SUBCLASS &with_arg_string(const std::string &data) {
4466  push_arb_arg_string(data);
4467  return *this;
4468  }
4469 
4484  template <typename T>
4485  ARB_BUILDER_SUBCLASS &with_arg(const T &data) {
4486  push_arb_arg(data);
4487  return *this;
4488  }
4489 
4490  #undef ARB_BUILDER_SUBCLASS
4491 
4492  };
4493 
4499  private:
4500 
4501  // `GateMap`s are a friend, so they can take pointers to the static
4502  // callback entry points.
4503  template <class Unbound, class Bound>
4504  friend class GateMap;
4505 
4509  static raw::dqcs_bool_return_t raw_detector(
4510  const void *user_data,
4511  raw::dqcs_handle_t gate,
4512  raw::dqcs_handle_t *qubits,
4513  raw::dqcs_handle_t *params
4514  ) noexcept {
4515  try {
4516  auto converter = reinterpret_cast<const std::shared_ptr<CustomGateConverter>*>(user_data);
4517  Gate gate_wrapper = Gate(gate);
4518  QubitSet qubits_wrapper = QubitSet();
4519  ArbData params_wrapper = ArbData();
4520  params_wrapper.set_arb(gate_wrapper);
4521  if (!(*converter)->detect(std::move(gate_wrapper), qubits_wrapper, params_wrapper)) {
4523  }
4524  *qubits = qubits_wrapper.take_handle();
4525  *params = params_wrapper.take_handle();
4527  } catch (const std::exception &e) {
4528  raw::dqcs_error_set(e.what());
4529  }
4531  }
4532 
4536  static raw::dqcs_handle_t raw_constructor(
4537  const void *user_data,
4538  raw::dqcs_handle_t qubits,
4539  raw::dqcs_handle_t params
4540  ) noexcept {
4541  try {
4542  auto converter = reinterpret_cast<const std::shared_ptr<CustomGateConverter>*>(user_data);
4543  return (*converter)->construct(QubitSet(qubits), ArbData(params)).take_handle();
4544  } catch (const std::exception &e) {
4545  raw::dqcs_error_set(e.what());
4546  }
4547  return 0;
4548  }
4549 
4553  static void raw_deleter(void *user_data) noexcept {
4554  auto converter = reinterpret_cast<const std::shared_ptr<CustomGateConverter>*>(user_data);
4555  delete converter;
4556  }
4557 
4558  public:
4559 
4560  // We're using inheritance, so ensure that the destructor as virtual.
4561  virtual ~CustomGateConverter() = default;
4562 
4580  virtual bool detect(Gate &&gate, QubitSet &qubits, ArbData &params) const {
4581  return false;
4582  }
4583 
4596  virtual Gate construct(QubitSet &&qubits, ArbData &&params) const {
4597  throw std::runtime_error("detector function not implemented");
4598  }
4599 
4600  };
4601 
4607  private:
4608 
4609  // `GateMap`s are a friend, so they can take pointers to the static
4610  // callback entry points.
4611  template <class Unbound, class Bound>
4612  friend class GateMap;
4613 
4617  static raw::dqcs_bool_return_t raw_detector(
4618  const void *user_data,
4619  raw::dqcs_handle_t matrix,
4620  size_t num_controls,
4621  raw::dqcs_handle_t *params
4622  ) noexcept {
4623  try {
4624  auto converter = reinterpret_cast<const std::shared_ptr<CustomUnitaryGateConverter>*>(user_data);
4625  ArbData params_wrapper = ArbData(*params);
4626  if (!(*converter)->detect(Matrix(matrix), num_controls, params_wrapper)) {
4628  }
4629  *params = params_wrapper.take_handle();
4631  } catch (const std::exception &e) {
4632  raw::dqcs_error_set(e.what());
4633  }
4635  }
4636 
4640  static raw::dqcs_handle_t raw_constructor(
4641  const void *user_data,
4642  raw::dqcs_handle_t *params,
4643  ssize_t *num_controls
4644  ) noexcept {
4645  try {
4646  auto converter = reinterpret_cast<const std::shared_ptr<CustomUnitaryGateConverter>*>(user_data);
4647  ArbData params_wrapper = ArbData(*params);
4648  Matrix matrix = (*converter)->construct(params_wrapper, *num_controls);
4649  *params = params_wrapper.take_handle();
4650  return matrix.take_handle();
4651  } catch (const std::exception &e) {
4652  raw::dqcs_error_set(e.what());
4653  }
4654  return 0;
4655  }
4656 
4660  static void raw_deleter(void *user_data) noexcept {
4661  auto converter = reinterpret_cast<const std::shared_ptr<CustomUnitaryGateConverter>*>(user_data);
4662  delete converter;
4663  }
4664 
4665  public:
4666 
4667  // We're using inheritance, so ensure that the destructor as virtual.
4668  virtual ~CustomUnitaryGateConverter() = default;
4669 
4688  virtual bool detect(Matrix &&matrix, ssize_t num_controls, ArbData &params) const {
4689  return false;
4690  }
4691 
4708  virtual Matrix construct(ArbData &params, ssize_t &num_controls) const {
4709  throw std::runtime_error("detector function not implemented");
4710  }
4711 
4712  };
4713 
4749  template <class Unbound, class Bound=Unbound>
4750  class GateMap : public Handle {
4751  private:
4752 
4757  static bool unbound_equality(const void *a, const void *b) {
4758  return *(const Unbound*)a == *(const Unbound*)b;
4759  }
4760 
4764  static uint64_t unbound_hash(const void *a) {
4765  return (uint64_t)std::hash<Unbound>{}(*(const Unbound*)a);
4766  }
4767 
4771  static void unbound_delete(void *a) {
4772  delete (Unbound*)a;
4773  }
4774 
4775  public:
4776 
4786  }
4787 
4807  GateMap(bool strip_qubit_refs = false, bool strip_data = false)
4808  : Handle(check(raw::dqcs_gm_new(strip_qubit_refs, strip_data, unbound_equality, unbound_hash))) {
4809  }
4810 
4811  // Delete copy construct/assign.
4812  GateMap(const GateMap&) = delete;
4813  void operator=(const GateMap&) = delete;
4814 
4818  GateMap(GateMap&&) = default;
4819 
4823  GateMap &operator=(GateMap&&) = default;
4824 
4848  Unbound &&key,
4849  PredefinedGate gate,
4850  int num_controls = -1,
4851  double epsilon = 0.000001,
4852  bool ignore_global_phase = true
4853  ) {
4855  handle,
4856  unbound_delete,
4857  new Unbound(std::move(key)),
4858  to_raw(gate),
4859  num_controls,
4860  epsilon,
4861  ignore_global_phase
4862  ));
4863  return std::move(*this);
4864  }
4865 
4889  const Unbound &key,
4890  PredefinedGate gate,
4891  int num_controls = -1,
4892  double epsilon = 0.000001,
4893  bool ignore_global_phase = true
4894  ) {
4896  handle,
4897  unbound_delete,
4898  new Unbound(key),
4899  to_raw(gate),
4900  num_controls,
4901  epsilon,
4902  ignore_global_phase
4903  ));
4904  return std::move(*this);
4905  }
4906 
4930  Unbound &&key,
4931  Matrix &&matrix,
4932  int num_controls = -1,
4933  double epsilon = 0.000001,
4934  bool ignore_global_phase = true
4935  ) {
4937  handle,
4938  unbound_delete,
4939  new Unbound(std::move(key)),
4940  matrix.get_handle(),
4941  num_controls,
4942  epsilon,
4943  ignore_global_phase
4944  ));
4945  return std::move(*this);
4946  }
4947 
4971  const Unbound &key,
4972  const Matrix &matrix,
4973  int num_controls = -1,
4974  double epsilon = 0.000001,
4975  bool ignore_global_phase = true
4976  ) {
4978  handle,
4979  unbound_delete,
4980  new Unbound(key),
4981  Matrix(matrix).get_handle(),
4982  num_controls,
4983  epsilon,
4984  ignore_global_phase
4985  ));
4986  return std::move(*this);
4987  }
4988 
5004  Unbound &&key,
5005  const std::shared_ptr<CustomUnitaryGateConverter> &converter
5006  ) {
5008  handle,
5009  unbound_delete,
5010  new Unbound(std::move(key)),
5011  CustomUnitaryGateConverter::raw_detector,
5012  CustomUnitaryGateConverter::raw_deleter,
5013  new std::shared_ptr<CustomUnitaryGateConverter>(converter),
5014  CustomUnitaryGateConverter::raw_constructor,
5015  CustomUnitaryGateConverter::raw_deleter,
5016  new std::shared_ptr<CustomUnitaryGateConverter>(converter)
5017  ));
5018  return std::move(*this);
5019  }
5020 
5036  const Unbound &key,
5037  const std::shared_ptr<CustomUnitaryGateConverter> &converter
5038  ) {
5040  handle,
5041  unbound_delete,
5042  new Unbound(key),
5043  CustomUnitaryGateConverter::raw_detector,
5044  CustomUnitaryGateConverter::raw_deleter,
5045  new std::shared_ptr<CustomUnitaryGateConverter>(converter),
5046  CustomUnitaryGateConverter::raw_constructor,
5047  CustomUnitaryGateConverter::raw_deleter,
5048  new std::shared_ptr<CustomUnitaryGateConverter>(converter)
5049  ));
5050  return std::move(*this);
5051  }
5052 
5072  Unbound &&key,
5073  PauliBasis basis = PauliBasis::Z,
5074  double epsilon = 0.000001,
5075  int num_measures = -1
5076  ) {
5078  handle,
5079  unbound_delete,
5080  new Unbound(std::move(key)),
5081  num_measures,
5082  Matrix(basis).get_handle(),
5083  epsilon
5084  ));
5085  return std::move(*this);
5086  }
5087 
5107  const Unbound &key,
5108  PauliBasis basis = PauliBasis::Z,
5109  double epsilon = 0.000001,
5110  int num_measures = -1
5111  ) {
5113  handle,
5114  unbound_delete,
5115  new Unbound(key),
5116  num_measures,
5117  Matrix(basis).get_handle(),
5118  epsilon
5119  ));
5120  return std::move(*this);
5121  }
5122 
5142  Unbound &&key,
5143  Matrix &&basis,
5144  double epsilon = 0.000001,
5145  int num_measures = -1
5146  ) {
5148  handle,
5149  unbound_delete,
5150  new Unbound(std::move(key)),
5151  num_measures,
5152  basis.get_handle(),
5153  epsilon
5154  ));
5155  return std::move(*this);
5156  }
5157 
5177  const Unbound &key,
5178  const Matrix &basis,
5179  double epsilon = 0.000001,
5180  int num_measures = -1
5181  ) {
5183  handle,
5184  unbound_delete,
5185  new Unbound(key),
5186  num_measures,
5187  Matrix(basis).get_handle(),
5188  epsilon
5189  ));
5190  return std::move(*this);
5191  }
5192 
5212  Unbound &&key,
5213  PauliBasis basis = PauliBasis::Z,
5214  double epsilon = 0.000001,
5215  int num_targets = -1
5216  ) {
5218  handle,
5219  unbound_delete,
5220  new Unbound(std::move(key)),
5221  num_targets,
5222  Matrix(basis).get_handle(),
5223  epsilon
5224  ));
5225  return std::move(*this);
5226  }
5227 
5247  const Unbound &key,
5248  PauliBasis basis = PauliBasis::Z,
5249  double epsilon = 0.000001,
5250  int num_targets = -1
5251  ) {
5253  handle,
5254  unbound_delete,
5255  new Unbound(key),
5256  num_targets,
5257  Matrix(basis).get_handle(),
5258  epsilon
5259  ));
5260  return std::move(*this);
5261  }
5262 
5282  Unbound &&key,
5283  Matrix &&basis,
5284  double epsilon = 0.000001,
5285  int num_targets = -1
5286  ) {
5288  handle,
5289  unbound_delete,
5290  new Unbound(std::move(key)),
5291  num_targets,
5292  basis.get_handle(),
5293  epsilon
5294  ));
5295  return std::move(*this);
5296  }
5297 
5317  const Unbound &key,
5318  const Matrix &basis,
5319  double epsilon = 0.000001,
5320  int num_targets = -1
5321  ) {
5323  handle,
5324  unbound_delete,
5325  new Unbound(key),
5326  num_targets,
5327  Matrix(basis).get_handle(),
5328  epsilon
5329  ));
5330  return std::move(*this);
5331  }
5332 
5348  Unbound &&key,
5349  const std::shared_ptr<CustomGateConverter> &converter
5350  ) {
5352  handle,
5353  unbound_delete,
5354  new Unbound(std::move(key)),
5355  CustomGateConverter::raw_detector,
5356  CustomGateConverter::raw_deleter,
5357  new std::shared_ptr<CustomGateConverter>(converter),
5358  CustomGateConverter::raw_constructor,
5359  CustomGateConverter::raw_deleter,
5360  new std::shared_ptr<CustomGateConverter>(converter)
5361  ));
5362  return std::move(*this);
5363  }
5364 
5380  const Unbound &key,
5381  const std::shared_ptr<CustomGateConverter> &converter
5382  ) {
5384  handle,
5385  unbound_delete,
5386  new Unbound(key),
5387  CustomGateConverter::raw_detector,
5388  CustomGateConverter::raw_deleter,
5389  new std::shared_ptr<CustomGateConverter>(converter),
5390  CustomGateConverter::raw_constructor,
5391  CustomGateConverter::raw_deleter,
5392  new std::shared_ptr<CustomGateConverter>(converter)
5393  ));
5394  return std::move(*this);
5395  }
5396 
5417  bool detect(
5418  const Gate &gate,
5419  const Unbound **unbound,
5420  QubitSet *qubits,
5421  ArbData *params
5422  ) {
5423  raw::dqcs_handle_t qubits_handle = 0;
5424  raw::dqcs_handle_t *qubits_handle_ptr = qubits ? &qubits_handle : nullptr;
5425  raw::dqcs_handle_t params_handle = 0;
5426  raw::dqcs_handle_t *params_handle_ptr = params ? &params_handle : nullptr;
5427  bool match = check(raw::dqcs_gm_detect(
5428  handle,
5429  gate.get_handle(),
5430  (const void**)unbound,
5431  qubits_handle_ptr,
5432  params_handle_ptr
5433  ));
5434  if (qubits && qubits_handle) *qubits = QubitSet(qubits_handle);
5435  if (params && params_handle) *params = ArbData(params_handle);
5436  return match;
5437  }
5438 
5452  const Unbound &unbound,
5453  QubitSet &&qubits,
5454  ArbData &&params
5455  ) {
5457  handle,
5458  &unbound,
5459  qubits.get_handle(),
5460  params.get_handle()
5461  )));
5462  }
5463 
5477  const Unbound &unbound,
5478  const QubitSet &qubits,
5479  const ArbData &params
5480  ) {
5481  return construct(unbound, QubitSet(qubits), ArbData(params));
5482  }
5483 
5495  const Unbound &unbound,
5496  QubitSet &&qubits
5497  ) {
5499  handle,
5500  &unbound,
5501  qubits.get_handle(),
5502  0
5503  )));
5504  }
5505 
5518  const Unbound &unbound,
5519  const QubitSet &qubits
5520  ) {
5521  return construct(unbound, QubitSet(qubits));
5522  }
5523 
5538  Bound convert(const Gate &gate) {
5539  const Unbound *unbound = nullptr;
5540  QubitSet qubits(0);
5541  ArbData params(0);
5542  if (!detect(gate, &unbound, &qubits, &params)) {
5543  throw std::runtime_error("unknown gate");
5544  }
5545  return unbound->bind(std::move(qubits), std::move(params));
5546  }
5547 
5563  Gate convert(const Bound &bound) {
5564  return construct(
5565  bound.get_unbound(),
5566  bound.get_qubits(),
5567  bound.get_params()
5568  );
5569  }
5570 
5571  };
5572 
5592  class Measurement : public Arb {
5593  public:
5594 
5604  }
5605 
5615  raw::dqcs_meas_new(qubit.get_index(), to_raw(value))
5616  )) {
5617  }
5618 
5627  raw::dqcs_meas_new(src.get_qubit().get_index(), to_raw(src.get_value()))
5628  )) {
5629  set_arb(src);
5630  }
5631 
5639  void operator=(const Measurement &src) {
5640  set_qubit(src.get_qubit());
5641  set_value(src.get_value());
5642  set_arb(src);
5643  }
5644 
5649 
5654 
5663  }
5664 
5673  }
5674 
5683  }
5684 
5691  void set_qubit(QubitRef qubit) {
5693  }
5694 
5695  // Include `ArbData` builder pattern functions.
5699  #define ARB_BUILDER_SUBCLASS Measurement
5700 
5710  ARB_BUILDER_SUBCLASS &with_json_string(const std::string &json) {
5711  set_arb_json_string(json);
5712  return *this;
5713  }
5714 
5724  ARB_BUILDER_SUBCLASS &with_cbor_string(const std::string &cbor) {
5725  set_arb_cbor_string(cbor);
5726  return *this;
5727  }
5728 
5740  template <class JSON>
5741  ARB_BUILDER_SUBCLASS &with_json(const JSON &json) {
5742  set_arb_json(json);
5743  return *this;
5744  }
5745 
5755  ARB_BUILDER_SUBCLASS &with_arg_string(const std::string &data) {
5756  push_arb_arg_string(data);
5757  return *this;
5758  }
5759 
5774  template <typename T>
5775  ARB_BUILDER_SUBCLASS &with_arg(const T &data) {
5776  push_arb_arg(data);
5777  return *this;
5778  }
5779 
5780  #undef ARB_BUILDER_SUBCLASS
5781 
5782  };
5783 
5789  class MeasurementSet : public Handle {
5790  public:
5791 
5801  }
5802 
5807  }
5808 
5819  template <class T>
5820  static MeasurementSet from_iter(const T &measurements) {
5821  MeasurementSet result;
5822  for (const Measurement &measurement : measurements) {
5823  result.set(measurement);
5824  }
5825  return result;
5826  }
5827 
5837  void set(Measurement &&measurement) {
5838  check(raw::dqcs_mset_set(handle, measurement.get_handle()));
5839  }
5840 
5850  void set(const Measurement &measurement) {
5851  set(Measurement(measurement));
5852  }
5853 
5864  MeasurementSet &&with(Measurement &&measurement) {
5865  set(std::move(measurement));
5866  return std::move(*this);
5867  }
5868 
5879  MeasurementSet &&with(const Measurement &measurement) {
5880  set(measurement);
5881  return std::move(*this);
5882  }
5883 
5894  Measurement get(const QubitRef &qubit) const {
5896  }
5897 
5909  Measurement take(const QubitRef &qubit) {
5911  }
5912 
5924  }
5925 
5934  void remove(const QubitRef &qubit) {
5936  }
5937 
5944  size_t size() const {
5945  return check(raw::dqcs_mset_len(handle));
5946  }
5947 
5956  bool contains(const QubitRef &qubit) const {
5957  return check(raw::dqcs_mset_contains(handle, qubit.get_index()));
5958  }
5959 
5972  std::vector<Measurement> drain_into_vector() {
5973  std::vector<Measurement> measurements;
5974  while (size()) {
5975  measurements.emplace_back(take_any());
5976  }
5977  return measurements;
5978  }
5979 
5992  std::vector<Measurement> copy_into_vector() {
5993  std::vector<Measurement> vector = drain_into_vector();
5995  free();
5996  handle = copy.take_handle();
5997  return vector;
5998  }
5999 
6013  }
6014 
6026  free();
6028  return *this;
6029  }
6030 
6035 
6040 
6041  };
6042 
6053  protected:
6054 
6060 
6065  }
6066 
6067  // Allow the C-style callbacks to construct the plugin state wrapper.
6068  friend class CallbackEntryPoints;
6069 
6070  public:
6071 
6072  // Delete the copy and move constructors and assignments.
6073  UpstreamPluginState(const UpstreamPluginState&) = delete;
6074  void operator=(const UpstreamPluginState&) = delete;
6076  UpstreamPluginState &operator=(UpstreamPluginState&&) = delete;
6077 
6085  double random_f64() noexcept {
6087  }
6088 
6094  uint64_t random_u64() noexcept {
6096  }
6097 
6107  template <typename T>
6108  T random() noexcept {
6109  uint64_t data[(sizeof(T) + 7) / 8];
6110  for (size_t i = 0; i < (sizeof(T) + 7) / 8; i++) {
6111  data = random_u64();
6112  }
6113  T retval;
6114  std::memcpy(&retval, data, sizeof(T));
6115  return retval;
6116  }
6117 
6118  };
6119 
6129  protected:
6130 
6135  }
6136 
6137  // Allow the C-style callbacks to construct the plugin state wrapper.
6138  friend class CallbackEntryPoints;
6139 
6140  public:
6141 
6142  // Delete the copy and move constructors and assignments.
6143  PluginState(const PluginState&) = delete;
6144  void operator=(const PluginState&) = delete;
6145  PluginState(PluginState&&) = delete;
6146  PluginState &operator=(PluginState&&) = delete;
6147 
6165  QubitSet allocate(size_t num_qubits, ArbCmdQueue &&cmds) {
6166  return QubitSet(check(raw::dqcs_plugin_allocate(state, num_qubits, cmds.get_handle())));
6167  }
6168 
6186  QubitSet allocate(size_t num_qubits, ArbCmdQueue &cmds) {
6187  return allocate(num_qubits, ArbCmdQueue(cmds));
6188  }
6189 
6203  QubitSet allocate(size_t num_qubits) {
6204  return QubitSet(check(raw::dqcs_plugin_allocate(state, num_qubits, 0)));
6205  }
6206 
6224  return allocate(1, std::move(cmds)).pop();
6225  }
6226 
6244  return allocate(ArbCmdQueue(cmds));
6245  }
6246 
6259  return allocate(1).pop();
6260  }
6261 
6274  void free(QubitSet &&qubits) {
6275  check(raw::dqcs_plugin_free(state, qubits.get_handle()));
6276  }
6277 
6290  void free(const QubitSet &qubits) {
6291  free(QubitSet(qubits));
6292  }
6293 
6305  void free(const QubitRef &qubit) {
6306  free(QubitSet().with(qubit));
6307  }
6308 
6321  void gate(Gate &&gate) {
6322  check(raw::dqcs_plugin_gate(state, gate.get_handle()));
6323  }
6324 
6337  void gate(const Matrix &matrix, const QubitRef &q) {
6338  if (matrix.size() == 2) {
6339  gate(Gate::unitary(QubitSet().with(q), matrix));
6340  } else {
6341  throw std::invalid_argument("matrix has incorrect size");
6342  }
6343  }
6344 
6361  void gate(const Matrix &matrix, const QubitRef &qa, const QubitRef &qb) {
6362  if (matrix.size() == 2) {
6363  gate(Gate::unitary(QubitSet().with(qb), QubitSet().with(qa), matrix));
6364  } else if (matrix.size() == 4) {
6365  gate(Gate::unitary(QubitSet().with(qa).with(qb), matrix));
6366  } else {
6367  throw std::invalid_argument("matrix has incorrect size");
6368  }
6369  }
6370 
6397  void gate(const Matrix &matrix, const QubitRef &qa, const QubitRef &qb, const QubitRef &qc) {
6398  if (matrix.size() == 2) {
6399  gate(Gate::unitary(QubitSet().with(qc), QubitSet().with(qa).with(qb), matrix));
6400  } else if (matrix.size() == 4) {
6401  gate(Gate::unitary(QubitSet().with(qb).with(qc), QubitSet().with(qa), matrix));
6402  } else if (matrix.size() == 8) {
6403  gate(Gate::unitary(QubitSet().with(qa).with(qb).with(qc), matrix));
6404  } else {
6405  throw std::invalid_argument("matrix has incorrect size");
6406  }
6407  }
6408 
6430  void measure_x(const QubitRef &q) {
6431  gate(Matrix(PredefinedGate::H), q);
6432  measure_z(q);
6433  gate(Matrix(PredefinedGate::H), q);
6434  }
6435 
6458  void measure_x(const QubitSet &qs) {
6459  auto qs_vec = qs.copy_into_vector();
6460  for (auto &q : qs_vec) gate(Matrix(PredefinedGate::H), q);
6461  measure_z(qs);
6462  for (auto &q : qs_vec) gate(Matrix(PredefinedGate::H), q);
6463  }
6464 
6487  void measure_y(const QubitRef &q) {
6488  gate(Matrix(PredefinedGate::S), q);
6489  gate(Matrix(PredefinedGate::Z), q);
6490  measure_x(q);
6491  gate(Matrix(PredefinedGate::S), q);
6492  }
6493 
6517  void measure_y(const QubitSet &qs) {
6518  auto qs_vec = qs.copy_into_vector();
6519  for (auto &q : qs_vec) gate(Matrix(PredefinedGate::S), q);
6520  for (auto &q : qs_vec) gate(Matrix(PredefinedGate::Z), q);
6521  measure_x(qs);
6522  for (auto &q : qs_vec) gate(Matrix(PredefinedGate::S), q);
6523  }
6524 
6537  void measure_z(const QubitRef &q) {
6538  measure_z(std::move(QubitSet().with(q)));
6539  }
6540 
6554  void measure_z(QubitSet &&qs) {
6555  gate(Gate::measure(std::move(qs)));
6556  }
6557 
6571  void measure_z(const QubitSet &qs) {
6572  measure_z(QubitSet(qs));
6573  }
6574 
6587  Cycle advance(Cycle cycles) {
6588  return check(raw::dqcs_plugin_advance(state, cycles));
6589  }
6590 
6599  ArbData arb(ArbCmd &&cmd) {
6600  return ArbData(check(raw::dqcs_plugin_arb(state, cmd.get_handle())));
6601  }
6602 
6611  ArbData arb(const ArbCmd &cmd) {
6612  return arb(ArbCmd(cmd));
6613  }
6614 
6626  }
6627 
6639  }
6640 
6653  }
6654 
6663  }
6664 
6665  };
6666 
6676  protected:
6677 
6682  }
6683 
6684  // Allow the C-style callbacks to construct the plugin state wrapper.
6685  friend class CallbackEntryPoints;
6686 
6687  public:
6688 
6689  // Delete the copy and move constructors and assignments.
6690  RunningPluginState(const RunningPluginState&) = delete;
6691  void operator=(const RunningPluginState&) = delete;
6693  RunningPluginState &operator=(RunningPluginState&&) = delete;
6694 
6706  void send(ArbData &&message) {
6707  check(raw::dqcs_plugin_send(state, message.get_handle()));
6708  }
6709 
6721  void send(const ArbData &message) {
6722  send(ArbData(message));
6723  }
6724 
6738  }
6739 
6740  };
6741 
6748  template <class R, class... Args>
6749  class Callback {
6750  private:
6751 
6756  template <class T, class S, class A>
6757  static std::function<S(A)> bind_first(S (*cb)(T, A), T user) {
6758  using namespace std::placeholders;
6759  return std::bind(cb, user, _1);
6760  }
6761 
6766  template <class T, class S, class A, class B>
6767  static std::function<S(A, B)> bind_first(S (*cb)(T, A, B), T user) {
6768  using namespace std::placeholders;
6769  return std::bind(cb, user, _1, _2);
6770  }
6771 
6776  template <class T, class S, class A, class B, class C>
6777  static std::function<S(A, B, C)> bind_first(S (*cb)(T, A, B, C), T user) {
6778  using namespace std::placeholders;
6779  return std::bind(cb, user, _1, _2, _3);
6780  }
6781 
6786  template <class T, class S, class A>
6787  static std::function<S(A)> bind_instance(T *instance, S (T::*cb)(A)) {
6788  using namespace std::placeholders;
6789  return std::bind(cb, instance, _1);
6790  }
6791 
6796  template <class T, class S, class A, class B>
6797  static std::function<S(A, B)> bind_instance(T *instance, S (T::*cb)(A, B)) {
6798  using namespace std::placeholders;
6799  return std::bind(cb, instance, _1, _2);
6800  }
6801 
6806  template <class T, class S, class A, class B, class C>
6807  static std::function<S(A, B, C)> bind_instance(T *instance, S (T::*cb)(A, B, C)) {
6808  using namespace std::placeholders;
6809  return std::bind(cb, instance, _1, _2, _3);
6810  }
6811 
6815  std::shared_ptr<std::function<R(Args...)>> cb;
6816 
6817  // Allow the C-style callbacks access to this class.
6818  friend class CallbackEntryPoints;
6819 
6820  public:
6821 
6827  Callback(R (*cb)(Args...)) noexcept
6828  : cb(std::make_shared<std::function<R(Args...)>>(cb))
6829  {}
6830 
6840  template <class T>
6841  Callback(R (*cb)(T, Args...), T user) noexcept
6842  : cb(std::make_shared<std::function<R(Args...)>>(bind_first<T, R, Args...>(cb, user)))
6843  {}
6844 
6852  template <class T>
6853  Callback(T *instance, R (T::*cb)(Args...)) noexcept
6854  : cb(std::make_shared<std::function<R(Args...)>>(bind_instance<T, R, Args...>(instance, cb)))
6855  {}
6856 
6862  Callback(std::function<R(Args...)> &&cb) noexcept
6863  : cb(std::make_shared<std::function<R(Args...)>>(std::move(cb)))
6864  {}
6865 
6871  Callback(const std::function<R(Args...)> &cb) noexcept
6872  : cb(std::make_shared<std::function<R(Args...)>>(cb))
6873  {}
6874 
6881  Callback(std::shared_ptr<std::function<R(Args...)>> &&cb) noexcept : cb(cb) {
6882  }
6883 
6890  Callback(const std::shared_ptr<std::function<R(Args...)>> &cb) noexcept : cb(cb) {
6891  }
6892 
6893  };
6894 
6899  namespace callback {
6900 
6905 
6910 
6915 
6920 
6925 
6930 
6935 
6940 
6945 
6950 
6974  typedef Callback<
6975  void,
6976  std::string&&, // message
6977  std::string&&, // logger
6978  Loglevel, // severity
6979  std::string&&, // module
6980  std::string&&, // file
6981  uint32_t, // line number
6982  std::chrono::system_clock::time_point&&, // timestamp
6983  uint32_t, // process ID
6984  uint64_t // thread ID
6985  > Log;
6986 
6987  } // namespace callback
6988 
6990 
6998  class CallbackEntryPoints {
6999  private:
7000  friend class Plugin;
7001  friend class SimulationConfiguration;
7002  friend class PluginConfigurationBuilder;
7003 
7007  static raw::dqcs_return_t initialize(
7008  void *user_data,
7010  raw::dqcs_handle_t init_cmds
7011  ) noexcept {
7012 
7013  // Wrap inputs.
7014  callback::Initialize *cb_wrapper = reinterpret_cast<callback::Initialize*>(user_data);
7015  PluginState state_wrapper(state);
7016  ArbCmdQueue init_cmds_wrapper(init_cmds);
7017 
7018  // Catch exceptions thrown in the user function to convert them to
7019  // DQCsim's error reporting protocol.
7020  try {
7021  (*(cb_wrapper->cb))(state_wrapper, std::move(init_cmds_wrapper));
7023  } catch (const std::exception &e) {
7024  raw::dqcs_error_set(e.what());
7025  }
7027  }
7028 
7032  static raw::dqcs_return_t drop(
7033  void *user_data,
7035  ) noexcept {
7036 
7037  // Wrap inputs.
7038  callback::Drop *cb_wrapper = reinterpret_cast<callback::Drop*>(user_data);
7039  PluginState state_wrapper(state);
7040 
7041  // Catch exceptions thrown in the user function to convert them to
7042  // DQCsim's error reporting protocol.
7043  try {
7044  (*(cb_wrapper->cb))(state_wrapper);
7046  } catch (const std::exception &e) {
7047  raw::dqcs_error_set(e.what());
7048  }
7050  }
7051 
7055  static raw::dqcs_handle_t run(
7056  void *user_data,
7058  raw::dqcs_handle_t args
7059  ) noexcept {
7060 
7061  // Wrap inputs.
7062  callback::Run *cb_wrapper = reinterpret_cast<callback::Run*>(user_data);
7063  RunningPluginState state_wrapper(state);
7064  ArbData args_wrapper(args);
7065 
7066  // Catch exceptions thrown in the user function to convert them to
7067  // DQCsim's error reporting protocol.
7068  try {
7069  return (*(cb_wrapper->cb))(state_wrapper, std::move(args_wrapper)).take_handle();
7070  } catch (const std::exception &e) {
7071  raw::dqcs_error_set(e.what());
7072  }
7073  return 0;
7074  }
7075 
7079  static raw::dqcs_return_t allocate(
7080  void *user_data,
7082  raw::dqcs_handle_t qubits,
7083  raw::dqcs_handle_t alloc_cmds
7084  ) noexcept {
7085 
7086  // Wrap inputs.
7087  callback::Allocate *cb_wrapper = reinterpret_cast<callback::Allocate*>(user_data);
7088  PluginState state_wrapper(state);
7089  QubitSet qubits_wrapper(qubits);
7090  ArbCmdQueue alloc_cmds_wrapper(alloc_cmds);
7091 
7092  // Catch exceptions thrown in the user function to convert them to
7093  // DQCsim's error reporting protocol.
7094  try {
7095  (*(cb_wrapper->cb))(state_wrapper, std::move(qubits_wrapper), std::move(alloc_cmds_wrapper));
7097  } catch (const std::exception &e) {
7098  raw::dqcs_error_set(e.what());
7099  }
7101  }
7102 
7106  static raw::dqcs_return_t free(
7107  void *user_data,
7109  raw::dqcs_handle_t qubits
7110  ) noexcept {
7111 
7112  // Wrap inputs.
7113  callback::Free *cb_wrapper = reinterpret_cast<callback::Free*>(user_data);
7114  PluginState state_wrapper(state);
7115  QubitSet qubits_wrapper(qubits);
7116 
7117  // Catch exceptions thrown in the user function to convert them to
7118  // DQCsim's error reporting protocol.
7119  try {
7120  (*(cb_wrapper->cb))(state_wrapper, std::move(qubits_wrapper));
7122  } catch (const std::exception &e) {
7123  raw::dqcs_error_set(e.what());
7124  }
7126  }
7127 
7131  static raw::dqcs_handle_t gate(
7132  void *user_data,
7134  raw::dqcs_handle_t gate
7135  ) noexcept {
7136 
7137  // Wrap inputs.
7138  callback::Gate *cb_wrapper = reinterpret_cast<callback::Gate*>(user_data);
7139  PluginState state_wrapper(state);
7140  Gate gate_wrapper(gate);
7141 
7142  // Catch exceptions thrown in the user function to convert them to
7143  // DQCsim's error reporting protocol.
7144  try {
7145  return (*(cb_wrapper->cb))(state_wrapper, std::move(gate_wrapper)).take_handle();
7146  } catch (const std::exception &e) {
7147  raw::dqcs_error_set(e.what());
7148  }
7149  return 0;
7150  }
7151 
7155  static raw::dqcs_handle_t modify_measurement(
7156  void *user_data,
7158  raw::dqcs_handle_t meas
7159  ) noexcept {
7160 
7161  // Wrap inputs.
7162  callback::ModifyMeasurement *cb_wrapper = reinterpret_cast<callback::ModifyMeasurement*>(user_data);
7163  UpstreamPluginState state_wrapper(state);
7164  Measurement meas_wrapper(meas);
7165 
7166  // Catch exceptions thrown in the user function to convert them to
7167  // DQCsim's error reporting protocol.
7168  try {
7169  return (*(cb_wrapper->cb))(state_wrapper, std::move(meas_wrapper)).take_handle();
7170  } catch (const std::exception &e) {
7171  raw::dqcs_error_set(e.what());
7172  }
7173  return 0;
7174  }
7175 
7179  static raw::dqcs_return_t advance(
7180  void *user_data,
7182  Cycle cycles
7183  ) noexcept {
7184 
7185  // Wrap inputs.
7186  callback::Advance *cb_wrapper = reinterpret_cast<callback::Advance*>(user_data);
7187  PluginState state_wrapper(state);
7188 
7189  // Catch exceptions thrown in the user function to convert them to
7190  // DQCsim's error reporting protocol.
7191  try {
7192  (*(cb_wrapper->cb))(state_wrapper, cycles);
7194  } catch (const std::exception &e) {
7195  raw::dqcs_error_set(e.what());
7196  }
7198  }
7199 
7203  static raw::dqcs_handle_t upstream_arb(
7204  void *user_data,
7206  raw::dqcs_handle_t cmd
7207  ) noexcept {
7208 
7209  // Wrap inputs.
7210  callback::Arb *cb_wrapper = reinterpret_cast<callback::Arb*>(user_data);
7211  PluginState state_wrapper(state);
7212  ArbCmd cmd_wrapper(cmd);
7213 
7214  // Catch exceptions thrown in the user function to convert them to
7215  // DQCsim's error reporting protocol.
7216  try {
7217  return (*(cb_wrapper->cb))(state_wrapper, std::move(cmd_wrapper)).take_handle();
7218  } catch (const std::exception &e) {
7219  raw::dqcs_error_set(e.what());
7220  }
7221  return 0;
7222  }
7223 
7227  static raw::dqcs_handle_t host_arb(
7228  void *user_data,
7230  raw::dqcs_handle_t cmd
7231  ) noexcept {
7232 
7233  // Wrap inputs.
7234  callback::Arb *cb_wrapper = reinterpret_cast<callback::Arb*>(user_data);
7235  PluginState state_wrapper(state);
7236  ArbCmd cmd_wrapper(cmd);
7237 
7238  // Catch exceptions thrown in the user function to convert them to
7239  // DQCsim's error reporting protocol.
7240  try {
7241  return (*(cb_wrapper->cb))(state_wrapper, std::move(cmd_wrapper)).take_handle();
7242  } catch (const std::exception &e) {
7243  raw::dqcs_error_set(e.what());
7244  }
7245  return 0;
7246  }
7247 
7251  static void spawn_plugin(
7252  void *user_data,
7253  const char *simulator
7254  ) noexcept {
7255 
7256  // Wrap inputs.
7257  callback::SpawnPlugin *cb_wrapper = reinterpret_cast<callback::SpawnPlugin*>(user_data);
7258  std::string simulator_wrapper(simulator);
7259 
7260  // Catch exceptions thrown in the user function to convert them to
7261  // DQCsim's error reporting protocol.
7262  try {
7263  (*(cb_wrapper->cb))(std::move(simulator_wrapper));
7264  } catch (const std::exception &e) {
7265  DQCSIM_FATAL("DQCsim caught std::exception in plugin thread: %s", e.what());
7266  }
7267  }
7268 
7272  static void log(
7273  void *user_data,
7274  const char *message,
7275  const char *logger,
7276  raw::dqcs_loglevel_t level,
7277  const char *module,
7278  const char *file,
7279  uint32_t line,
7280  uint64_t time_s,
7281  uint32_t time_ns,
7282  uint32_t pid,
7283  uint64_t tid
7284  ) noexcept {
7285 
7286  // Wrap inputs.
7287  callback::Log *cb_wrapper = reinterpret_cast<callback::Log*>(user_data);
7288 
7289  // Catch exceptions thrown in the user function to convert them to
7290  // DQCsim's error reporting protocol.
7291  try {
7292  (*(cb_wrapper->cb))(
7293  std::string(message ? message : ""),
7294  std::string(logger ? logger : ""),
7295  check(level),
7296  std::string(module ? module : ""),
7297  std::string(file ? file : ""),
7298  line,
7299  std::chrono::system_clock::time_point(
7300  std::chrono::duration_cast<std::chrono::microseconds>(
7301  std::chrono::seconds(time_s)
7302  + std::chrono::nanoseconds(time_ns)
7303  )
7304  ),
7305  pid,
7306  tid
7307  );
7308  } catch (const std::exception &e) {
7309  std::cerr << "DQCsim caught std::exception in log callback: " << e.what() << std::endl;
7310  }
7311  }
7312 
7316  template <class T>
7317  static void user_free(void *user_data) noexcept {
7318  T *cb_wrapper = reinterpret_cast<T*>(user_data);
7319  delete cb_wrapper;
7320  }
7321 
7322  };
7324 
7333  class PluginJoinHandle : public Handle {
7334  public:
7335 
7344  PluginJoinHandle(HandleIndex handle) noexcept : Handle(handle) {
7345  }
7346 
7347  // Delete copy construct/assign.
7348  PluginJoinHandle(const PluginJoinHandle&) = delete;
7349  void operator=(const PluginJoinHandle&) = delete;
7350 
7355 
7360 
7366  void wait() {
7367  if (handle) {
7368  check(raw::dqcs_plugin_wait(handle));
7369  take_handle();
7370  }
7371  }
7372 
7373  };
7374 
7594  class Plugin : public Handle {
7595  public:
7596 
7605  Plugin(HandleIndex handle) noexcept : Handle(handle) {
7606  }
7607 
7620  PluginType type,
7621  const std::string &name,
7622  const std::string &author,
7623  const std::string &version
7624  ) : Handle(raw::dqcs_pdef_new(
7625  to_raw(type), name.c_str(), author.c_str(), version.c_str()
7626  )) {
7627  }
7628 
7641  const std::string &name,
7642  const std::string &author,
7643  const std::string &version
7644  ) {
7645  return Plugin(PluginType::Frontend, name, author, version);
7646  }
7647 
7660  const std::string &name,
7661  const std::string &author,
7662  const std::string &version
7663  ) {
7664  return Plugin(PluginType::Operator, name, author, version);
7665  }
7666 
7678  static Plugin Backend(
7679  const std::string &name,
7680  const std::string &author,
7681  const std::string &version
7682  ) {
7683  return Plugin(PluginType::Backend, name, author, version);
7684  }
7685 
7686  // Delete copy construct/assign.
7687  Plugin(const Plugin&) = delete;
7688  void operator=(const Plugin&) = delete;
7689 
7693  Plugin(Plugin&&) = default;
7694 
7698  Plugin &operator=(Plugin&&) = default;
7699 
7707  return check(raw::dqcs_pdef_type(handle));
7708  }
7709 
7716  std::string get_name() const {
7717  char *cstr = check(raw::dqcs_pdef_name(handle));
7718  std::string str(cstr);
7719  std::free(cstr);
7720  return str;
7721  }
7722 
7729  std::string get_author() const {
7730  char *cstr = check(raw::dqcs_pdef_author(handle));
7731  std::string str(cstr);
7732  std::free(cstr);
7733  return str;
7734  }
7735 
7742  std::string get_version() const {
7743  char *cstr = check(raw::dqcs_pdef_version(handle));
7744  std::string str(cstr);
7745  std::free(cstr);
7746  return str;
7747  }
7748 
7749  // Code below is generated using the following Python script:
7750  // print(' // Code below is generated using the following Python script:')
7751  // with open(__file__, 'r') as f:
7752  // print(''.join(map(lambda x: ' // ' + x, f.readlines())), end='')
7753  //
7754  // template = """
7755  // private:
7756  //
7757  // /**
7758  // * Assigns the {0[0]} callback function from a `new`-initialized
7759  // * raw pointer to a `callback::{0[2]}` object. Callee will ensure that
7760  // * `delete` is called.
7761  // */
7762  // void set_{0[1]}(callback::{0[2]} *cb) {{
7763  // try {{
7764  // check(raw::dqcs_pdef_set_{0[1]}_cb(
7765  // handle,
7766  // CallbackEntryPoints::{0[1]},
7767  // CallbackEntryPoints::user_free<callback::{0[2]}>,
7768  // cb));
7769  // }} catch (...) {{
7770  // delete cb;
7771  // throw;
7772  // }}
7773  // }}
7774  //
7775  // public:
7776  //
7777  // /**
7778  // * Assigns the {0[0]} callback function from a pre-existing
7779  // * `callback::{0[2]}` object by copy.
7780  // *
7781  // * \\param cb The callback object.
7782  // * \\returns `&self`, to continue building.
7783  // * \\throws std::runtime_error When the current handle is invalid or of an
7784  // * unsupported plugin type, or when the callback object is invalid.
7785  // */
7786  // Plugin &&with_{0[1]}(const callback::{0[2]} &cb) {{
7787  // set_{0[1]}(new callback::{0[2]}(cb));
7788  // return std::move(*this);
7789  // }}
7790  //
7791  // /**
7792  // * Assigns the {0[0]} callback function from a pre-existing
7793  // * `callback::{0[2]}` object by move.
7794  // *
7795  // * \\param cb The callback object.
7796  // * \\returns `&self`, to continue building.
7797  // * \\throws std::runtime_error When the current handle is invalid or of an
7798  // * unsupported plugin type, or when the callback object is invalid.
7799  // */
7800  // Plugin &&with_{0[1]}(callback::{0[2]} &&cb) {{
7801  // set_{0[1]}(new callback::{0[2]}(std::move(cb)));
7802  // return std::move(*this);
7803  // }}
7804  //
7805  // /**
7806  // * Assigns the {0[0]} callback function by constructing the
7807  // * callback object implicitly.
7808  // *
7809  // * \\returns `&self`, to continue building.
7810  // * \\throws std::runtime_error When the current handle is invalid or of an
7811  // * unsupported plugin type, or when the callback object is invalid.
7812  // */
7813  // template<typename... Args>
7814  // Plugin &&with_{0[1]}(Args... args) {{
7815  // set_{0[1]}(new callback::{0[2]}(args...));
7816  // return std::move(*this);
7817  // }}
7818  // """
7819  //
7820  // print(''.join(map(template.format, [
7821  // ('initialize', 'initialize', 'Initialize'),
7822  // ('drop', 'drop', 'Drop'),
7823  // ('run', 'run', 'Run'),
7824  // ('allocate', 'allocate', 'Allocate'),
7825  // ('free', 'free', 'Free'),
7826  // ('gate', 'gate', 'Gate'),
7827  // ('modify-measurement', 'modify_measurement', 'ModifyMeasurement'),
7828  // ('advance', 'advance', 'Advance'),
7829  // ('upstream-arb', 'upstream_arb', 'Arb'),
7830  // ('host-arb', 'host_arb', 'Arb'),
7831  // ])))
7832  //
7833  // print(' // End of generated code.')
7834 
7835  private:
7836 
7842  void set_initialize(callback::Initialize *cb) {
7843  try {
7845  handle,
7846  CallbackEntryPoints::initialize,
7847  CallbackEntryPoints::user_free<callback::Initialize>,
7848  cb));
7849  } catch (...) {
7850  delete cb;
7851  throw;
7852  }
7853  }
7854 
7855  public:
7856 
7867  set_initialize(new callback::Initialize(cb));
7868  return std::move(*this);
7869  }
7870 
7881  set_initialize(new callback::Initialize(std::move(cb)));
7882  return std::move(*this);
7883  }
7884 
7893  template<typename... Args>
7894  Plugin &&with_initialize(Args... args) {
7895  set_initialize(new callback::Initialize(args...));
7896  return std::move(*this);
7897  }
7898 
7899  private:
7900 
7906  void set_drop(callback::Drop *cb) {
7907  try {
7909  handle,
7910  CallbackEntryPoints::drop,
7911  CallbackEntryPoints::user_free<callback::Drop>,
7912  cb));
7913  } catch (...) {
7914  delete cb;
7915  throw;
7916  }
7917  }
7918 
7919  public:
7920 
7931  set_drop(new callback::Drop(cb));
7932  return std::move(*this);
7933  }
7934 
7945  set_drop(new callback::Drop(std::move(cb)));
7946  return std::move(*this);
7947  }
7948 
7957  template<typename... Args>
7958  Plugin &&with_drop(Args... args) {
7959  set_drop(new callback::Drop(args...));
7960  return std::move(*this);
7961  }
7962 
7963  private:
7964 
7970  void set_run(callback::Run *cb) {
7971  try {
7973  handle,
7974  CallbackEntryPoints::run,
7975  CallbackEntryPoints::user_free<callback::Run>,
7976  cb));
7977  } catch (...) {
7978  delete cb;
7979  throw;
7980  }
7981  }
7982 
7983  public:
7984 
7995  set_run(new callback::Run(cb));
7996  return std::move(*this);
7997  }
7998 
8009  set_run(new callback::Run(std::move(cb)));
8010  return std::move(*this);
8011  }
8012 
8021  template<typename... Args>
8022  Plugin &&with_run(Args... args) {
8023  set_run(new callback::Run(args...));
8024  return std::move(*this);
8025  }
8026 
8027  private:
8028 
8034  void set_allocate(callback::Allocate *cb) {
8035  try {
8037  handle,
8038  CallbackEntryPoints::allocate,
8039  CallbackEntryPoints::user_free<callback::Allocate>,
8040  cb));
8041  } catch (...) {
8042  delete cb;
8043  throw;
8044  }
8045  }
8046 
8047  public:
8048 
8059  set_allocate(new callback::Allocate(cb));
8060  return std::move(*this);
8061  }
8062 
8073  set_allocate(new callback::Allocate(std::move(cb)));
8074  return std::move(*this);
8075  }
8076 
8085  template<typename... Args>
8086  Plugin &&with_allocate(Args... args) {
8087  set_allocate(new callback::Allocate(args...));
8088  return std::move(*this);
8089  }
8090 
8091  private:
8092 
8098  void set_free(callback::Free *cb) {
8099  try {
8101  handle,
8102  CallbackEntryPoints::free,
8103  CallbackEntryPoints::user_free<callback::Free>,
8104  cb));
8105  } catch (...) {
8106  delete cb;
8107  throw;
8108  }
8109  }
8110 
8111  public:
8112 
8123  set_free(new callback::Free(cb));
8124  return std::move(*this);
8125  }
8126 
8137  set_free(new callback::Free(std::move(cb)));
8138  return std::move(*this);
8139  }
8140 
8149  template<typename... Args>
8150  Plugin &&with_free(Args... args) {
8151  set_free(new callback::Free(args...));
8152  return std::move(*this);
8153  }
8154 
8155  private:
8156 
8162  void set_gate(callback::Gate *cb) {
8163  try {
8165  handle,
8166  CallbackEntryPoints::gate,
8167  CallbackEntryPoints::user_free<callback::Gate>,
8168  cb));
8169  } catch (...) {
8170  delete cb;
8171  throw;
8172  }
8173  }
8174 
8175  public:
8176 
8187  set_gate(new callback::Gate(cb));
8188  return std::move(*this);
8189  }
8190 
8201  set_gate(new callback::Gate(std::move(cb)));
8202  return std::move(*this);
8203  }
8204 
8213  template<typename... Args>
8214  Plugin &&with_gate(Args... args) {
8215  set_gate(new callback::Gate(args...));
8216  return std::move(*this);
8217  }
8218 
8219  private:
8220 
8226  void set_modify_measurement(callback::ModifyMeasurement *cb) {
8227  try {
8229  handle,
8230  CallbackEntryPoints::modify_measurement,
8231  CallbackEntryPoints::user_free<callback::ModifyMeasurement>,
8232  cb));
8233  } catch (...) {
8234  delete cb;
8235  throw;
8236  }
8237  }
8238 
8239  public:
8240 
8251  set_modify_measurement(new callback::ModifyMeasurement(cb));
8252  return std::move(*this);
8253  }
8254 
8265  set_modify_measurement(new callback::ModifyMeasurement(std::move(cb)));
8266  return std::move(*this);
8267  }
8268 
8277  template<typename... Args>
8279  set_modify_measurement(new callback::ModifyMeasurement(args...));
8280  return std::move(*this);
8281  }
8282 
8283  private:
8284 
8290  void set_advance(callback::Advance *cb) {
8291  try {
8293  handle,
8294  CallbackEntryPoints::advance,
8295  CallbackEntryPoints::user_free<callback::Advance>,
8296  cb));
8297  } catch (...) {
8298  delete cb;
8299  throw;
8300  }
8301  }
8302 
8303  public:
8304 
8315  set_advance(new callback::Advance(cb));
8316  return std::move(*this);
8317  }
8318 
8329  set_advance(new callback::Advance(std::move(cb)));
8330  return std::move(*this);
8331  }
8332 
8341  template<typename... Args>
8342  Plugin &&with_advance(Args... args) {
8343  set_advance(new callback::Advance(args...));
8344  return std::move(*this);
8345  }
8346 
8347  private:
8348 
8354  void set_upstream_arb(callback::Arb *cb) {
8355  try {
8357  handle,
8358  CallbackEntryPoints::upstream_arb,
8359  CallbackEntryPoints::user_free<callback::Arb>,
8360  cb));
8361  } catch (...) {
8362  delete cb;
8363  throw;
8364  }
8365  }
8366 
8367  public:
8368 
8379  set_upstream_arb(new callback::Arb(cb));
8380  return std::move(*this);
8381  }
8382 
8393  set_upstream_arb(new callback::Arb(std::move(cb)));
8394  return std::move(*this);
8395  }
8396 
8405  template<typename... Args>
8406  Plugin &&with_upstream_arb(Args... args) {
8407  set_upstream_arb(new callback::Arb(args...));
8408  return std::move(*this);
8409  }
8410 
8411  private:
8412 
8418  void set_host_arb(callback::Arb *cb) {
8419  try {
8421  handle,
8422  CallbackEntryPoints::host_arb,
8423  CallbackEntryPoints::user_free<callback::Arb>,
8424  cb));
8425  } catch (...) {
8426  delete cb;
8427  throw;
8428  }
8429  }
8430 
8431  public:
8432 
8443  set_host_arb(new callback::Arb(cb));
8444  return std::move(*this);
8445  }
8446 
8457  set_host_arb(new callback::Arb(std::move(cb)));
8458  return std::move(*this);
8459  }
8460 
8469  template<typename... Args>
8470  Plugin &&with_host_arb(Args... args) {
8471  set_host_arb(new callback::Arb(args...));
8472  return std::move(*this);
8473  }
8474 
8475  // End of generated code.
8476 
8487  void run(const char *simulator) {
8488  check(raw::dqcs_plugin_run(handle, simulator));
8489  take_handle();
8490  }
8491 
8503  int run(int argc, char *argv[]) noexcept {
8504  if (argc != 2) {
8505  DQCSIM_FATAL("Expecting exactly one command-line argument, but got %d", argc);
8506  return 1;
8507  }
8508  try {
8509  run(argv[1]);
8510  } catch (const std::exception &e) {
8511  DQCSIM_FATAL("Returning failure because of the following: %s", e.what());
8512  return 1;
8513  } catch (...) {
8514  DQCSIM_FATAL("Returning failure because of an unknown exception");
8515  return 1;
8516  }
8517  return 0;
8518  }
8519 
8531  PluginJoinHandle start(const char *simulator) {
8532  PluginJoinHandle join_handle(check(raw::dqcs_plugin_start(handle, simulator)));
8533  take_handle();
8534  return join_handle;
8535  }
8536 
8537  };
8538 
8542  class PluginConfiguration : public Handle {
8543  public:
8544 
8553  PluginConfiguration(HandleIndex handle) noexcept : Handle(handle) {
8554  }
8555 
8556  // Delete copy construct/assign.
8557  PluginConfiguration(const PluginConfiguration&) = delete;
8558  void operator=(const PluginConfiguration&) = delete;
8559 
8564 
8569 
8576  virtual PluginType get_plugin_type() const = 0;
8577 
8587  virtual std::string get_name() const = 0;
8588 
8596  virtual void add_init_cmd(ArbCmd &&cmd) = 0;
8597 
8605  void add_init_cmd(const ArbCmd &cmd) {
8606  add_init_cmd(ArbCmd(cmd));
8607  }
8608 
8615  virtual void set_verbosity(Loglevel level) = 0;
8616 
8623  virtual Loglevel get_verbosity() const = 0;
8624 
8633  virtual void log_tee(Loglevel verbosity, const std::string &filename) = 0;
8634 
8635  };
8636 
8641  public:
8642 
8652  }
8653 
8654  // Delete copy construct/assign.
8656  void operator=(const PluginProcessConfiguration&) = delete;
8657 
8662 
8667 
8674  PluginType get_plugin_type() const override {
8675  return check(raw::dqcs_pcfg_type(handle));
8676  }
8677 
8687  std::string get_name() const override {
8688  char *ptr = check(raw::dqcs_pcfg_name(handle));
8689  std::string retval(ptr);
8690  std::free(ptr);
8691  return retval;
8692  }
8693 
8700  std::string get_executable() const {
8701  char *ptr = check(raw::dqcs_pcfg_executable(handle));
8702  std::string retval(ptr);
8703  std::free(ptr);
8704  return retval;
8705  }
8706 
8713  std::string get_script() const {
8714  char *ptr = check(raw::dqcs_pcfg_script(handle));
8715  std::string retval(ptr);
8716  std::free(ptr);
8717  return retval;
8718  }
8719 
8727  void add_init_cmd(ArbCmd &&cmd) override {
8728  check(raw::dqcs_pcfg_init_cmd(handle, cmd.get_handle()));
8729  }
8730 
8741  add_init_cmd(std::move(cmd));
8742  return std::move(*this);
8743  }
8744 
8756  void set_env_var(const std::string &key, const std::string &value) {
8757  check(raw::dqcs_pcfg_env_set(handle, key.c_str(), value.c_str()));
8758  }
8759 
8773  PluginProcessConfiguration &&with_env_var(const std::string &key, const std::string &value) {
8774  set_env_var(key, value);
8775  return std::move(*this);
8776  }
8777 
8788  void unset_env_var(const std::string &key) {
8789  check(raw::dqcs_pcfg_env_unset(handle, key.c_str()));
8790  }
8791 
8804  PluginProcessConfiguration &&without_env_var(const std::string &key) {
8805  unset_env_var(key);
8806  return std::move(*this);
8807  }
8808 
8816  void set_work_dir(const std::string &dir) {
8817  check(raw::dqcs_pcfg_work_set(handle, dir.c_str()));
8818  }
8819 
8829  PluginProcessConfiguration &&with_work_dir(const std::string &dir) {
8830  set_work_dir(dir);
8831  return std::move(*this);
8832  }
8833 
8841  std::string get_work_dir() const {
8842  char *ptr = check(raw::dqcs_pcfg_work_get(handle));
8843  std::string retval(ptr);
8844  std::free(ptr);
8845  return retval;
8846  }
8847 
8854  void set_verbosity(Loglevel level) override {
8855  check(raw::dqcs_pcfg_verbosity_set(handle, to_raw(level)));
8856  }
8857 
8866  set_verbosity(level);
8867  return std::move(*this);
8868  }
8869 
8876  Loglevel get_verbosity() const override {
8877  return check(raw::dqcs_pcfg_verbosity_get(handle));
8878  }
8879 
8888  void log_tee(Loglevel verbosity, const std::string &filename) override {
8889  return check(raw::dqcs_pcfg_tee(handle, to_raw(verbosity), filename.c_str()));
8890  }
8891 
8902  PluginProcessConfiguration &&with_log_tee(Loglevel verbosity, const std::string &filename) {
8903  log_tee(verbosity, filename);
8904  return std::move(*this);
8905  }
8906 
8917  check(raw::dqcs_pcfg_stdout_mode_set(handle, to_raw(level)));
8918  }
8919 
8931  set_stdout_loglevel(level);
8932  return std::move(*this);
8933  }
8934 
8943  return check(raw::dqcs_pcfg_stdout_mode_get(handle));
8944  }
8945 
8956  check(raw::dqcs_pcfg_stderr_mode_set(handle, to_raw(level)));
8957  }
8958 
8970  set_stderr_loglevel(level);
8971  return std::move(*this);
8972  }
8973 
8982  return check(raw::dqcs_pcfg_stderr_mode_get(handle));
8983  }
8984 
8995  void set_accept_timeout(double timeout) {
8996  check(raw::dqcs_pcfg_accept_timeout_set(handle, timeout));
8997  }
8998 
9012  set_accept_timeout(timeout);
9013  return std::move(*this);
9014  }
9015 
9024  set_accept_timeout(std::numeric_limits<double>::infinity());
9025  return std::move(*this);
9026  }
9027 
9035  double get_accept_timeout() const {
9036  return check(raw::dqcs_pcfg_accept_timeout_get(handle));
9037  }
9038 
9049  void set_shutdown_timeout(double timeout) {
9050  check(raw::dqcs_pcfg_shutdown_timeout_set(handle, timeout));
9051  }
9052 
9066  set_shutdown_timeout(timeout);
9067  return std::move(*this);
9068  }
9069 
9078  set_shutdown_timeout(std::numeric_limits<double>::infinity());
9079  return std::move(*this);
9080  }
9081 
9089  double get_shutdown_timeout() const {
9091  }
9092 
9093  };
9094 
9099  public:
9100 
9110  }
9111 
9112  // Delete copy construct/assign.
9114  void operator=(const PluginThreadConfiguration&) = delete;
9115 
9120 
9125 
9132  PluginType get_plugin_type() const override {
9133  return check(raw::dqcs_tcfg_type(handle));
9134  }
9135 
9145  std::string get_name() const override {
9146  char *ptr = check(raw::dqcs_tcfg_name(handle));
9147  std::string retval(ptr);
9148  std::free(ptr);
9149  return retval;
9150  }
9151 
9159  void add_init_cmd(ArbCmd &&cmd) override {
9160  check(raw::dqcs_tcfg_init_cmd(handle, cmd.get_handle()));
9161  }
9162 
9173  add_init_cmd(std::move(cmd));
9174  return std::move(*this);
9175  }
9176 
9183  void set_verbosity(Loglevel level) override {
9184  check(raw::dqcs_tcfg_verbosity_set(handle, to_raw(level)));
9185  }
9186 
9195  set_verbosity(level);
9196  return std::move(*this);
9197  }
9198 
9205  Loglevel get_verbosity() const override {
9206  return check(raw::dqcs_tcfg_verbosity_get(handle));
9207  }
9208 
9217  void log_tee(Loglevel verbosity, const std::string &filename) override {
9218  return check(raw::dqcs_tcfg_tee(handle, to_raw(verbosity), filename.c_str()));
9219  }
9220 
9231  PluginThreadConfiguration &&with_log_tee(Loglevel verbosity, const std::string &filename) {
9232  log_tee(verbosity, filename);
9233  return std::move(*this);
9234  }
9235 
9236  };
9237 
9242  private:
9243  PluginType type;
9244  std::string name;
9245  public:
9246 
9256  PluginConfigurationBuilder(PluginType type) noexcept : type(type), name() {}
9257 
9272  PluginConfigurationBuilder &&with_name(const std::string &name) noexcept {
9273  this->name = name;
9274  return std::move(*this);
9275  }
9276 
9288  PluginProcessConfiguration with_spec(const std::string &spec) {
9290  to_raw(type), name.c_str(), spec.c_str()
9291  )));
9292  }
9293 
9307  PluginProcessConfiguration with_executable(const std::string &executable, const std::string &script = "") {
9309  to_raw(type), name.c_str(), executable.c_str(), script.c_str()
9310  )));
9311  }
9312 
9324  if (plugin.get_type() != type) {
9325  throw std::invalid_argument("plugin type does not match callback object type");
9326  }
9328  plugin.get_handle(), name.c_str()
9329  )));
9330  }
9331 
9332  private:
9333 
9349  PluginThreadConfiguration with_spawner_ptr(callback::SpawnPlugin *data) {
9351  to_raw(type),
9352  name.c_str(),
9353  CallbackEntryPoints::spawn_plugin,
9354  CallbackEntryPoints::user_free<callback::SpawnPlugin>,
9355  data
9356  )));
9357  }
9358 
9359  public:
9360 
9377  return with_spawner_ptr(new callback::SpawnPlugin(data));
9378  }
9379 
9396  return with_spawner_ptr(new callback::SpawnPlugin(std::move(data)));
9397  }
9398 
9415  template<typename... Args>
9417  return with_spawner_ptr(new callback::SpawnPlugin(args...));
9418  }
9419 
9420  };
9421 
9430  inline PluginConfigurationBuilder Frontend(const std::string &name = "") noexcept {
9432  }
9433 
9442  inline PluginConfigurationBuilder Operator(const std::string &name = "") noexcept {
9444  }
9445 
9454  inline PluginConfigurationBuilder Backend(const std::string &name = "") noexcept {
9456  }
9457 
9461  class Simulation : public Handle {
9462  public:
9463 
9472  Simulation(HandleIndex handle) noexcept : Handle(handle) {
9473  }
9474 
9475  // Delete copy construct/assign.
9476  Simulation(const Simulation&) = delete;
9477  void operator=(const Simulation&) = delete;
9478 
9482  Simulation(Simulation&&) = default;
9483 
9488 
9499  void start() {
9500  check(raw::dqcs_sim_start(handle, 0));
9501  }
9502 
9515  void start(ArbData &&data) {
9516  check(raw::dqcs_sim_start(handle, data.get_handle()));
9517  }
9518 
9531  void start(const ArbData &data) {
9532  start(ArbData(data));
9533  }
9534 
9545  return ArbData(check(raw::dqcs_sim_wait(handle)));
9546  }
9547 
9560  start();
9561  return wait();
9562  }
9563 
9577  ArbData run(ArbData &&data) {
9578  start(std::move(data));
9579  return wait();
9580  }
9581 
9595  ArbData run(const ArbData &data) {
9596  start(data);
9597  return wait();
9598  }
9599 
9608  void send() {
9609  check(raw::dqcs_sim_send(handle, 0));
9610  }
9611 
9622  void send(ArbData &&data) {
9623  check(raw::dqcs_sim_send(handle, data.get_handle()));
9624  }
9625 
9636  void send(const ArbData &data) {
9637  send(ArbData(data));
9638  }
9639 
9648  return ArbData(check(raw::dqcs_sim_recv(handle)));
9649  }
9650 
9664  void yield() {
9665  check(raw::dqcs_sim_yield(handle));
9666  }
9667 
9682  ArbData arb(const std::string &name, ArbCmd &&cmd) {
9683  return ArbData(check(raw::dqcs_sim_arb(handle, name.c_str(), cmd.get_handle())));
9684  }
9685 
9700  ArbData arb(const std::string &name, const ArbCmd &cmd) {
9701  return arb(name, ArbCmd(cmd));
9702  }
9703 
9722  ArbData arb(ssize_t index, ArbCmd &&cmd) {
9723  return ArbData(check(raw::dqcs_sim_arb_idx(handle, index, cmd.get_handle())));
9724  }
9725 
9744  ArbData arb(ssize_t index, const ArbCmd &cmd) {
9745  return arb(index, ArbCmd(cmd));
9746  }
9747 
9756  std::string get_name(const std::string &name) {
9757  char *ptr = check(raw::dqcs_sim_get_name(handle, name.c_str()));
9758  std::string str(ptr);
9759  std::free(ptr);
9760  return str;
9761  }
9762 
9775  std::string get_name(ssize_t index) {
9776  char *ptr = check(raw::dqcs_sim_get_name_idx(handle, index));
9777  std::string str(ptr);
9778  std::free(ptr);
9779  return str;
9780  }
9781 
9790  std::string get_author(const std::string &name) {
9791  char *ptr = check(raw::dqcs_sim_get_author(handle, name.c_str()));
9792  std::string str(ptr);
9793  std::free(ptr);
9794  return str;
9795  }
9796 
9809  std::string get_author(ssize_t index) {
9810  char *ptr = check(raw::dqcs_sim_get_author_idx(handle, index));
9811  std::string str(ptr);
9812  std::free(ptr);
9813  return str;
9814  }
9815 
9824  std::string get_version(const std::string &name) {
9825  char *ptr = check(raw::dqcs_sim_get_version(handle, name.c_str()));
9826  std::string str(ptr);
9827  std::free(ptr);
9828  return str;
9829  }
9830 
9843  std::string get_version(ssize_t index) {
9844  char *ptr = check(raw::dqcs_sim_get_version_idx(handle, index));
9845  std::string str(ptr);
9846  std::free(ptr);
9847  return str;
9848  }
9849 
9857  void write_reproduction_file(const std::string &filename) {
9858  check(raw::dqcs_sim_write_reproduction_file(handle, filename.c_str()));
9859  }
9860 
9861  };
9862 
9867  public:
9868 
9877  SimulationConfiguration(HandleIndex handle) noexcept : Handle(handle) {
9878  }
9879 
9884  }
9885 
9886  // Delete copy construct/assign.
9888  void operator=(const SimulationConfiguration&) = delete;
9889 
9894 
9899 
9921  check(raw::dqcs_scfg_push_plugin(handle, plugin.get_handle()));
9922  }
9923 
9936  add_plugin(std::move(plugin));
9937  return std::move(*this);
9938  }
9939 
9949  void set_seed(uint64_t seed) {
9950  check(raw::dqcs_scfg_seed_set(handle, seed));
9951  }
9952 
9965  set_seed(seed);
9966  return std::move(*this);
9967  }
9968 
9978  uint64_t get_seed() const noexcept {
9979  return raw::dqcs_scfg_seed_get(handle);
9980  }
9981 
9997  }
9998 
10015  set_reproduction_style(style);
10016  return std::move(*this);
10017  }
10018 
10028  }
10029 
10041  }
10042 
10055  return std::move(*this);
10056  }
10057 
10067  }
10068 
10079  set_dqcsim_verbosity(level);
10080  return std::move(*this);
10081  }
10082 
10092  }
10093 
10106  }
10107 
10120  set_stderr_verbosity(level);
10121  return std::move(*this);
10122  }
10123 
10136  }
10137 
10146  void log_tee(Loglevel verbosity, const std::string &filename) {
10147  return check(raw::dqcs_scfg_tee(handle, to_raw(verbosity), filename.c_str()));
10148  }
10149 
10160  SimulationConfiguration &&with_log_tee(Loglevel verbosity, const std::string &filename) {
10161  log_tee(verbosity, filename);
10162  return std::move(*this);
10163  }
10164 
10165  private:
10166 
10190  void set_log_callback_ptr(Loglevel verbosity, callback::Log *data) {
10192  handle,
10193  to_raw(verbosity),
10195  CallbackEntryPoints::user_free<callback::Log>,
10196  data
10197  ));
10198  }
10199 
10200  public:
10201 
10220  void set_log_callback(Loglevel verbosity, const callback::Log &data) {
10221  set_log_callback_ptr(verbosity, new callback::Log(data));
10222  }
10223 
10242  void set_log_callback(Loglevel verbosity, callback::Log &&data) {
10243  set_log_callback_ptr(verbosity, new callback::Log(std::move(data)));
10244  }
10245 
10264  template<typename... Args>
10265  void set_log_callback(Loglevel verbosity, Args... args) {
10266  set_log_callback_ptr(verbosity, new callback::Log(args...));
10267  }
10268 
10290  set_log_callback_ptr(verbosity, new callback::Log(data));
10291  return std::move(*this);
10292  }
10293 
10315  set_log_callback_ptr(verbosity, new callback::Log(std::move(data)));
10316  return std::move(*this);
10317  }
10318 
10339  template<typename... Args>
10341  set_log_callback_ptr(verbosity, new callback::Log(args...));
10342  return std::move(*this);
10343  }
10344 
10362  return Simulation(check(raw::dqcs_sim_new(handle)));
10363  }
10364 
10379  Simulation sim = build();
10380  sim.run();
10381  return sim;
10382  }
10383 
10401  Simulation sim = build();
10402  sim.run(std::move(data));
10403  return sim;
10404  }
10405 
10422  Simulation run(const ArbData &data) {
10423  Simulation sim = build();
10424  sim.run(data);
10425  return sim;
10426  }
10427 
10428  };
10429 
10430 } // namespace wrap
10431 
10432 } // namespace dqcsim
10433 
10434 #endif
10435 
10437 #ifdef DQCSIM_SHORT_LOGGING_MACROS
10438 
10440 #ifndef _DQCSIM_LOGGING_INCLUDED_
10441 #define _DQCSIM_LOGGING_INCLUDED_
10443 
10452 #define TRACE DQCSIM_TRACE
10453 
10461 #define DEBUG DQCSIM_DEBUG
10462 
10470 #define INFO DQCSIM_INFO
10471 
10479 #define NOTE DQCSIM_NOTE
10480 
10488 #define WARN DQCSIM_WARN
10489 
10497 #define WARNING DQCSIM_WARNING
10498 
10506 #define ERROR DQCSIM_ERROR
10507 
10515 #define FATAL DQCSIM_FATAL
10516 
10524 #define LOG DQCSIM_LOG
10525 
10526 #endif // _DQCSIM_LOGGING_INCLUDED_
10527 
10529 #endif // DQCSIM_SHORT_LOGGING_MACROS
10530 
dqcsim::raw::dqcs_mset_contains
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.
dqcsim::wrap::RunningPluginState::RunningPluginState
RunningPluginState(raw::dqcs_plugin_state_t state)
Hidden constructor, only to be used by the callback wrappers.
Definition: dqcsim:6681
dqcsim::wrap::Cmd::is_oper
bool is_oper(const std::string &oper) const
Returns whether this command has the given operation identifier.
Definition: dqcsim:2420
dqcsim::wrap::Measurement::Measurement
Measurement(Measurement &&handle)=default
Default move constructor.
dqcsim::wrap::QubitSet::operator=
QubitSet & operator=(QubitSet &&)=default
Default move assignment.
dqcsim::wrap::PluginProcessConfiguration::with_stderr_loglevel
PluginProcessConfiguration && with_stderr_loglevel(Loglevel level)
Configures the capture mode for the stderr stream of the specified plugin process (builder pattern).
Definition: dqcsim:8969
dqcsim::raw::dqcs_cq_len
ssize_t dqcs_cq_len(dqcs_handle_t cq)
Returns the number of ArbCmd objects in the given ArbCmd queue.
dqcsim::wrap::Handle::~Handle
virtual ~Handle() noexcept
Delete the handle and its wrapper.
Definition: dqcsim:1651
dqcsim::raw::dqcs_meas_value_set
dqcs_return_t dqcs_meas_value_set(dqcs_handle_t meas, dqcs_measurement_t value)
Sets the measurement value associated with a measurement object.
dqcsim::wrap::Measurement::get_value
MeasurementValue get_value() const
Returns the measurement value.
Definition: dqcsim:5661
dqcs_qbset_copy
dqcs_handle_t dqcs_qbset_copy(dqcs_handle_t qbset)
Returns a copy of the given qubit set, intended for non-destructive iteration.
dqcsim::wrap::HandleType::Gate
@ Gate
Indicates that a handle is a Gate.
dqcsim::raw::dqcs_sim_new
dqcs_handle_t dqcs_sim_new(dqcs_handle_t scfg)
Constructs a DQCsim simulation.
dqcsim::wrap::Plugin::with_gate
Plugin && with_gate(callback::Gate &&cb)
Assigns the gate callback function from a pre-existing callback::Gate object by move.
Definition: dqcsim:8200
dqcsim::wrap::QubitRef::get_index
QubitIndex get_index() const noexcept
Returns the raw qubit index.
Definition: dqcsim:2953
dqcsim::wrap::Matrix::Matrix
Matrix(Matrix &&)=default
Default move constructor.
DQCS_GATE_TYPE_INVALID
@ DQCS_GATE_TYPE_INVALID
Invalid gate type.
Definition: dqcsim.h:100
dqcsim::wrap::Gate::predefined
static Gate predefined(PredefinedGate gate, const QubitSet &qubits, const ArbData &parameters)
Constructs a new predefined gate.
Definition: dqcsim:3622
dqcsim::wrap::QubitRef::QubitRef
QubitRef(const QubitRef &)=default
Default copy constructor.
dqcsim::wrap::SimulationConfiguration::build
Simulation build()
Constructs the DQCsim simulation from this configuration object.
Definition: dqcsim:10361
dqcsim::wrap::Plugin::with_advance
Plugin && with_advance(const callback::Advance &cb)
Assigns the advance callback function from a pre-existing callback::Advance object by copy.
Definition: dqcsim:8314
DQCS_GATE_U2
@ DQCS_GATE_U2
Any two-qubit unitary gate, parameterized as a full unitary matrix.
Definition: dqcsim.h:853
dqcsim::wrap::UpstreamPluginState::random_u64
uint64_t random_u64() noexcept
Generates a random integer using the simulator random seed.
Definition: dqcsim:6094
dqcsim::raw::dqcs_sim_recv
dqcs_handle_t dqcs_sim_recv(dqcs_handle_t sim)
Waits for the simulated accelerator to send a message to us.
dqcsim::raw::dqcs_gate_new_custom
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.
dqcsim::raw::dqcs_handle_t
unsigned long long dqcs_handle_t
Type for a handle.
Definition: cdqcsim:728
dqcsim::wrap::Matrix::Matrix
Matrix(PredefinedGate gate, const ArbData &parameters)
Constructs a predefined matrix, using ArbData to represent the parameters for parameterized gates.
Definition: dqcsim:3256
dqcsim::wrap::Matrix::approx_eq
bool approx_eq(const Matrix &other, double epsilon=0.000001, bool ignore_global_phase=true) const
Approximate equality operator for two matrices.
Definition: dqcsim:3382
dqcsim::wrap::PluginProcessConfiguration::set_accept_timeout
void set_accept_timeout(double timeout)
Configures the timeout for the plugin process to connect to DQCsim.
Definition: dqcsim:8995
dqcsim::wrap::Arb
Class wrapper for handles that support the arb interface.
Definition: dqcsim:1810
dqcsim::raw::dqcs_tcfg_name
char * dqcs_tcfg_name(dqcs_handle_t tcfg)
Returns the configured name for the given plugin thread.
dqcsim::wrap::Simulation::arb
ArbData arb(ssize_t index, ArbCmd &&cmd)
Sends an ArbCmd (passed by move) to the given plugin (referenced by index).
Definition: dqcsim:9722
DQCS_HTYPE_MEAS_SET
@ DQCS_HTYPE_MEAS_SET
Indicates that the given handle belongs to a set of qubit measurement results.
Definition: dqcsim.h:230
dqcsim::wrap::Simulation::start
void start()
Starts a program on the simulated accelerator without an argument.
Definition: dqcsim:9499
dqcsim::wrap::QubitSet::QubitSet
QubitSet()
Constructs an empty qubit set.
Definition: dqcsim:3002
dqcsim::wrap::PluginState::gate
void gate(const Matrix &matrix, const QubitRef &qa, const QubitRef &qb, const QubitRef &qc)
Shorthand for sending a three-qubit gate to the downstream plugin.
Definition: dqcsim:6397
dqcsim::raw::dqcs_pdef_set_upstream_arb_cb
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.
dqcsim::raw::dqcs_arb_cbor_get
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
@ DQCS_GATE_RY_180
Ry(180°) gate.
Definition: dqcsim.h:657
dqcsim::wrap::ArbCmdQueue::with
ArbCmdQueue && with(const Cmd &cmd)
Pushes an ArbCmd into the queue by copying (builder pattern).
Definition: dqcsim:2753
dqcsim::wrap::Gate::measure
static Gate measure(const QubitSet &measures)
Constructs a new Z-axis measurement gate.
Definition: dqcsim:3764
dqcsim::wrap::PluginProcessConfiguration::set_stdout_loglevel
void set_stdout_loglevel(Loglevel level)
Configures the capture mode for the stdout stream of the specified plugin process.
Definition: dqcsim:8916
dqcsim::wrap::PluginThreadConfiguration::with_verbosity
PluginThreadConfiguration && with_verbosity(Loglevel level)
Sets the logging verbosity level of the plugin (builder pattern).
Definition: dqcsim:9194
dqcsim::wrap::Arb::set_arb
void set_arb(const Arb &src)
Assigns all arb data from the given arb to this one.
Definition: dqcsim:2172
dqcsim::wrap::Gate::unitary
static Gate unitary(QubitSet &&targets, QubitSet &&controls, const Matrix &matrix)
Constructs a new custom unitary gate with control qubits.
Definition: dqcsim:3711
dqcsim::wrap::PluginType::Backend
@ Backend
Backend plugin.
dqcsim::wrap::ArbData::operator=
ArbData & operator=(ArbData &&)=default
Default move assignment.
dqcsim::raw::dqcs_cmd_iface_cmp
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.
dqcsim::wrap::SimulationConfiguration::disable_reproduction
void disable_reproduction()
Disables the reproduction logging system.
Definition: dqcsim:10039
dqcsim::wrap::PluginJoinHandle::PluginJoinHandle
PluginJoinHandle(HandleIndex handle) noexcept
Wraps the given plugin join handle.
Definition: dqcsim:7344
dqcsim::wrap::UpstreamPluginState::random
T random() noexcept
Generates a random value using the simulator random seed.
Definition: dqcsim:6108
dqcsim::wrap::ArbData::ArbData
ArbData(ArbData &&)=default
Default move constructor.
dqcsim::wrap::Plugin::with_upstream_arb
Plugin && with_upstream_arb(callback::Arb &&cb)
Assigns the upstream-arb callback function from a pre-existing callback::Arb object by move.
Definition: dqcsim:8392
dqcsim::wrap::Simulation::arb
ArbData arb(const std::string &name, ArbCmd &&cmd)
Sends an ArbCmd (passed by move) to the given plugin (referenced by instance name).
Definition: dqcsim:9682
dqcsim::wrap::ArbData::with_arg
ArbData & with_arg(const T &data)
Pushes a value of type T to the back of the arbitrary argument list (builder pattern).
Definition: dqcsim:2348
dqcsim::wrap::PluginConfigurationBuilder::PluginConfigurationBuilder
PluginConfigurationBuilder(PluginType type) noexcept
Constructs a plugin configuration builder for the given plugin type.
Definition: dqcsim:9256
dqcsim::raw::dqcs_gate_targets
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.
dqcsim::wrap::to_raw
raw::dqcs_handle_type_t to_raw(HandleType type) noexcept
Converts a HandleType to its raw C enum.
Definition: dqcsim:334
DQCS_HTYPE_GATE_MAP
@ DQCS_HTYPE_GATE_MAP
Indicates that the given handle belongs to a gate map.
Definition: dqcsim.h:242
dqcsim::wrap::Gate::custom
static Gate custom(const std::string &name, QubitSet &&targets, QubitSet &&controls, QubitSet &&measures)
Constructs a new custom gate with target qubits, control qubits, and measured qubits.
Definition: dqcsim:4008
DQCS_GATE_RX_M90
@ DQCS_GATE_RX_M90
Rx(-90°) gate.
Definition: dqcsim.h:605
dqcsim::wrap::Simulation::get_version
std::string get_version(const std::string &name)
Queries the version of a plugin, referenced by instance name.
Definition: dqcsim:9824
dqcsim::wrap::SimulationConfiguration::run
Simulation run(const ArbData &data)
Constructs the DQCsim simulation from this configuration object, and runs a program on the simulated ...
Definition: dqcsim:10422
dqcsim::wrap::Callback::Callback
Callback(T *instance, R(T::*cb)(Args...)) noexcept
Constructs the callback wrapper from a member function.
Definition: dqcsim:6853
dqcsim::wrap::QubitSet::contains
bool contains(const QubitRef &qubit) const
Returns whether the given qubit is contained in the set.
Definition: dqcsim:3107
dqcsim::wrap::Gate::get_type
GateType get_type() const
Returns the type of this gate.
Definition: dqcsim:4292
dqcsim::wrap::CustomGateConverter::detect
virtual bool detect(Gate &&gate, QubitSet &qubits, ArbData &params) const
The to-be-implemented detector function.
Definition: dqcsim:4580
dqcsim::raw::dqcs_arb_assign
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
@ DQCS_HTYPE_INVALID
Indicates that the given handle is invalid.
Definition: dqcsim.h:181
DQCS_HTYPE_GATE
@ DQCS_HTYPE_GATE
Indicates that the given handle belongs to a quantum gate description.
Definition: dqcsim.h:215
dqcsim::raw::dqcs_mat_basis_approx_eq
dqcs_bool_return_t dqcs_mat_basis_approx_eq(dqcs_handle_t a, dqcs_handle_t b, double epsilon)
Approximately compares two basis matrices.
dqcsim::wrap::PluginProcessConfiguration::unset_env_var
void unset_env_var(const std::string &key)
Removes/unsets an environment variable for the plugin process.
Definition: dqcsim:8788
dqcsim::wrap::MeasurementSet::operator=
MeasurementSet & operator=(MeasurementSet &&)=default
Default move assignment.
DQCS_GATE_RX_90
@ DQCS_GATE_RX_90
Rx(90°) gate.
Definition: dqcsim.h:594
dqcsim::wrap::MeasurementSet::operator=
MeasurementSet & operator=(MeasurementSet &src)
Copy-assigns a measurement set object.
Definition: dqcsim:6025
dqcsim::raw::dqcs_pdef_set_drop_cb
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
@ DQCS_GATE_S
The S matrix, also known as a 90 degree Z rotation.
Definition: dqcsim.h:550
dqcsim::raw::dqcs_gate_new_prep
dqcs_handle_t dqcs_gate_new_prep(dqcs_handle_t targets, dqcs_handle_t matrix)
Constructs a new prep gate.
dqcsim::wrap::Gate::has_controls
bool has_controls() const
Returns whether this gate has control qubits.
Definition: dqcsim:4334
dqcsim::wrap::Gate::custom
static Gate custom(const std::string &name, QubitSet &&targets)
Constructs a new custom gate with only target qubits.
Definition: dqcsim:4231
dqcsim::raw::dqcs_plugin_recv
dqcs_handle_t dqcs_plugin_recv(dqcs_plugin_state_t plugin)
Waits for a message from the host.
DQCS_GATE_RX_180
@ DQCS_GATE_RX_180
Rx(180°) gate.
Definition: dqcsim.h:620
dqcsim::wrap::Gate::custom
static Gate custom(const std::string &name, const QubitSet &targets, const QubitSet &controls, const QubitSet &measures)
Constructs a new custom gate with target qubits, control qubits, and measured qubits.
Definition: dqcsim:4041
dqcsim::wrap::HandleType::Matrix
@ Matrix
Indicates that a handle is a Matrix.
dqcsim::wrap::ArbCmd::ArbCmd
ArbCmd(const ArbCmd &src)
Copy-constructs an ArbCmd object from another ArbCmd object.
Definition: dqcsim:2504
DQCS_HTYPE_ARB_CMD_QUEUE
@ DQCS_HTYPE_ARB_CMD_QUEUE
Indicates that the given handle belongs to a queue of ArbCmd object.
Definition: dqcsim.h:201
dqcsim::raw::dqcs_pdef_name
char * dqcs_pdef_name(dqcs_handle_t pdef)
Returns the plugin name for the given plugin definition object.
dqcsim::wrap::MeasurementSet::take
Measurement take(const QubitRef &qubit)
Moves the measurement object for the given qubit out of the set.
Definition: dqcsim:5909
dqcsim::wrap::PluginState::advance
Cycle advance(Cycle cycles)
Tells the downstream plugin to run for the specified number of cycles.
Definition: dqcsim:6587
dqcsim::wrap::Plugin::with_host_arb
Plugin && with_host_arb(callback::Arb &&cb)
Assigns the host-arb callback function from a pre-existing callback::Arb object by move.
Definition: dqcsim:8456
dqcsim::wrap::SimulationConfiguration
Wrapper class for configuring a simulation.
Definition: dqcsim:9866
dqcsim::raw::dqcs_sim_send
dqcs_return_t dqcs_sim_send(dqcs_handle_t sim, dqcs_handle_t data)
Sends a message to the simulated accelerator.
dqcsim::wrap::CustomUnitaryGateConverter
Class that you can inherit from to make your own unitary gate converter for use within DQCsim.
Definition: dqcsim:4606
dqcsim::raw::dqcs_sim_start
dqcs_return_t dqcs_sim_start(dqcs_handle_t sim, dqcs_handle_t data)
Starts a program on the simulated accelerator.
DQCS_BOOL_FAILURE
@ DQCS_BOOL_FAILURE
The function has failed.
Definition: dqcsim.h:82
dqcsim::raw::dqcs_qbset_len
ssize_t dqcs_qbset_len(dqcs_handle_t qbset)
Returns the number of qubits in the given set.
dqcsim::wrap::PluginProcessConfiguration::get_stderr_loglevel
Loglevel get_stderr_loglevel() const
Returns the configured stderr capture mode for the specified plugin process.
Definition: dqcsim:8981
dqcsim::wrap::Plugin::with_gate
Plugin && with_gate(const callback::Gate &cb)
Assigns the gate callback function from a pre-existing callback::Gate object by copy.
Definition: dqcsim:8186
dqcsim::raw::dqcs_pdef_set_host_arb_cb
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
@ DQCS_GATE_S_DAG
The S-dagger matrix, also known as a negative 90 degree Z rotation.
Definition: dqcsim.h:561
dqcsim::wrap::Arb::set_arb_arg_strings
void set_arb_arg_strings(const T &strings)
Sets the arbitrary argument list to the given iterable of std::strings.
Definition: dqcsim:1986
dqcsim::raw::dqcs_handle_type_t
dqcs_handle_type_t
Enumeration of types that can be associated with a handle.
Definition: cdqcsim:165
dqcsim::wrap::Handle::get_handle
HandleIndex get_handle() const noexcept
Returns the raw handle without relinquishing ownership.
Definition: dqcsim:1691
dqcsim::wrap::Gate::predefined
static Gate predefined(PredefinedGate gate, const QubitSet &qubits)
Constructs a new non-parameterized predefined gate.
Definition: dqcsim:3660
DQCS_BASIS_X
@ DQCS_BASIS_X
The X basis.
Definition: dqcsim.h:49
dqcsim::raw::dqcs_arb_remove
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
@ DQCS_GATE_RX
The matrix for an arbitrary X rotation.
Definition: dqcsim.h:717
dqcsim::wrap::Plugin::with_allocate
Plugin && with_allocate(callback::Allocate &&cb)
Assigns the allocate callback function from a pre-existing callback::Allocate object by move.
Definition: dqcsim:8072
dqcsim::wrap::Matrix::Matrix
Matrix(HandleIndex handle) noexcept
Wraps the given matrix handle.
Definition: dqcsim:3171
dqcsim::wrap::ArbCmdQueue::ArbCmdQueue
ArbCmdQueue(ArbCmdQueue &src)
Copy-constructs a queue of ArbCmds.
Definition: dqcsim:2824
dqcsim::wrap::PluginThreadConfiguration::add_init_cmd
void add_init_cmd(ArbCmd &&cmd) override
Attaches an arbitrary initialization command to the plugin.
Definition: dqcsim:9159
dqcsim::wrap::ArbCmdQueue
Class wrapper for queues (lists) of ArbCmds.
Definition: dqcsim:2652
dqcsim::wrap::Arb::set_arb_cbor_string
void set_arb_cbor_string(const std::string &cbor)
Sets the arbitrary JSON data to the given serialized CBOR string.
Definition: dqcsim:1880
dqcsim::raw::dqcs_loglevel_t
dqcs_loglevel_t
Enumeration of loglevels and logging modes.
Definition: cdqcsim:285
dqcsim::wrap::SimulationConfiguration::SimulationConfiguration
SimulationConfiguration(HandleIndex handle) noexcept
Wraps the given simulation configuration handle.
Definition: dqcsim:9877
dqcsim::wrap::GateMap::with_measure
GateMap && with_measure(const Unbound &key, const Matrix &basis, double epsilon=0.000001, int num_measures=-1)
Adds a measurement gate mapping.
Definition: dqcsim:5176
dqcsim::wrap::PluginState::arb
ArbData arb(const ArbCmd &cmd)
Sends an arbitrary command downstream.
Definition: dqcsim:6611
dqcsim::raw::dqcs_predefined_gate_t::DQCS_GATE_INVALID
@ DQCS_GATE_INVALID
Invalid gate. Used as an error return value.
dqcsim::wrap::PluginJoinHandle::PluginJoinHandle
PluginJoinHandle(PluginJoinHandle &&)=default
Default move constructor.
dqcsim::wrap::Arb::set_arb_arg
void set_arb_arg(ssize_t index, const T &data)
Sets the arbitrary argument at the given index to a value of type T.
Definition: dqcsim:2022
dqcsim::raw::dqcs_pcfg_new
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.
dqcsim::wrap::Simulation::arb
ArbData arb(const std::string &name, const ArbCmd &cmd)
Sends an ArbCmd (passed by copy) to the given plugin (referenced by instance name).
Definition: dqcsim:9700
dqcsim::raw::dqcs_sim_get_author_idx
char * dqcs_sim_get_author_idx(dqcs_handle_t sim, ssize_t index)
Queries the author of a plugin, referenced by index.
dqcsim::wrap::Plugin::get_author
std::string get_author() const
Returns the author of the described plugin.
Definition: dqcsim:7729
dqcsim::wrap::Measurement::Measurement
Measurement(HandleIndex handle) noexcept
Wraps the given measurement handle.
Definition: dqcsim:5603
dqcsim::raw::dqcs_plugin_gate
dqcs_return_t dqcs_plugin_gate(dqcs_plugin_state_t plugin, dqcs_handle_t gate)
Tells the downstream plugin to execute a gate.
dqcsim::wrap::Gate::custom
static Gate custom(const std::string &name, const QubitSet &targets)
Constructs a new custom gate with only target qubits.
Definition: dqcsim:4255
dqcsim::wrap::SimulationConfiguration::with_reproduction_style
SimulationConfiguration && with_reproduction_style(PathStyle style)
Sets the path style used when writing reproduction files (builder pattern).
Definition: dqcsim:10014
dqcs_mat_predef
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.
dqcsim::raw::dqcs_pcfg_stdout_mode_get
dqcs_loglevel_t dqcs_pcfg_stdout_mode_get(dqcs_handle_t pcfg)
Returns the configured stdout capture mode for the specified plugin process.
dqcsim::wrap::Arb::push_arb_arg_string
void push_arb_arg_string(const std::string &data)
Pushes a (binary) string to the back of the arbitrary argument list.
Definition: dqcsim:2033
dqcsim::raw::dqcs_pcfg_work_set
dqcs_return_t dqcs_pcfg_work_set(dqcs_handle_t pcfg, const char *work)
Overrides the working directory for the plugin process.
dqcsim::wrap::PluginState::free
void free(QubitSet &&qubits)
Frees the given downstream qubits.
Definition: dqcsim:6274
dqcsim::wrap::PluginProcessConfiguration::get_stdout_loglevel
Loglevel get_stdout_loglevel() const
Returns the configured stdout capture mode for the specified plugin process.
Definition: dqcsim:8942
dqcsim::wrap::Arb::pop_arb_arg_string
std::string pop_arb_arg_string()
Pops from the back of the arbitrary argument list as a (binary) string.
Definition: dqcsim:2062
dqcsim::wrap::PluginProcessConfiguration::get_script
std::string get_script() const
Returns the configured script path for the plugin.
Definition: dqcsim:8713
dqcsim::wrap::GateMap::with_unitary
GateMap && with_unitary(Unbound &&key, const std::shared_ptr< CustomUnitaryGateConverter > &converter)
Adds a custom unitary gate mapping.
Definition: dqcsim:5003
dqcsim::wrap::Measurement::set_value
void set_value(MeasurementValue value)
Sets the measurement value.
Definition: dqcsim:5671
dqcsim::wrap::PluginConfigurationBuilder::with_callbacks
PluginThreadConfiguration with_callbacks(Plugin &&plugin)
Builds a plugin thread configuration object from a plugin definition object, containing a bunch of ca...
Definition: dqcsim:9323
dqcsim::raw::dqcs_pdef_set_free_cb
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.
dqcsim::wrap::HandleType::Simulation
@ Simulation
Indicates that a handle is a Simulation.
dqcsim::wrap::Gate::has_matrix
bool has_matrix() const
Returns whether this gate has a matrix.
Definition: dqcsim:4378
dqcsim::wrap::QubitRef::QubitRef
QubitRef(QubitIndex index)
Wraps a raw reference.
Definition: dqcsim:2890
dqcsim::wrap::PluginConfigurationBuilder::with_executable
PluginProcessConfiguration with_executable(const std::string &executable, const std::string &script="")
Builds a plugin process configuration object from a path to a plugin executable and an optional path ...
Definition: dqcsim:9307
dqcsim::wrap::Gate::with_json_string
Gate & with_json_string(const std::string &json)
Sets the arbitrary JSON data to the given serialized JSON string (builder pattern).
Definition: dqcsim:4420
dqcsim::wrap::ArbCmd::with_json_string
ArbCmd & with_json_string(const std::string &json)
Sets the arbitrary JSON data to the given serialized JSON string (builder pattern).
Definition: dqcsim:2552
DQCS_LOG_ERROR
@ DQCS_LOG_ERROR
This loglevel is to be used for reporting or propagating a non-fatal error caused by the API caller d...
Definition: dqcsim.h:359
dqcsim::wrap::Measurement::with_arg
Measurement & with_arg(const T &data)
Pushes a value of type T to the back of the arbitrary argument list (builder pattern).
Definition: dqcsim:5775
dqcsim::wrap::Plugin::with_drop
Plugin && with_drop(Args... args)
Assigns the drop callback function by constructing the callback object implicitly.
Definition: dqcsim:7958
dqcsim::raw::dqcs_mat_strip_control
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.
dqcsim::raw::dqcs_mat_len
ssize_t dqcs_mat_len(dqcs_handle_t mat)
Returns the number of complex entries in the given matrix.
dqcsim::wrap::PluginConfigurationBuilder::with_spawner
PluginThreadConfiguration with_spawner(const callback::SpawnPlugin &data)
Builds a plugin thread configuration object using a single callback that spawns the entire plugin.
Definition: dqcsim:9376
dqcsim::wrap::PluginConfigurationBuilder
Builder class used to construct plugin configurations.
Definition: dqcsim:9241
dqcsim::wrap::GateMap::construct
Gate construct(const Unbound &unbound, const QubitSet &qubits)
Uses a gate map object to construct a DQCsim gate from the plugin's representation.
Definition: dqcsim:5517
dqcsim::wrap::PluginProcessConfiguration::get_shutdown_timeout
double get_shutdown_timeout() const
Returns the configured timeout for the plugin process to shut down gracefully.
Definition: dqcsim:9089
dqcsim::raw::dqcs_pcfg_stderr_mode_get
dqcs_loglevel_t dqcs_pcfg_stderr_mode_get(dqcs_handle_t pcfg)
Returns the configured stderr capture mode for the specified plugin process.
dqcsim::raw::dqcs_mset_set
dqcs_return_t dqcs_mset_set(dqcs_handle_t mset, dqcs_handle_t meas)
Adds a measurement result to a measurement result set.
dqcsim::raw::dqcs_arb_len
ssize_t dqcs_arb_len(dqcs_handle_t arb)
Returns the number of unstructured arguments, or -1 to indicate failure.
dqcsim::wrap::SimulationConfiguration::add_plugin
void add_plugin(PluginConfiguration &&plugin)
Appends a plugin to a simulation configuration.
Definition: dqcsim:9920
dqcsim::raw::dqcs_sim_get_version
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
@ DQCS_HTYPE_FRONT_PROCESS_CONFIG
Indicates that the given handle belongs to a frontend plugin process configuration object.
Definition: dqcsim.h:250
dqcsim::wrap::PluginThreadConfiguration::PluginThreadConfiguration
PluginThreadConfiguration(PluginThreadConfiguration &&)=default
Default move constructor.
dqcsim::wrap::SimulationConfiguration::with_log_tee
SimulationConfiguration && with_log_tee(Loglevel verbosity, const std::string &filename)
Configures DQCsim to also output its log messages to a file (builder pattern).
Definition: dqcsim:10160
dqcsim::raw::dqcs_plugin_run
dqcs_return_t dqcs_plugin_run(dqcs_handle_t pdef, const char *simulator)
Executes a plugin in the current thread.
dqcsim::wrap::QubitIndex
raw::dqcs_qubit_t QubitIndex
C++-styled type name for raw::dqcs_qubit_t.
Definition: dqcsim:108
dqcsim::wrap::PluginProcessConfiguration::with_log_tee
PluginProcessConfiguration && with_log_tee(Loglevel verbosity, const std::string &filename)
Configures a plugin thread to also output its log messages to a file (builder pattern).
Definition: dqcsim:8902
dqcsim::raw::dqcs_gate_matrix
dqcs_handle_t dqcs_gate_matrix(dqcs_handle_t gate)
Returns a copy of the unitary matrix associated with this gate, if one exists.
dqcsim::wrap::log
void log(wrap::Loglevel level, const std::string &module, const std::string &file, unsigned int line_nr, const std::string &format, Args... args) noexcept
Shim around the dqcs_log_format C API using std::string for the strings.
Definition: dqcsim:1459
dqcsim::wrap::Plugin::Backend
static Plugin Backend(const std::string &name, const std::string &author, const std::string &version)
Shorthand for constructing a new backend plugin.
Definition: dqcsim:7678
dqcsim::wrap::Handle::dump
std::string dump() const
Returns a string containing a debug dump of the handle.
Definition: dqcsim:1770
dqcsim::raw::dqcs_tcfg_type
dqcs_plugin_type_t dqcs_tcfg_type(dqcs_handle_t tcfg)
Returns the type of the given plugin thread configuration.
dqcsim::raw::dqcs_mset_take_any
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...
dqcsim::raw::dqcs_arb_get_raw
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.
dqcsim::wrap::GateType
GateType
Enumeration of gate types supported by DQCsim.
Definition: dqcsim:720
dqcs_pdef_new
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.
dqcsim::raw::dqcs_cq_next
dqcs_return_t dqcs_cq_next(dqcs_handle_t cq)
Advances an ArbCmd queue to the next command.
dqcsim::wrap::Plugin::with_host_arb
Plugin && with_host_arb(const callback::Arb &cb)
Assigns the host-arb callback function from a pre-existing callback::Arb object by copy.
Definition: dqcsim:8442
dqcsim::wrap::QubitRef::operator=
QubitRef & operator=(const QubitRef &)=default
Default copy assignment.
dqcs_qbset_new
dqcs_handle_t dqcs_qbset_new(void)
Creates a new set of qubit references.
dqcsim::raw::dqcs_return_t
dqcs_return_t
Default return type for functions that don't need to return anything.
Definition: cdqcsim:702
dqcsim::raw::dqcs_mat_approx_unitary
dqcs_bool_return_t dqcs_mat_approx_unitary(dqcs_handle_t matrix, double epsilon)
Returns whether the matrix is approximately unitary.
dqcsim::wrap::QubitSet::with
QubitSet && with(const QubitRef &qubit)
Pushes a qubit into the set (builder pattern).
Definition: dqcsim:3074
dqcsim::wrap::Callback::Callback
Callback(std::shared_ptr< std::function< R(Args...)>> &&cb) noexcept
Constructs the callback wrapper by means of moving a shared_ptr to a std::function.
Definition: dqcsim:6881
dqcsim::raw::dqcs_sim_get_author
char * dqcs_sim_get_author(dqcs_handle_t sim, const char *name)
Queries the author of a plugin, referenced by instance name.
dqcsim::raw::dqcs_meas_qubit_set
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
@ DQCS_LOG_OFF
Turns logging off.
Definition: dqcsim.h:346
dqcsim::wrap::HandleType::ArbCmd
@ ArbCmd
Indicates that a handle is an ArbCmd.
dqcsim::wrap::Plugin::with_initialize
Plugin && with_initialize(Args... args)
Assigns the initialize callback function by constructing the callback object implicitly.
Definition: dqcsim:7894
dqcsim::wrap::MeasurementSet
Represents a set of measurements.
Definition: dqcsim:5789
dqcsim::wrap::Gate::with_arg_string
Gate & with_arg_string(const std::string &data)
Pushes a (binary) string to the back of the arbitrary argument list (builder pattern).
Definition: dqcsim:4465
dqcsim::wrap::Measurement::operator=
Measurement & operator=(Measurement &&)=default
Default move assignment.
dqcsim::raw::dqcs_gate_type_t::DQCS_GATE_TYPE_INVALID
@ DQCS_GATE_TYPE_INVALID
Invalid gate type. Used as an error return value.
dqcsim::raw::dqcs_pdef_set_gate_cb
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.
dqcsim::wrap::PluginState::measure_z
void measure_z(const QubitRef &q)
Shorthand for sending a single-qubit Z-axis measurement to the downstream plugin.
Definition: dqcsim:6537
dqcsim::wrap::Arb::set_arb_json_string
void set_arb_json_string(const std::string &json)
Sets the arbitrary JSON data to the given serialized JSON string.
Definition: dqcsim:1849
dqcs_arb_new
dqcs_handle_t dqcs_arb_new(void)
Creates a new ArbData object.
dqcsim::wrap::PluginProcessConfiguration::log_tee
void log_tee(Loglevel verbosity, const std::string &filename) override
Configures a plugin thread to also output its log messages to a file.
Definition: dqcsim:8888
dqcsim::wrap::MeasurementSet::MeasurementSet
MeasurementSet()
Constructs an empty measurement set.
Definition: dqcsim:5806
dqcsim::wrap::Gate::custom
static Gate custom(const std::string &name, QubitSet &&targets, QubitSet &&controls, QubitSet &&measures, const Matrix &matrix)
Constructs a new custom gate with target qubits, control qubits, measured qubits, and a matrix.
Definition: dqcsim:3937
dqcsim::wrap::QubitSet::QubitSet
QubitSet(HandleIndex handle) noexcept
Wraps the given qubit set handle.
Definition: dqcsim:2993
DQCS_HTYPE_OPER_PROCESS_CONFIG
@ DQCS_HTYPE_OPER_PROCESS_CONFIG
Indicates that the given handle belongs to an operator plugin process configuration object.
Definition: dqcsim.h:258
dqcsim::wrap::ArbCmd::with_arg_string
ArbCmd & with_arg_string(const std::string &data)
Pushes a (binary) string to the back of the arbitrary argument list (builder pattern).
Definition: dqcsim:2597
dqcsim::wrap::Gate::custom
static Gate custom(const std::string &name)
Constructs a new custom gate without qubit operands.
Definition: dqcsim:4274
dqcsim::wrap::QubitRef::operator<<
friend std::ostream & operator<<(std::ostream &out, const QubitRef &qubit)
Allow qubit references to be printed.
Definition: dqcsim:2943
dqcsim::raw::dqcs_plugin_get_cycle
dqcs_cycle_t dqcs_plugin_get_cycle(dqcs_plugin_state_t plugin)
Returns the current value of the downstream cycle counter.
dqcsim::raw::dqcs_pcfg_accept_timeout_set
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.
dqcsim::wrap::GateMap::with_measure
GateMap && with_measure(Unbound &&key, PauliBasis basis=PauliBasis::Z, double epsilon=0.000001, int num_measures=-1)
Adds a measurement gate mapping.
Definition: dqcsim:5071
dqcsim::wrap::Plugin::operator=
Plugin & operator=(Plugin &&)=default
Default move assignment.
dqcsim::wrap::PluginProcessConfiguration::with_init_cmd
PluginProcessConfiguration && with_init_cmd(ArbCmd &&cmd)
Attaches an arbitrary initialization command to the plugin (builder pattern).
Definition: dqcsim:8740
dqcsim::raw::dqcs_mat_is_predef
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...
dqcsim::raw::dqcs_scfg_stderr_verbosity_set
dqcs_return_t dqcs_scfg_stderr_verbosity_set(dqcs_handle_t scfg, dqcs_loglevel_t level)
Configures the stderr sink verbosity for a simulation.
dqcsim::wrap::PluginConfiguration::PluginConfiguration
PluginConfiguration(HandleIndex handle) noexcept
Wraps the given plugin process or thread configuration handle.
Definition: dqcsim:8553
DQCS_GATE_TYPE_PREP
@ DQCS_GATE_TYPE_PREP
Prep gates have one or more target qubits and a 2x2 unitary matrix representing the basis.
Definition: dqcsim.h:149
dqcsim::raw::dqcs_plugin_send
dqcs_return_t dqcs_plugin_send(dqcs_plugin_state_t plugin, dqcs_handle_t arb)
Sends a message to the host.
dqcsim::wrap::Plugin::with_gate
Plugin && with_gate(Args... args)
Assigns the gate callback function by constructing the callback object implicitly.
Definition: dqcsim:8214
dqcsim::raw::dqcs_return_t::DQCS_FAILURE
@ DQCS_FAILURE
The function has failed.
dqcsim::wrap::PluginState::arb
ArbData arb(ArbCmd &&cmd)
Sends an arbitrary command downstream.
Definition: dqcsim:6599
dqcsim::wrap::HandleType::GateMap
@ GateMap
Indicates that a handle is a GateMap.
dqcsim::raw::dqcs_gate_type_t
dqcs_gate_type_t
Types of DQCsim gates.
Definition: cdqcsim:102
dqcsim::wrap::Matrix::basis_approx_eq
bool basis_approx_eq(const Matrix &other, double epsilon=0.000001) const
Approximate equality operator for two basis matrices.
Definition: dqcsim:3407
DQCS_PTYPE_FRONT
@ DQCS_PTYPE_FRONT
Frontend plugin.
Definition: dqcsim.h:465
dqcsim::wrap::SimulationConfiguration::set_log_callback
void set_log_callback(Loglevel verbosity, const callback::Log &data)
Configures DQCsim to also output its log messages to callback function.
Definition: dqcsim:10220
dqcsim::wrap::PluginState::allocate
QubitSet allocate(size_t num_qubits)
Allocates a number of default downstream qubits.
Definition: dqcsim:6203
dqcsim::wrap::PluginConfigurationBuilder::with_name
PluginConfigurationBuilder && with_name(const std::string &name) noexcept
Builder function for naming the plugin instance.
Definition: dqcsim:9272
dqcsim::wrap::UpstreamPluginState::UpstreamPluginState
UpstreamPluginState(raw::dqcs_plugin_state_t state)
Hidden constructor, only to be used by the callback wrappers.
Definition: dqcsim:6064
dqcsim::wrap::Gate::unitary
static Gate unitary(const QubitSet &targets, const QubitSet &controls, const Matrix &matrix)
Constructs a new custom unitary gate with control qubits.
Definition: dqcsim:3734
dqcsim::wrap::Simulation::start
void start(ArbData &&data)
Starts a program on the simulated accelerator using the given ArbData object as an argument (passed b...
Definition: dqcsim:9515
dqcsim::raw::dqcs_arb_push_raw
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.
dqcsim::wrap::PluginProcessConfiguration::set_work_dir
void set_work_dir(const std::string &dir)
Overrides the working directory for the plugin process.
Definition: dqcsim:8816
dqcsim::wrap::ArbCmdQueue::drain_into_vector
std::vector< ArbCmd > drain_into_vector()
Drains the queue into a vector of ArbCmds.
Definition: dqcsim:2786
dqcsim::wrap::Gate::measure
static Gate measure(const QubitSet &measures, PauliBasis basis)
Constructs a new measurement gate, measuring in the given Pauli basis.
Definition: dqcsim:3796
dqcsim::wrap::SimulationConfiguration::set_dqcsim_verbosity
void set_dqcsim_verbosity(Loglevel level)
Configures the logging verbosity for DQCsim's own messages.
Definition: dqcsim:10065
dqcsim::wrap::GateMap::operator=
GateMap & operator=(GateMap &&)=default
Default move assignment.
dqcsim::wrap::SimulationConfiguration::set_stderr_verbosity
void set_stderr_verbosity(Loglevel level)
Configures the stderr sink verbosity for a simulation.
Definition: dqcsim:10104
dqcsim::wrap::callback::Drop
Callback< void, PluginState & > Drop
Callback wrapper specialized for the drop callback.
Definition: dqcsim:6909
DQCS_GATE_U1
@ DQCS_GATE_U1
Any single-qubit unitary gate, parameterized as a full unitary matrix.
Definition: dqcsim.h:792
dqcsim::wrap::GateMap::detect
bool detect(const Gate &gate, const Unbound **unbound, QubitSet *qubits, ArbData *params)
Uses the gate map to convert an incoming DQCsim gate to the plugin's Unbound representation.
Definition: dqcsim:5417
dqcsim::raw::dqcs_pdef_set_initialize_cb
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.
dqcsim::wrap::PluginState::gate
void gate(Gate &&gate)
Sends a gate to the downstream plugin.
Definition: dqcsim:6321
dqcsim::wrap::MeasurementSet::drain_into_vector
std::vector< Measurement > drain_into_vector()
Drains the measurement set into a vector.
Definition: dqcsim:5972
dqcsim::wrap::Matrix::Matrix
Matrix(PauliBasis basis)
Constructs a Pauli basis matrix.
Definition: dqcsim:3267
dqcsim::wrap::PluginProcessConfiguration::get_name
std::string get_name() const override
Returns the name given to the plugin.
Definition: dqcsim:8687
dqcsim::wrap::QubitRef
Represents a qubit.
Definition: dqcsim:2874
dqcsim::wrap::PluginType
PluginType
Enumeration of the three types of plugins.
Definition: dqcsim:660
dqcsim::wrap::callback::Run
Callback< ArbData, RunningPluginState &, ArbData && > Run
Callback wrapper specialized for the run callback.
Definition: dqcsim:6914
dqcsim::wrap::PluginThreadConfiguration::log_tee
void log_tee(Loglevel verbosity, const std::string &filename) override
Configures a plugin thread to also output its log messages to a file.
Definition: dqcsim:9217
DQCS_PTYPE_INVALID
@ DQCS_PTYPE_INVALID
Invalid plugin type.
Definition: dqcsim.h:461
dqcsim::wrap::MeasurementSet::size
size_t size() const
Returns the number of measurements in the set.
Definition: dqcsim:5944
dqcsim::wrap::Gate::prep
static Gate prep(const QubitSet &targets)
Constructs a new Z-axis prep gate, putting the qubits in the |0> state.
Definition: dqcsim:3854
dqcsim::wrap::Frontend
PluginConfigurationBuilder Frontend(const std::string &name="") noexcept
Shorthand for constructing a frontend plugin configuration builder.
Definition: dqcsim:9430
dqcsim::wrap::Matrix::get
std::vector< complex > get() const
Returns the data contained by the matrix in row-major form as complex numbers.
Definition: dqcsim:3343
dqcsim::raw::dqcs_scfg_stderr_verbosity_get
dqcs_loglevel_t dqcs_scfg_stderr_verbosity_get(dqcs_handle_t scfg)
Returns the configured stderr sink verbosity for a simulation.
dqcsim::wrap::PluginThreadConfiguration::get_name
std::string get_name() const override
Returns the name given to the plugin.
Definition: dqcsim:9145
dqcsim::wrap::GateMap::with_unitary
GateMap && with_unitary(Unbound &&key, PredefinedGate gate, int num_controls=-1, double epsilon=0.000001, bool ignore_global_phase=true)
Adds a unitary gate mapping for the given DQCsim-defined gate.
Definition: dqcsim:4847
dqcsim::wrap::MeasurementSet::from_iter
static MeasurementSet from_iter(const T &measurements)
Constructs a measurement set object from an iterable of measurements.
Definition: dqcsim:5820
DQCS_GATE_TYPE_MEASUREMENT
@ DQCS_GATE_TYPE_MEASUREMENT
Measurement gates have one or more measured qubits and a 2x2 unitary matrix representing the basis.
Definition: dqcsim.h:132
dqcsim::raw::dqcs_tcfg_verbosity_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.
dqcsim::wrap::Loglevel
Loglevel
Represents the loglevel of a message, a loglevel filter level, or one of the possible actions to take...
Definition: dqcsim:407
dqcsim::wrap::GateMap::GateMap
GateMap(HandleIndex handle) noexcept
Wraps the given gate map handle.
Definition: dqcsim:4785
dqcsim::wrap::UpstreamPluginState::state
const raw::dqcs_plugin_state_t state
The wrapped plugin state.
Definition: dqcsim:6059
dqcsim::wrap::Cmd::Cmd
Cmd(HandleIndex handle) noexcept
Wraps the given cmd handle.
Definition: dqcsim:2373
DQCS_MEAS_INVALID
@ DQCS_MEAS_INVALID
Error value used to indicate that something went wrong.
Definition: dqcsim.h:413
dqcsim::wrap::QubitRef::operator=
QubitRef & operator=(QubitRef &&)=default
Default move assignment.
dqcsim::raw::dqcs_cmd_oper_cmp
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.
dqcsim::wrap::GateMap::convert
Bound convert(const Gate &gate)
Wrapper function for detect(), converting from DQCsim's gate representation directly to the plugin's ...
Definition: dqcsim:5538
DQCS_HTYPE_FRONT_DEF
@ DQCS_HTYPE_FRONT_DEF
Indicates that the given handle belongs to a frontend plugin definition object.
Definition: dqcsim.h:310
dqcsim::raw::dqcs_path_style_t::DQCS_PATH_STYLE_INVALID
@ DQCS_PATH_STYLE_INVALID
Error value used to indicate that something went wrong.
dqcsim::raw::dqcs_meas_value_get
dqcs_measurement_t dqcs_meas_value_get(dqcs_handle_t meas)
Returns the measurement value associated with a measurement object.
dqcsim::wrap::Loglevel::Off
@ Off
In the context of a filter, turns logging off.
DQCS_HTYPE_MEAS
@ DQCS_HTYPE_MEAS
Indicates that the given handle belongs to a qubit measurement result.
Definition: dqcsim.h:223
cdqcsim
Provides DQCsim's raw C API symbols in the dqcsim::raw namespace.
dqcsim::raw::dqcs_arb_cbor_set
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.
dqcsim::wrap::SimulationConfiguration::with_log_callback
SimulationConfiguration && with_log_callback(Loglevel verbosity, const callback::Log &data)
Configures DQCsim to also output its log messages to callback function (builder pattern).
Definition: dqcsim:10289
dqcsim::wrap::Plugin::Frontend
static Plugin Frontend(const std::string &name, const std::string &author, const std::string &version)
Shorthand for constructing a new frontend plugin.
Definition: dqcsim:7640
dqcsim::wrap::Plugin::with_drop
Plugin && with_drop(callback::Drop &&cb)
Assigns the drop callback function from a pre-existing callback::Drop object by move.
Definition: dqcsim:7944
dqcsim::wrap::PluginJoinHandle::operator=
PluginJoinHandle & operator=(PluginJoinHandle &&)=default
Default move assignment.
dqcsim::wrap::Simulation::get_version
std::string get_version(ssize_t index)
Queries the version of a plugin, referenced by index.
Definition: dqcsim:9843
dqcsim::raw::dqcs_scfg_repro_path_style_set
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.
dqcsim::wrap::Plugin::Plugin
Plugin(PluginType type, const std::string &name, const std::string &author, const std::string &version)
Constructs a new plugin definition object.
Definition: dqcsim:7619
dqcsim::raw::dqcs_arb_clear
dqcs_return_t dqcs_arb_clear(dqcs_handle_t arb)
Clears the unstructured argument list.
dqcsim::wrap::Gate::custom
static Gate custom(const std::string &name, const QubitSet &targets, const Matrix &matrix)
Constructs a new custom gate with target qubits and a matrix.
Definition: dqcsim:4209
dqcsim::wrap::PluginProcessConfiguration::set_verbosity
void set_verbosity(Loglevel level) override
Sets the logging verbosity level of the plugin.
Definition: dqcsim:8854
dqcsim::raw::dqcs_mat_add_controls
dqcs_handle_t dqcs_mat_add_controls(dqcs_handle_t mat, size_t number_of_controls)
Constructs a controlled matrix from the given matrix.
dqcsim::raw::dqcs_error_get
const char * dqcs_error_get()
Returns a pointer to the latest error message.
dqcsim::wrap::Handle::operator<<
friend std::ostream & operator<<(std::ostream &out, const Handle &handle)
Write the debug dump string of the handle to the given output stream.
Definition: dqcsim:1788
dqcsim::wrap::GateMap::with_custom
GateMap && with_custom(const Unbound &key, const std::shared_ptr< CustomGateConverter > &converter)
Adds a custom gate mapping.
Definition: dqcsim:5379
DQCS_HTYPE_MATRIX
@ DQCS_HTYPE_MATRIX
Indicates that the given handle belongs to a matrix.
Definition: dqcsim.h:236
dqcsim::raw::dqcs_scfg_dqcsim_verbosity_get
dqcs_loglevel_t dqcs_scfg_dqcsim_verbosity_get(dqcs_handle_t scfg)
Returns the configured verbosity for DQCsim's own messages.
dqcsim::wrap::ArbData::ArbData
ArbData(HandleIndex handle) noexcept
Wraps the given ArbData handle.
Definition: dqcsim:2213
dqcsim::wrap::HandleType::PluginJoinHandle
@ PluginJoinHandle
Indicates that a handle is a PluginJoinHandle.
DQCS_LOG_TRACE
@ DQCS_LOG_TRACE
This loglevel is to be used for reporting debugging information useful for debugging the internals of...
Definition: dqcsim.h:394
dqcsim::wrap::PluginState::get_cycle
Cycle get_cycle()
Returns the current value of the downstream cycle counter.
Definition: dqcsim:6661
dqcsim::wrap::GateMap::with_unitary
GateMap && with_unitary(const Unbound &key, PredefinedGate gate, int num_controls=-1, double epsilon=0.000001, bool ignore_global_phase=true)
Adds a unitary gate mapping for the given DQCsim-defined gate.
Definition: dqcsim:4888
dqcsim::wrap::PluginThreadConfiguration
Wrapper class for local plugin thread configurations.
Definition: dqcsim:9098
dqcsim::wrap::Arb::pop_arb_arg_as
T pop_arb_arg_as() const
Pops from the back of the arbitrary argument list as a value of type T.
Definition: dqcsim:2087
dqcsim::raw::dqcs_gate_new_predef
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.
dqcsim::wrap::HandleType::QubitSet
@ QubitSet
Indicates that a handle is a QubitSet.
dqcsim::wrap::Gate::Gate
Gate(Gate &&)=default
Default move constructor.
dqcsim::wrap::Plugin::with_allocate
Plugin && with_allocate(const callback::Allocate &cb)
Assigns the allocate callback function from a pre-existing callback::Allocate object by copy.
Definition: dqcsim:8058
dqcsim::wrap::SimulationConfiguration::run
Simulation run()
Constructs the DQCsim simulation from this configuration object, and runs a program on the simulated ...
Definition: dqcsim:10378
dqcsim::wrap::Measurement::operator=
void operator=(const Measurement &src)
Copy assignment operator for Measurement objects.
Definition: dqcsim:5639
dqcsim::raw::dqcs_gate_controls
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.
dqcsim::raw::dqcs_pcfg_stdout_mode_set
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.
dqcsim::wrap::ArbCmd::with_arg
ArbCmd & with_arg(const T &data)
Pushes a value of type T to the back of the arbitrary argument list (builder pattern).
Definition: dqcsim:2617
dqcs_mat_basis
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.
dqcsim::wrap::GateMap::with_measure
GateMap && with_measure(Unbound &&key, Matrix &&basis, double epsilon=0.000001, int num_measures=-1)
Adds a measurement gate mapping.
Definition: dqcsim:5141
dqcsim::wrap::Simulation::run
ArbData run()
Runs a program on the simulated accelerator without an argument.
Definition: dqcsim:9559
dqcsim::wrap::HandleType::MeasurementSet
@ MeasurementSet
Indicates that a handle is a MeasurementSet.
dqcsim::wrap::PluginState::get_cycles_since_measure
Cycle get_cycles_since_measure(const QubitRef &qubit)
Returns the number of downstream cycles since the latest measurement of the given downstream qubit.
Definition: dqcsim:6637
dqcsim::wrap::PluginJoinHandle::wait
void wait()
Waits for the plugin to terminate.
Definition: dqcsim:7366
dqcsim::wrap::Plugin::with_modify_measurement
Plugin && with_modify_measurement(callback::ModifyMeasurement &&cb)
Assigns the modify-measurement callback function from a pre-existing callback::ModifyMeasurement obje...
Definition: dqcsim:8264
dqcsim::wrap::PauliBasis
PauliBasis
Enumeration of Pauli bases.
Definition: dqcsim:836
dqcsim::wrap::ArbCmd::operator=
void operator=(const ArbCmd &src)
Copy assignment operator for ArbCmd objects.
Definition: dqcsim:2517
dqcsim::wrap::PluginState::measure_y
void measure_y(const QubitRef &q)
Shorthand for sending a single-qubit Y-axis measurement to the downstream plugin.
Definition: dqcsim:6487
dqcsim::raw::dqcs_pcfg_stderr_mode_set
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.
dqcsim::wrap::Plugin::with_upstream_arb
Plugin && with_upstream_arb(Args... args)
Assigns the upstream-arb callback function by constructing the callback object implicitly.
Definition: dqcsim:8406
dqcsim::raw::dqcs_basis_t
dqcs_basis_t
Enumeration of Pauli bases.
Definition: cdqcsim:58
dqcsim::wrap::Simulation::Simulation
Simulation(Simulation &&)=default
Default move constructor.
dqcsim::wrap::QubitSet::size
size_t size() const
Returns the number of qubits in the set.
Definition: dqcsim:3096
dqcsim::wrap::ArbCmdQueue::ArbCmdQueue
ArbCmdQueue()
Constructs an empty ArbCmd queue object.
Definition: dqcsim:2672
dqcsim::wrap::Plugin::run
void run(const char *simulator)
Runs the defined plugin in the current thread with the given simulator connection descriptor string.
Definition: dqcsim:8487
dqcsim::wrap::SimulationConfiguration::set_log_callback
void set_log_callback(Loglevel verbosity, callback::Log &&data)
Configures DQCsim to also output its log messages to callback function.
Definition: dqcsim:10242
DQCS_PTYPE_OPER
@ DQCS_PTYPE_OPER
Operator plugin.
Definition: dqcsim.h:469
dqcsim::raw::dqcs_arb_set_raw
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.
dqcsim::wrap::Operator
PluginConfigurationBuilder Operator(const std::string &name="") noexcept
Shorthand for constructing an operator plugin configuration builder.
Definition: dqcsim:9442
dqcsim::wrap::CustomUnitaryGateConverter::construct
virtual Matrix construct(ArbData &params, ssize_t &num_controls) const
The to-be-implemented constructor function.
Definition: dqcsim:4708
dqcsim::wrap::Gate::has_name
bool has_name() const
Returns whether this gate has a name.
Definition: dqcsim:4401
dqcsim::wrap::PluginState::allocate
QubitSet allocate(size_t num_qubits, ArbCmdQueue &&cmds)
Allocates a number of downstream qubits, copying in the given command queue as arbitrary additional d...
Definition: dqcsim:6165
dqcsim::wrap::ArbCmdQueue::from_iter
static ArbCmdQueue from_iter(T &&cmds)
Constructs an ArbCmd queue object from an iterable of ArbCmds by moving.
Definition: dqcsim:2707
dqcsim::wrap::PredefinedGate
PredefinedGate
Enumeration of unitary gates defined by DQCsim.
Definition: dqcsim:917
dqcsim::wrap::MeasurementValue::Zero
@ Zero
Qubit measurement returned zero.
dqcsim::wrap::PluginType::Frontend
@ Frontend
Frontend plugin.
dqcsim::wrap::GateMap::construct
Gate construct(const Unbound &unbound, const QubitSet &qubits, const ArbData &params)
Uses a gate map object to construct a DQCsim gate from the plugin's representation.
Definition: dqcsim:5476
dqcsim::raw::dqcs_pdef_set_run_cb
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.
dqcsim::raw::dqcs_pcfg_type
dqcs_plugin_type_t dqcs_pcfg_type(dqcs_handle_t pcfg)
Returns the type of the given plugin process configuration.
dqcsim::wrap::Handle
Base class for wrapping any handle.
Definition: dqcsim:1618
dqcs_meas_new
dqcs_handle_t dqcs_meas_new(dqcs_qubit_t qubit, dqcs_measurement_t value)
Constructs a new measurement object.
dqcsim::wrap::QubitSet::copy_into_vector
std::vector< QubitRef > copy_into_vector() const
Copies the qubit set into a vector.
Definition: dqcsim:3141
dqcsim::wrap::callback::Log
Callback< void, std::string &&, std::string &&, Loglevel, std::string &&, std::string &&, uint32_t, std::chrono::system_clock::time_point &&, uint32_t, uint64_t > Log
Callback wrapper specialized for the simulation logging callback.
Definition: dqcsim:6985
dqcsim::wrap::GateMap::with_unitary
GateMap && with_unitary(const Unbound &key, const Matrix &matrix, int num_controls=-1, double epsilon=0.000001, bool ignore_global_phase=true)
Adds a unitary gate mapping for the given unitary matrix.
Definition: dqcsim:4970
dqcsim::wrap::callback::Initialize
Callback< void, PluginState &, ArbCmdQueue && > Initialize
Callback wrapper specialized for the initialize callback.
Definition: dqcsim:6904
dqcsim::wrap::PluginProcessConfiguration::get_verbosity
Loglevel get_verbosity() const override
Returns the current logging verbosity level of the plugin.
Definition: dqcsim:8876
dqcsim::raw::dqcs_gate_has_controls
dqcs_bool_return_t dqcs_gate_has_controls(dqcs_handle_t gate)
Returns whether the specified gate has control qubits.
dqcsim::wrap::SimulationConfiguration::run
Simulation run(ArbData &&data)
Constructs the DQCsim simulation from this configuration object, and runs a program on the simulated ...
Definition: dqcsim:10400
dqcs_gm_new
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.
dqcsim::wrap::MeasurementSet::MeasurementSet
MeasurementSet(MeasurementSet &&handle)=default
Default move constructor.
dqcsim::wrap::PluginState::get_cycles_between_measures
Cycle get_cycles_between_measures(const QubitRef &qubit)
Returns the number of downstream cycles between the last two measurements of the given downstream qub...
Definition: dqcsim:6651
dqcsim::wrap::PluginProcessConfiguration::without_accept_timeout
PluginProcessConfiguration && without_accept_timeout()
Disables the timeout for the plugin process to connect to DQCsim (builder pattern).
Definition: dqcsim:9023
dqcsim::raw::dqcs_gate_type
dqcs_gate_type_t dqcs_gate_type(dqcs_handle_t gate)
Returns the gate type of the given gate.
dqcsim::wrap::QubitSet::push
void push(const QubitRef &qubit)
Pushes a qubit into the set.
Definition: dqcsim:3062
dqcsim::wrap::HandleType::ArbCmdQueue
@ ArbCmdQueue
Indicates that a handle is an ArbCmdQueue.
DQCS_PATH_STYLE_KEEP
@ DQCS_PATH_STYLE_KEEP
Specifies that paths should be saved the same way they were specified on the command line.
Definition: dqcsim.h:440
dqcsim::wrap::GateMap::with_prep
GateMap && with_prep(const Unbound &key, PauliBasis basis=PauliBasis::Z, double epsilon=0.000001, int num_targets=-1)
Adds a prep gate mapping.
Definition: dqcsim:5246
dqcsim::wrap::PluginConfiguration
Generic class for plugin configurations.
Definition: dqcsim:8542
dqcsim::raw::dqcs_pdef_version
char * dqcs_pdef_version(dqcs_handle_t pdef)
Returns the plugin version for the given plugin definition object.
dqcsim::raw::dqcs_qubit_t
unsigned long long dqcs_qubit_t
Type for a qubit reference.
Definition: cdqcsim:742
dqcsim::wrap::Gate::custom
static Gate custom(const std::string &name, const QubitSet &targets, const QubitSet &controls)
Constructs a new custom gate with target qubits and control qubits.
Definition: dqcsim:4158
dqcsim::wrap::PluginState::measure_x
void measure_x(const QubitSet &qs)
Shorthand for sending a multi-qubit X-axis measurement to the downstream plugin.
Definition: dqcsim:6458
dqcsim::wrap::MeasurementSet::contains
bool contains(const QubitRef &qubit) const
Returns whether the set contains measurement data for the given qubit.
Definition: dqcsim:5956
dqcsim::wrap::Plugin::with_initialize
Plugin && with_initialize(callback::Initialize &&cb)
Assigns the initialize callback function from a pre-existing callback::Initialize object by move.
Definition: dqcsim:7880
dqcsim::wrap::GateMap::with_unitary
GateMap && with_unitary(Unbound &&key, Matrix &&matrix, int num_controls=-1, double epsilon=0.000001, bool ignore_global_phase=true)
Adds a unitary gate mapping for the given unitary matrix.
Definition: dqcsim:4929
dqcsim::raw::dqcs_gate_name
char * dqcs_gate_name(dqcs_handle_t gate)
Returns the name of a custom gate.
dqcsim::raw::dqcs_tcfg_init_cmd
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.
dqcsim::wrap::Matrix::dimension
size_t dimension() const
Returns the number of rows/columns in the matrix.
Definition: dqcsim:3322
dqcsim::wrap::Gate::prep
static Gate prep(QubitSet &&targets, Matrix &&basis)
Constructs a new prep gate for a custom initial state.
Definition: dqcsim:3896
dqcsim::wrap::Arb::get_arb_cbor_string
std::string get_arb_cbor_string() const
Returns the current arbitrary JSON data as a serialized CBOR string.
Definition: dqcsim:1865
dqcsim::raw::dqcs_pcfg_env_unset
dqcs_return_t dqcs_pcfg_env_unset(dqcs_handle_t pcfg, const char *key)
Removes/unsets an environment variable for the plugin process.
dqcsim::wrap::Plugin::with_allocate
Plugin && with_allocate(Args... args)
Assigns the allocate callback function by constructing the callback object implicitly.
Definition: dqcsim:8086
dqcsim::wrap::PluginState::free
void free(const QubitSet &qubits)
Frees the given downstream qubits.
Definition: dqcsim:6290
dqcsim::wrap::Arb::remove_arb_arg
void remove_arb_arg(ssize_t index)
Removes the arbitrary argument at the given index.
Definition: dqcsim:2143
dqcsim::wrap::PluginConfiguration::operator=
PluginConfiguration & operator=(PluginConfiguration &&)=default
Default move assignment.
dqcs_mat_add_controls
dqcs_handle_t dqcs_mat_add_controls(dqcs_handle_t mat, size_t number_of_controls)
Constructs a controlled matrix from the given matrix.
dqcsim::raw::dqcs_qbset_pop
dqcs_qubit_t dqcs_qbset_pop(dqcs_handle_t qbset)
Pops a qubit reference off of a qubit reference set.
dqcsim::wrap::PluginProcessConfiguration::with_shutdown_timeout
PluginProcessConfiguration && with_shutdown_timeout(double timeout)
Configures the timeout for the plugin process to shut down gracefully (builder pattern).
Definition: dqcsim:9065
dqcsim::wrap::MeasurementValue
MeasurementValue
Represents the result of a qubit measurement.
Definition: dqcsim:534
dqcsim::wrap::PluginThreadConfiguration::get_verbosity
Loglevel get_verbosity() const override
Returns the current logging verbosity level of the plugin.
Definition: dqcsim:9205
dqcsim::wrap::PauliBasis::X
@ X
The X basis.
dqcsim::wrap::CustomGateConverter::construct
virtual Gate construct(QubitSet &&qubits, ArbData &&params) const
The to-be-implemented constructor function.
Definition: dqcsim:4596
dqcsim::raw::dqcs_pcfg_accept_timeout_get
double dqcs_pcfg_accept_timeout_get(dqcs_handle_t pcfg)
Returns the configured timeout for the plugin process to connect to DQCsim.
dqcsim::raw::dqcs_pdef_set_modify_measurement_cb
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.
dqcsim::wrap::Arb::get_arb_json_string
std::string get_arb_json_string() const
Returns the current arbitrary JSON data as a serialized JSON string.
Definition: dqcsim:1830
dqcsim::wrap::Plugin::start
PluginJoinHandle start(const char *simulator)
Starts the defined plugin in the current thread.
Definition: dqcsim:8531
dqcsim::raw::dqcs_pdef_set_advance_cb
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.
dqcsim::raw::dqcs_pcfg_shutdown_timeout_set
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.
dqcsim::raw::dqcs_gate_measures
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.
dqcsim::wrap::GateType::Unitary
@ Unitary
Unitary gates have one or more target qubits, zero or more control qubits, and a unitary matrix,...
dqcsim::wrap::Matrix::Matrix
Matrix(size_t num_qubits, const complex *matrix)
Constructs a matrix from a row-major flattened array of 4**num_qubits complexs.
Definition: dqcsim:3186
dqcsim::raw::dqcs_gm_add_custom
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.
dqcsim::wrap::Plugin::with_host_arb
Plugin && with_host_arb(Args... args)
Assigns the host-arb callback function by constructing the callback object implicitly.
Definition: dqcsim:8470
dqcsim::raw::dqcs_cycle_t
long long dqcs_cycle_t
Type for a simulation cycle timestamp.
Definition: cdqcsim:756
dqcsim::raw::dqcs_sim_yield
dqcs_return_t dqcs_sim_yield(dqcs_handle_t sim)
Yields to the simulator.
dqcsim::wrap::MeasurementSet::MeasurementSet
MeasurementSet(MeasurementSet &src)
Copy-constructs a measurement set object.
Definition: dqcsim:6011
dqcsim::wrap::QubitSet
Represents an ordered set of qubit references.
Definition: dqcsim:2982
dqcsim::wrap::PluginState::allocate
QubitRef allocate()
Allocates a single downstream qubit.
Definition: dqcsim:6258
dqcsim::wrap::Gate::with_json
Gate & with_json(const JSON &json)
Sets the arbitrary JSON data to the given JSON object from nlohmann::json (builder pattern).
Definition: dqcsim:4451
dqcsim::wrap::ArbCmd::ArbCmd
ArbCmd(const Cmd &src)
Copy-constructs an ArbCmd object from any object supporting the Cmd interface.
Definition: dqcsim:2491
dqcsim::wrap::PluginConfiguration::log_tee
virtual void log_tee(Loglevel verbosity, const std::string &filename)=0
Configures a plugin thread to also output its log messages to a file.
dqcs_cq_new
dqcs_handle_t dqcs_cq_new(void)
Creates a new ArbCmd queue object.
dqcsim::raw::dqcs_sim_arb
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.
dqcsim::wrap::Gate::Gate
Gate(HandleIndex handle) noexcept
Wraps the given Gate handle.
Definition: dqcsim:3563
DQCS_LOG_DEBUG
@ DQCS_LOG_DEBUG
This loglevel is to be used for reporting debugging information useful for debugging the user of the ...
Definition: dqcsim.h:387
dqcsim::wrap::Gate::custom
static Gate custom(const std::string &name, QubitSet &&targets, QubitSet &&controls)
Constructs a new custom gate with target qubits and control qubits.
Definition: dqcsim:4131
dqcsim::wrap::Arb::clear_arb_args
void clear_arb_args()
Clears the arbitrary argument list.
Definition: dqcsim:2162
dqcsim::wrap::PluginState::measure_y
void measure_y(const QubitSet &qs)
Shorthand for sending a multi-qubit Y-axis measurement to the downstream plugin.
Definition: dqcsim:6517
ARB_BUILDER_SUBCLASS
#define ARB_BUILDER_SUBCLASS
Helper macro to prevent code repetition; not visible outside of the header.
Definition: dqcsim:5699
dqcsim::wrap::HandleType::ArbData
@ ArbData
Indicates that a handle is an ArbData.
dqcsim::wrap::UpstreamPluginState
Wrapper for DQCsim's internal plugin state within the context of upstream-synchronous plugin callback...
Definition: dqcsim:6052
dqcsim::wrap::ArbCmdQueue::copy_into_vector
std::vector< ArbCmd > copy_into_vector()
Copies the queue into a vector of ArbCmds.
Definition: dqcsim:2806
DQCS_GATE_RZ_M90
@ DQCS_GATE_RZ_M90
Rz(-90°) gate.
Definition: dqcsim.h:687
dqcsim::raw::dqcs_gm_detect
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.
dqcsim::wrap::Simulation::send
void send(const ArbData &data)
Sends the given ArbData message to the simulated accelerator (passed by copy).
Definition: dqcsim:9636
dqcsim::wrap::ArbData::with_cbor_string
ArbData & with_cbor_string(const std::string &cbor)
Sets the arbitrary JSON data to the given serialized CBOR string (builder pattern).
Definition: dqcsim:2297
dqcsim::wrap::GateMap
Gate map wrapper class.
Definition: dqcsim:4750
dqcsim::raw::dqcs_pcfg_env_set
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.
dqcsim::wrap::Measurement::with_json
Measurement & with_json(const JSON &json)
Sets the arbitrary JSON data to the given JSON object from nlohmann::json (builder pattern).
Definition: dqcsim:5741
dqcsim::wrap::Matrix::operator=
Matrix & operator=(Matrix &&)=default
Default move assignment.
dqcsim::wrap::Plugin::with_run
Plugin && with_run(callback::Run &&cb)
Assigns the run callback function from a pre-existing callback::Run object by move.
Definition: dqcsim:8008
dqcsim::raw::dqcs_tcfg_new
dqcs_handle_t dqcs_tcfg_new(dqcs_handle_t pdef, const char *name)
Creates a new plugin thread configuration object from a plugin definition.
dqcsim::wrap::Matrix::Matrix
Matrix(size_t num_qubits, const double *matrix)
Constructs a matrix from a row-major flattened array of 2 * 4**num_qubits complexs.
Definition: dqcsim:3202
dqcsim::wrap::GateMap::construct
Gate construct(const Unbound &unbound, QubitSet &&qubits, ArbData &&params)
Uses a gate map object to construct a DQCsim gate from the plugin's representation.
Definition: dqcsim:5451
dqcsim::wrap::Plugin::Operator
static Plugin Operator(const std::string &name, const std::string &author, const std::string &version)
Shorthand for constructing a new operator plugin.
Definition: dqcsim:7659
dqcsim::wrap::GateMap::convert
Gate convert(const Bound &bound)
Wrapper function for construct(), converting directly from the plugin's Bound gate type to DQCsim's g...
Definition: dqcsim:5563
dqcsim::wrap::SimulationConfiguration::SimulationConfiguration
SimulationConfiguration(SimulationConfiguration &&)=default
Default move constructor.
dqcsim::wrap::MeasurementSet::remove
void remove(const QubitRef &qubit)
Removes the measurement object for the given qubit from the set.
Definition: dqcsim:5934
dqcsim::raw::dqcs_gate_has_measures
dqcs_bool_return_t dqcs_gate_has_measures(dqcs_handle_t gate)
Returns whether the specified gate measures any qubits.
dqcsim::wrap::Handle::Handle
Handle() noexcept
Constructs an empty wrapper.
Definition: dqcsim:1634
dqcsim::raw::dqcs_plugin_advance
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.
dqcsim::wrap::PluginState::get_measurement
Measurement get_measurement(const QubitRef &qubit)
Returns the latest measurement of the given downstream qubit.
Definition: dqcsim:6624
dqcsim::wrap::log_raw
bool log_raw(wrap::Loglevel level, const std::string &module, const std::string &file, unsigned int line_nr, const std::string &message) noexcept
Shim around the dqcs_log_raw C API using std::string for the strings.
Definition: dqcsim:1495
dqcsim::wrap::SimulationConfiguration::SimulationConfiguration
SimulationConfiguration()
Creates a new simulation configuration.
Definition: dqcsim:9883
dqcsim::raw::dqcs_arb_insert_raw
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.
dqcsim::wrap::HandleType::Measurement
@ Measurement
Indicates that a handle is a Measurement.
dqcsim::wrap::GateMap::with_prep
GateMap && with_prep(const Unbound &key, const Matrix &basis, double epsilon=0.000001, int num_targets=-1)
Adds a prep gate mapping.
Definition: dqcsim:5316
dqcsim::wrap::Gate::prep
static Gate prep(QubitSet &&targets)
Constructs a new Z-axis prep gate, putting the qubits in the |0> state.
Definition: dqcsim:3842
dqcsim::wrap::SimulationConfiguration::set_log_callback
void set_log_callback(Loglevel verbosity, Args... args)
Configures DQCsim to also output its log messages to callback function.
Definition: dqcsim:10265
dqcsim::wrap::SimulationConfiguration::with_stderr_verbosity
SimulationConfiguration && with_stderr_verbosity(Loglevel level)
Configures the stderr sink verbosity for a simulation (builder pattern).
Definition: dqcsim:10119
DQCS_GATE_PAULI_I
@ DQCS_GATE_PAULI_I
The identity gate for a single qubit.
Definition: dqcsim.h:494
dqcsim::raw::dqcs_cmd_iface_get
char * dqcs_cmd_iface_get(dqcs_handle_t cmd)
Returns the interface ID of an ArbCmd.
dqcsim::raw::dqcs_sim_write_reproduction_file
dqcs_return_t dqcs_sim_write_reproduction_file(dqcs_handle_t sim, const char *filename)
Writes a reproduction file for the simulation so far.
dqcsim::wrap::callback::ModifyMeasurement
Callback< MeasurementSet, UpstreamPluginState &, Measurement && > ModifyMeasurement
Callback wrapper specialized for the modify_measurement callback.
Definition: dqcsim:6934
DQCS_GATE_RY
@ DQCS_GATE_RY
The matrix for an arbitrary Y rotation.
Definition: dqcsim.h:732
dqcsim::wrap::ArbCmd::ArbCmd
ArbCmd(ArbCmd &&)=default
Default move constructor.
dqcsim::wrap::SimulationConfiguration::get_seed
uint64_t get_seed() const noexcept
Returns the configured random seed.
Definition: dqcsim:9978
dqcsim::wrap::Matrix::operator=
void operator=(const Matrix &src)
Copy assignment operator for matrices.
Definition: dqcsim:3290
dqcsim::wrap::Simulation::start
void start(const ArbData &data)
Starts a program on the simulated accelerator using the given ArbData object as an argument (passed b...
Definition: dqcsim:9531
dqcsim::wrap::MeasurementSet::with
MeasurementSet && with(Measurement &&measurement)
Moves the given measurement object into the set (builder pattern).
Definition: dqcsim:5864
dqcsim::wrap::SimulationConfiguration::operator=
SimulationConfiguration & operator=(SimulationConfiguration &&)=default
Default move assignment.
dqcsim::raw::dqcs_pcfg_executable
char * dqcs_pcfg_executable(dqcs_handle_t pcfg)
Returns the configured executable path for the given plugin process.
dqcsim::raw::dqcs_gm_add_custom_unitary
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.
dqcsim::raw::dqcs_qbset_push
dqcs_return_t dqcs_qbset_push(dqcs_handle_t qbset, dqcs_qubit_t qubit)
Pushes a qubit reference into a qubit reference set.
dqcsim::wrap::ArbCmd::with_json
ArbCmd & with_json(const JSON &json)
Sets the arbitrary JSON data to the given JSON object from nlohmann::json (builder pattern).
Definition: dqcsim:2583
dqcsim::raw::dqcs_handle_type_t::DQCS_HTYPE_INVALID
@ DQCS_HTYPE_INVALID
Indicates that the given handle is invalid.
dqcsim::wrap::Matrix::get_as_doubles
std::vector< double > get_as_doubles() const
Returns the data contained by the matrix in row-major form as pairs of real/imag doubles.
Definition: dqcsim:3358
dqcsim::raw::dqcs_gate_has_matrix
dqcs_bool_return_t dqcs_gate_has_matrix(dqcs_handle_t gate)
Returns whether a unitary matrix is associated with this gate.
dqcsim::wrap::Plugin::with_free
Plugin && with_free(const callback::Free &cb)
Assigns the free callback function from a pre-existing callback::Free object by copy.
Definition: dqcsim:8122
dqcsim::wrap::Cmd
Class wrapper for handles that support the cmd interface.
Definition: dqcsim:2362
dqcsim::wrap::ArbCmd::operator=
ArbCmd & operator=(ArbCmd &&)=default
Default move assignment.
DQCS_HTYPE_FRONT_THREAD_CONFIG
@ DQCS_HTYPE_FRONT_THREAD_CONFIG
Indicates that the given handle belongs to a frontend plugin thread configuration object.
Definition: dqcsim.h:274
dqcsim::raw::dqcs_plugin_arb
dqcs_handle_t dqcs_plugin_arb(dqcs_plugin_state_t plugin, dqcs_handle_t cmd)
Sends an arbitrary command downstream.
dqcsim::wrap::Matrix::size
size_t size() const
Returns the number of elements in the matrix.
Definition: dqcsim:3312
dqcsim::wrap::ArbData::with_json_string
ArbData & with_json_string(const std::string &json)
Sets the arbitrary JSON data to the given serialized JSON string (builder pattern).
Definition: dqcsim:2283
dqcsim::wrap::SimulationConfiguration::get_stderr_verbosity
Loglevel get_stderr_verbosity() const
Returns the configured stderr sink verbosity for a simulation.
Definition: dqcsim:10134
DQCS_HTYPE_OPER_THREAD_CONFIG
@ DQCS_HTYPE_OPER_THREAD_CONFIG
Indicates that the given handle belongs to an operator plugin thread configuration object.
Definition: dqcsim.h:282
dqcsim::wrap::Simulation::get_author
std::string get_author(ssize_t index)
Queries the author of a plugin, referenced by index.
Definition: dqcsim:9809
dqcsim::wrap::ArbData::ArbData
ArbData(const Arb &src)
Copy-constructs an ArbData object from any object supporting the Arb interface.
Definition: dqcsim:2233
DQCS_HTYPE_ARB_CMD
@ DQCS_HTYPE_ARB_CMD
Indicates that the given handle belongs to an ArbCmd object.
Definition: dqcsim.h:194
dqcsim::wrap::Cmd::get_iface
std::string get_iface() const
Returns the interface identifier of this command.
Definition: dqcsim:2382
dqcsim::wrap::Plugin::with_run
Plugin && with_run(Args... args)
Assigns the run callback function by constructing the callback object implicitly.
Definition: dqcsim:8022
dqcsim::wrap::GateMap::GateMap
GateMap(GateMap &&)=default
Default move constructor.
DQCS_HTYPE_QUBIT_SET
@ DQCS_HTYPE_QUBIT_SET
Indicates that the given handle belongs to a set of qubit references.
Definition: dqcsim.h:208
dqcsim::wrap::MeasurementSet::set
void set(const Measurement &measurement)
Copies the given measurement object into the set.
Definition: dqcsim:5850
dqcsim::wrap::Handle::is_valid
bool is_valid() const noexcept
Returns whether this wrapper (still) contains a valid handle.
Definition: dqcsim:1678
dqcsim::wrap::Plugin::with_advance
Plugin && with_advance(Args... args)
Assigns the advance callback function by constructing the callback object implicitly.
Definition: dqcsim:8342
DQCS_LOG_FATAL
@ DQCS_LOG_FATAL
This loglevel is to be used for reporting a fatal error, resulting from the owner of the logger getti...
Definition: dqcsim.h:353
dqcsim::wrap::ArbCmdQueue::push
void push(ArbCmd &&cmd)
Pushes an ArbCmd into the queue by moving.
Definition: dqcsim:2681
dqcsim::wrap::PluginState::allocate
QubitRef allocate(ArbCmdQueue &cmds)
Allocates a single downstream qubit, moving in the given command queue as arbitrary additional data f...
Definition: dqcsim:6243
dqcsim::wrap::SimulationConfiguration::with_plugin
SimulationConfiguration && with_plugin(PluginConfiguration &&plugin)
Appends a plugin to a simulation configuration (builder pattern).
Definition: dqcsim:9935
dqcsim::wrap::ArbCmd::ArbCmd
ArbCmd(HandleIndex handle) noexcept
Wraps the given ArbCmd handle.
Definition: dqcsim:2467
dqcsim::wrap::PluginState::measure_z
void measure_z(const QubitSet &qs)
Shorthand for sending a multi-qubit Z-axis measurement to the downstream plugin.
Definition: dqcsim:6571
dqcsim::wrap::callback::Gate
Callback< MeasurementSet, PluginState &, Gate && > Gate
Callback wrapper specialized for the gate callback.
Definition: dqcsim:6929
dqcsim::raw::dqcs_sim_wait
dqcs_handle_t dqcs_sim_wait(dqcs_handle_t sim)
Waits for the simulated accelerator to finish its current program.
dqcsim::raw::dqcs_mat_dimension
ssize_t dqcs_mat_dimension(dqcs_handle_t mat)
Returns the dimension (number of rows == number of columns) of the given matrix.
dqcsim::wrap::ArbCmdQueue::ArbCmdQueue
ArbCmdQueue(ArbCmdQueue &&)=default
Default move constructor.
dqcsim::wrap::QubitSet::drain_into_vector
std::vector< QubitRef > drain_into_vector()
Drains the qubit set into a vector.
Definition: dqcsim:3122
dqcsim::wrap::Matrix::Matrix
Matrix(PredefinedGate gate)
Constructs a non-parameterized predefined matrix.
Definition: dqcsim:3214
dqcsim::wrap::PluginJoinHandle
Class wrapper for plugin join handles.
Definition: dqcsim:7333
dqcsim::wrap::GateType::Measurement
@ Measurement
Measurement gates have one or more measured qubits and a 2x2 unitary matrix representing the basis.
dqcsim::wrap::Arb::get_arb_arg_count
size_t get_arb_arg_count() const
Returns the number of arbitrary arguments.
Definition: dqcsim:2153
dqcsim::raw::dqcs_plugin_get_cycles_between_measures
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...
dqcsim::wrap::PluginConfigurationBuilder::with_spec
PluginProcessConfiguration with_spec(const std::string &spec)
Builds a plugin process configuration object from a "sugared" plugin specification string,...
Definition: dqcsim:9288
dqcsim::wrap::ArbCmdQueue::operator=
ArbCmdQueue & operator=(ArbCmdQueue &src)
Copy-assigns a queue of ArbCmds.
Definition: dqcsim:2840
dqcsim::wrap::PluginProcessConfiguration::with_env_var
PluginProcessConfiguration && with_env_var(const std::string &key, const std::string &value)
Overrides an environment variable for the plugin process (builder pattern).
Definition: dqcsim:8773
dqcsim::wrap::PluginConfiguration::get_verbosity
virtual Loglevel get_verbosity() const =0
Returns the current logging verbosity level of the plugin.
dqcsim::wrap::Arb::get_arb_arg_as
T get_arb_arg_as(ssize_t index) const
Returns the arbitrary argument at the given index as the given type.
Definition: dqcsim:1964
dqcsim::raw::dqcs_scfg_log_callback
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.
dqcsim::raw::dqcs_bool_return_t
dqcs_bool_return_t
Return type for functions that normally return a boolean but can also fail.
Definition: cdqcsim:91
dqcsim::raw::dqcs_predefined_gate_t
dqcs_predefined_gate_t
Enumeration of gates defined by DQCsim.
Definition: cdqcsim:375
dqcsim::wrap::Plugin::Plugin
Plugin(HandleIndex handle) noexcept
Wraps the given plugin definition handle.
Definition: dqcsim:7605
DQCS_GATE_PAULI_Z
@ DQCS_GATE_PAULI_Z
The Pauli Z matrix.
Definition: dqcsim.h:527
dqcsim::wrap::PluginState::allocate
QubitSet allocate(size_t num_qubits, ArbCmdQueue &cmds)
Allocates a number of downstream qubits, moving in the given command queue as arbitrary additional da...
Definition: dqcsim:6186
dqcsim::wrap::GateMap::with_custom
GateMap && with_custom(Unbound &&key, const std::shared_ptr< CustomGateConverter > &converter)
Adds a custom gate mapping.
Definition: dqcsim:5347
dqcsim::raw::dqcs_meas_qubit_get
dqcs_qubit_t dqcs_meas_qubit_get(dqcs_handle_t meas)
Returns the qubit reference associated with a measurement object.
DQCS_HTYPE_OPER_DEF
@ DQCS_HTYPE_OPER_DEF
Indicates that the given handle belongs to an operator plugin definition object.
Definition: dqcsim.h:317
dqcsim::wrap::PluginProcessConfiguration::PluginProcessConfiguration
PluginProcessConfiguration(PluginProcessConfiguration &&)=default
Default move constructor.
dqcsim::raw::dqcs_measurement_t
dqcs_measurement_t
Qubit measurement value.
Definition: cdqcsim:335
dqcsim::wrap::MeasurementSet::MeasurementSet
MeasurementSet(HandleIndex handle) noexcept
Wraps the given measurement set handle.
Definition: dqcsim:5800
DQCS_FALSE
@ DQCS_FALSE
The function did what it was supposed to and returned false.
Definition: dqcsim.h:86
dqcsim::wrap::MeasurementSet::copy_into_vector
std::vector< Measurement > copy_into_vector()
Copies the qubit set into a vector.
Definition: dqcsim:5992
dqcsim::wrap::ArbData::with_json
ArbData & with_json(const JSON &json)
Sets the arbitrary JSON data to the given JSON object from nlohmann::json (builder pattern).
Definition: dqcsim:2314
dqcsim::wrap::Cycle
raw::dqcs_cycle_t Cycle
C++-styled type name for raw::dqcs_cycle_t.
Definition: dqcsim:115
dqcsim::wrap::PluginProcessConfiguration::PluginProcessConfiguration
PluginProcessConfiguration(HandleIndex handle) noexcept
Wraps the given plugin process configuration handle.
Definition: dqcsim:8651
dqcsim::wrap::PluginConfiguration::PluginConfiguration
PluginConfiguration(PluginConfiguration &&)=default
Default move constructor.
dqcsim::wrap::ArbCmdQueue::push
void push(const Cmd &cmd)
Pushes an ArbCmd into the queue by copying.
Definition: dqcsim:2692
dqcsim::raw::dqcs_loglevel_t::DQCS_LOG_INVALID
@ DQCS_LOG_INVALID
Invalid loglevel.
dqcsim::wrap::SimulationConfiguration::without_reproduction
SimulationConfiguration && without_reproduction()
Disables the reproduction logging system (builder pattern).
Definition: dqcsim:10053
dqcsim::wrap::GateMap::GateMap
GateMap(bool strip_qubit_refs=false, bool strip_data=false)
Constructs a new gate map.
Definition: dqcsim:4807
dqcsim::wrap::PluginState::measure_x
void measure_x(const QubitRef &q)
Shorthand for sending a single-qubit X-axis measurement to the downstream plugin.
Definition: dqcsim:6430
dqcsim::wrap::PluginConfigurationBuilder::with_spawner
PluginThreadConfiguration with_spawner(callback::SpawnPlugin &&data)
Builds a plugin thread configuration object using a single callback that spawns the entire plugin.
Definition: dqcsim:9395
dqcsim::raw::dqcs_log_raw
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.
dqcsim::wrap::QubitSet::QubitSet
QubitSet(const QubitSet &src)
Copy-constructs a qubit set.
Definition: dqcsim:3028
dqcsim::wrap::Measurement::Measurement
Measurement(const QubitRef &qubit, MeasurementValue value)
Constructs a measurement object.
Definition: dqcsim:5614
DQCS_GATE_T
@ DQCS_GATE_T
The T matrix, also known as a 45 degree Z rotation.
Definition: dqcsim.h:572
DQCS_LOG_NOTE
@ DQCS_LOG_NOTE
This loglevel is to be used for reporting information specifically requested by the user/API caller,...
Definition: dqcsim.h:376
dqcsim::wrap::PluginState::measure_z
void measure_z(QubitSet &&qs)
Shorthand for sending a multi-qubit Z-axis measurement to the downstream plugin.
Definition: dqcsim:6554
dqcsim::raw::dqcs_plugin_allocate
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.
dqcsim::wrap::SimulationConfiguration::with_log_callback
SimulationConfiguration && with_log_callback(Loglevel verbosity, callback::Log &&data)
Configures DQCsim to also output its log messages to callback function (builder pattern).
Definition: dqcsim:10314
dqcsim::wrap::Simulation::run
ArbData run(const ArbData &data)
Runs a program on the simulated accelerator using the given ArbData object as an argument (passed by ...
Definition: dqcsim:9595
dqcsim::wrap::RunningPluginState::send
void send(ArbData &&message)
Sends a message to the host.
Definition: dqcsim:6706
dqcsim::raw::dqcs_pcfg_script
char * dqcs_pcfg_script(dqcs_handle_t pcfg)
Returns the configured script path for the given plugin process.
dqcsim::raw::dqcs_plugin_free
dqcs_return_t dqcs_plugin_free(dqcs_plugin_state_t plugin, dqcs_handle_t qbset)
Free the given downstream qubits.
DQCS_PATH_STYLE_RELATIVE
@ DQCS_PATH_STYLE_RELATIVE
Specifies that all paths should be saved relative to DQCsim's working directory.
Definition: dqcsim.h:445
dqcsim::raw::dqcs_scfg_seed_get
uint64_t dqcs_scfg_seed_get(dqcs_handle_t scfg)
Returns the configured random seed.
dqcsim::wrap::QubitSet::QubitSet
QubitSet(QubitSet &&)=default
Default move constructor.
dqcsim::wrap::Gate::with_cbor_string
Gate & with_cbor_string(const std::string &cbor)
Sets the arbitrary JSON data to the given serialized CBOR string (builder pattern).
Definition: dqcsim:4434
dqcsim::wrap::ArbCmd
Class wrapper for ArbCmd handles.
Definition: dqcsim:2456
dqcsim::wrap::ArbData::with_arg_string
ArbData & with_arg_string(const std::string &data)
Pushes a (binary) string to the back of the arbitrary argument list (builder pattern).
Definition: dqcsim:2328
dqcsim::raw::dqcs_handle_type
dqcs_handle_type_t dqcs_handle_type(dqcs_handle_t handle)
Returns the type of object associated with the given handle.
dqcsim::wrap::SimulationConfiguration::with_dqcsim_verbosity
SimulationConfiguration && with_dqcsim_verbosity(Loglevel level)
Configures the logging verbosity for DQCsim's own messages (builder pattern).
Definition: dqcsim:10078
dqcsim::raw::dqcs_pdef_author
char * dqcs_pdef_author(dqcs_handle_t pdef)
Returns the plugin author for the given plugin definition object.
dqcsim::raw::dqcs_plugin_get_cycles_since_measure
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.
dqcsim::wrap::ArbCmdQueue::with
ArbCmdQueue && with(ArbCmd &&cmd)
Pushes an ArbCmd into the queue by moving (builder pattern).
Definition: dqcsim:2740
dqcsim::wrap::Measurement::with_arg_string
Measurement & with_arg_string(const std::string &data)
Pushes a (binary) string to the back of the arbitrary argument list (builder pattern).
Definition: dqcsim:5755
dqcsim::wrap::Cmd::get_oper
std::string get_oper() const
Returns the operation identifier of this command.
Definition: dqcsim:2406
dqcsim::wrap::PluginConfigurationBuilder::with_spawner
PluginThreadConfiguration with_spawner(Args... args)
Builds a plugin thread configuration object using a single callback that spawns the entire plugin.
Definition: dqcsim:9416
dqcsim::wrap::PluginConfiguration::get_name
virtual std::string get_name() const =0
Returns the name given to the plugin.
dqcsim::wrap::Matrix::is_predefined
bool is_predefined(PredefinedGate gate, double epsilon=0.000001, bool ignore_global_phase=true, ArbData *parameters=nullptr) const
Detects whether this matrix is approximately equal to (some parameterization of) the given predefined...
Definition: dqcsim:3449
dqcsim::wrap::check
void check(raw::dqcs_return_t code)
Checks a dqcs_return_t return value; if failure, throws a runtime error with DQCsim's error message.
Definition: dqcsim:124
dqcsim::wrap::Matrix::num_qubits
size_t num_qubits() const
Returns the number of qubits associated with the matrix.
Definition: dqcsim:3332
dqcsim::wrap::Gate::prep
static Gate prep(const QubitSet &targets, const Matrix &basis)
Constructs a new prep gate for a custom initial state.
Definition: dqcsim:3910
dqcsim::raw::dqcs_mat_num_qubits
ssize_t dqcs_mat_num_qubits(dqcs_handle_t mat)
Returns the number of qubits targeted by the given matrix.
DQCS_GATE_T_DAG
@ DQCS_GATE_T_DAG
The T-dagger matrix, also known as a negative 45 degree Z rotation.
Definition: dqcsim.h:583
dqcsim::wrap::PredefinedGate::I
@ I
The identity gate for a single qubit.
dqcsim::wrap::PluginState
Wrapper for DQCsim's internal plugin state within the context of downstream-synchronous plugin callba...
Definition: dqcsim:6128
dqcsim::raw::dqcs_mset_take
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 ...
dqcsim::raw::dqcs_basis_t::DQCS_BASIS_INVALID
@ DQCS_BASIS_INVALID
Invalid basis. Used as an error return value.
dqcsim::wrap::QubitSet::operator=
void operator=(const QubitSet &src)
Copy assignment operator for qubit sets.
Definition: dqcsim:3039
dqcsim::wrap::SimulationConfiguration::get_reproduction_style
PathStyle get_reproduction_style() const
Returns the path style used when writing reproduction files.
Definition: dqcsim:10026
dqcsim::wrap::Gate::has_measures
bool has_measures() const
Returns whether this gate has measurement qubits.
Definition: dqcsim:4357
dqcsim::raw::dqcs_arb_get_size
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.
dqcsim::wrap::callback::SpawnPlugin
Callback< void, std::string && > SpawnPlugin
Callback wrapper specialized for the manual plugin spawning callback.
Definition: dqcsim:6949
dqcsim::wrap::Gate::with_arg
Gate & with_arg(const T &data)
Pushes a value of type T to the back of the arbitrary argument list (builder pattern).
Definition: dqcsim:4485
dqcsim::raw::dqcs_path_style_t
dqcs_path_style_t
Reproduction file path style.
Definition: cdqcsim:347
dqcsim::wrap::complex
std::complex< double > complex
Typedef for the complex numbers used within the gate matrices.
Definition: dqcsim:3151
DQCS_GATE_RZ_90
@ DQCS_GATE_RZ_90
Rz(90°) gate.
Definition: dqcsim.h:672
dqcsim::wrap::PluginProcessConfiguration::without_env_var
PluginProcessConfiguration && without_env_var(const std::string &key)
Removes/unsets an environment variable for the plugin process (builder pattern).
Definition: dqcsim:8804
DQCS_GATE_RY_M90
@ DQCS_GATE_RY_M90
Ry(-90°) gate.
Definition: dqcsim.h:642
dqcs_scfg_new
dqcs_handle_t dqcs_scfg_new(void)
Constructs an empty simulation configuration.
DQCS_GATE_PHASE_K
@ DQCS_GATE_PHASE_K
The matrix for a Z rotation with angle π/2^k.
Definition: dqcsim.h:762
dqcsim::wrap::Gate::measure
static Gate measure(const QubitSet &measures, const Matrix &basis)
Constructs a new measurement gate, measuring in the given custom basis.
Definition: dqcsim:3830
dqcsim::raw::dqcs_gm_add_measure
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.
dqcsim::raw::dqcs_plugin_type_t
dqcs_plugin_type_t
Enumeration of the three types of plugins.
Definition: cdqcsim:362
dqcsim::wrap::PluginProcessConfiguration::without_shutdown_timeout
PluginProcessConfiguration && without_shutdown_timeout()
Disables the timeout for the plugin process to shut down gracefully (builder pattern).
Definition: dqcsim:9077
dqcsim::wrap::Gate::has_targets
bool has_targets() const
Returns whether this gate has target qubits.
Definition: dqcsim:4313
dqcsim::raw::dqcs_arb_pop_raw
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.
dqcsim::raw::dqcs_pcfg_new_raw
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.
dqcsim::raw::dqcs_plugin_get_measurement
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.
dqcsim::wrap::Arb::Arb
Arb(HandleIndex handle) noexcept
Wraps the given arb handle.
Definition: dqcsim:1821
dqcsim::wrap::Arb::get_arb_json
JSON get_arb_json() const
Returns the current arbitrary JSON data as a JSON object from nlohmann::json.
Definition: dqcsim:1903
dqcsim::wrap::Gate::custom
static Gate custom(const std::string &name, const QubitSet &targets, const QubitSet &controls, const QubitSet &measures, const Matrix &matrix)
Constructs a new custom gate with target qubits, control qubits, measured qubits, and a matrix.
Definition: dqcsim:3975
dqcsim::raw::dqcs_mset_get
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.
dqcsim::raw::dqcs_sim_get_name_idx
char * dqcs_sim_get_name_idx(dqcs_handle_t sim, ssize_t index)
Queries the implementation name of a plugin, referenced by index.
dqcsim::wrap::Simulation::get_name
std::string get_name(const std::string &name)
Queries the class name of a plugin, referenced by instance name.
Definition: dqcsim:9756
dqcsim::wrap::Simulation::send
void send(ArbData &&data)
Sends the given ArbData message to the simulated accelerator (passed by move).
Definition: dqcsim:9622
DQCS_BASIS_INVALID
@ DQCS_BASIS_INVALID
Invalid basis.
Definition: dqcsim.h:38
dqcsim::wrap::Gate::prep
static Gate prep(const QubitSet &targets, PauliBasis basis)
Constructs a new prep gate, putting the qubits in the base state for the given Pauli basis.
Definition: dqcsim:3882
dqcsim::wrap::Handle::Handle
Handle(HandleIndex handle) noexcept
Wraps the given raw handle.
Definition: dqcsim:1645
dqcsim::wrap::RunningPluginState
Wrapper for DQCsim's internal plugin state within the context of the run callback in a frontend.
Definition: dqcsim:6675
dqcsim::wrap::MeasurementSet::with
MeasurementSet && with(const Measurement &measurement)
Copies the given measurement object into the set (builder pattern).
Definition: dqcsim:5879
dqcsim::raw::dqcs_error_set
void dqcs_error_set(const char *msg)
Sets the latest error message string.
dqcsim::wrap::Plugin::with_initialize
Plugin && with_initialize(const callback::Initialize &cb)
Assigns the initialize callback function from a pre-existing callback::Initialize object by copy.
Definition: dqcsim:7866
dqcsim::wrap::PluginProcessConfiguration::set_shutdown_timeout
void set_shutdown_timeout(double timeout)
Configures the timeout for the plugin process to shut down gracefully.
Definition: dqcsim:9049
dqcsim::wrap::Simulation::run
ArbData run(ArbData &&data)
Runs a program on the simulated accelerator using the given ArbData object as an argument (passed by ...
Definition: dqcsim:9577
dqcsim::wrap::Plugin::with_modify_measurement
Plugin && with_modify_measurement(Args... args)
Assigns the modify-measurement callback function by constructing the callback object implicitly.
Definition: dqcsim:8278
dqcsim::wrap::Gate::measure
static Gate measure(QubitSet &&measures, Matrix &&basis)
Constructs a new measurement gate, measuring in the given custom basis.
Definition: dqcsim:3813
DQCSIM_FATAL
#define DQCSIM_FATAL(fmt,...)
Convenience macro for calling log() with fatal loglevel and automatically determined filename and lin...
Definition: dqcsim:1594
dqcsim::raw::dqcs_pcfg_work_get
char * dqcs_pcfg_work_get(dqcs_handle_t pcfg)
Returns the configured working directory for the given plugin process.
dqcsim::wrap::Plugin::with_advance
Plugin && with_advance(callback::Advance &&cb)
Assigns the advance callback function from a pre-existing callback::Advance object by move.
Definition: dqcsim:8328
dqcsim::wrap::Simulation::write_reproduction_file
void write_reproduction_file(const std::string &filename)
Writes a reproduction file for the simulation so far.
Definition: dqcsim:9857
dqcsim::wrap::SimulationConfiguration::get_dqcsim_verbosity
Loglevel get_dqcsim_verbosity() const
Returns the configured verbosity for DQCsim's own messages.
Definition: dqcsim:10090
DQCS_GATE_PAULI_Y
@ DQCS_GATE_PAULI_Y
The Pauli Y matrix.
Definition: dqcsim.h:516
dqcsim::wrap::Backend
PluginConfigurationBuilder Backend(const std::string &name="") noexcept
Shorthand for constructing a backend plugin configuration builder.
Definition: dqcsim:9454
dqcsim::wrap::Simulation::get_author
std::string get_author(const std::string &name)
Queries the author of a plugin, referenced by instance name.
Definition: dqcsim:9790
dqcsim::wrap::SimulationConfiguration::set_seed
void set_seed(uint64_t seed)
Configures the random seed that the simulation should use.
Definition: dqcsim:9949
dqcsim::wrap::Gate::measure
static Gate measure(QubitSet &&measures)
Constructs a new Z-axis measurement gate.
Definition: dqcsim:3749
dqcsim::wrap::Handle::type
HandleType type() const
Returns the type of this handle.
Definition: dqcsim:1799
dqcsim::wrap::Gate
Represents any kind of gate with qubits bound to it.
Definition: dqcsim:3552
dqcsim::wrap::Gate::get_targets
QubitSet get_targets() const
Returns a new qubit reference set with the target qubits for this gate.
Definition: dqcsim:4303
dqcsim::wrap::Simulation::get_name
std::string get_name(ssize_t index)
Queries the class name of a plugin, referenced by index.
Definition: dqcsim:9775
dqcsim::raw::dqcs_plugin_random_u64
dqcs_handle_t dqcs_plugin_random_u64(dqcs_plugin_state_t plugin)
Generates a random unsigned 64-bit number using the simulator random seed.
dqcsim::raw::dqcs_sim_arb_idx
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.
dqcsim::raw::dqcs_sim_get_name
char * dqcs_sim_get_name(dqcs_handle_t sim, const char *name)
Queries the implementation name of a plugin, referenced by instance name.
dqcsim::wrap::CustomUnitaryGateConverter::detect
virtual bool detect(Matrix &&matrix, ssize_t num_controls, ArbData &params) const
The to-be-implemented detector function.
Definition: dqcsim:4688
dqcsim::wrap::Callback::Callback
Callback(std::function< R(Args...)> &&cb) noexcept
Constructs the callback wrapper by moving a std::function.
Definition: dqcsim:6862
dqcsim::raw::dqcs_plugin_random_f64
double dqcs_plugin_random_f64(dqcs_plugin_state_t plugin)
Generates a random floating point number using the simulator random seed.
dqcsim::wrap::MeasurementSet::get
Measurement get(const QubitRef &qubit) const
Returns a copy of the measurement object for the given qubit.
Definition: dqcsim:5894
DQCS_GATE_SWAP
@ DQCS_GATE_SWAP
The swap gate matrix.
Definition: dqcsim.h:831
dqcsim::wrap::Simulation::wait
ArbData wait()
Waits for the simulated accelerator to finish its current program.
Definition: dqcsim:9544
dqcsim::wrap::QubitRef::QubitRef
QubitRef(QubitRef &&)=default
Default move constructor.
DQCS_HTYPE_SIM_CONFIG
@ DQCS_HTYPE_SIM_CONFIG
Indicates that the given handle belongs to a simulator configuration object.
Definition: dqcsim.h:297
dqcsim::raw::dqcs_tcfg_new_raw
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.
dqcsim::wrap::callback::Advance
Callback< void, PluginState &, Cycle > Advance
Callback wrapper specialized for the advance callback.
Definition: dqcsim:6939
dqcsim::wrap::QubitRef::operator==
bool operator==(const QubitRef &other) const noexcept
Qubit reference equality operator.
Definition: dqcsim:2922
dqcsim::wrap::Matrix::approx_unitary
bool approx_unitary(double epsilon=0.000001) const
Approximate unitary check.
Definition: dqcsim:3425
dqcs_mset_new
dqcs_handle_t dqcs_mset_new(void)
Creates a new set of qubit measurement results.
dqcsim::wrap::PluginType::Operator
@ Operator
Operator plugin.
dqcsim::wrap::Arb::insert_arb_arg_string
void insert_arb_arg_string(ssize_t index, const std::string &data)
Inserts an arbitrary argument at the given index using a (binary) string.
Definition: dqcsim:2110
dqcsim::wrap::Matrix
Represents a square matrix used for describing N-qubit gates.
Definition: dqcsim:3160
dqcsim::raw::dqcs_gm_add_predef_unitary
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.
dqcsim::wrap::Simulation::send
void send()
Sends an empty message to the simulated accelerator.
Definition: dqcsim:9608
dqcsim::wrap::Callback::Callback
Callback(const std::function< R(Args...)> &cb) noexcept
Constructs the callback wrapper by copying a std::function.
Definition: dqcsim:6871
dqcsim::raw::dqcs_scfg_repro_disable
dqcs_return_t dqcs_scfg_repro_disable(dqcs_handle_t scfg)
Disables the reproduction logging system.
dqcsim::wrap::ArbCmdQueue::ArbCmdQueue
ArbCmdQueue(HandleIndex handle) noexcept
Wraps the given ArbCmdQueue handle.
Definition: dqcsim:2663
dqcsim::wrap::PathStyle
PathStyle
Represents the possible options for dealing with paths when writing a reproduction file.
Definition: dqcsim:597
dqcsim::raw::dqcs_plugin_start
dqcs_handle_t dqcs_plugin_start(dqcs_handle_t pdef, const char *simulator)
Executes a plugin in a worker thread.
dqcsim::raw::dqcs_measurement_t::DQCS_MEAS_INVALID
@ DQCS_MEAS_INVALID
Error value used to indicate that something went wrong.
dqcsim::wrap::Handle::operator=
Handle & operator=(Handle &&src)
Move constructor; simply moves ownership of the handle from the source object to the assignment targe...
Definition: dqcsim:1748
dqcsim::wrap::PluginProcessConfiguration::get_plugin_type
PluginType get_plugin_type() const override
Returns the plugin type.
Definition: dqcsim:8674
dqcsim::wrap::Handle::free
void free()
Explicitly delete the handle, allowing errors to be caught.
Definition: dqcsim:1668
dqcsim::wrap::GateMap::with_measure
GateMap && with_measure(const Unbound &key, PauliBasis basis=PauliBasis::Z, double epsilon=0.000001, int num_measures=-1)
Adds a measurement gate mapping.
Definition: dqcsim:5106
dqcsim::wrap::Handle::take_handle
HandleIndex take_handle() noexcept
Returns the raw handle and relinquishes ownership.
Definition: dqcsim:1703
dqcsim::wrap::Plugin::get_type
PluginType get_type() const
Returns the plugin type described by this object.
Definition: dqcsim:7706
dqcsim::wrap::PluginProcessConfiguration::operator=
PluginProcessConfiguration & operator=(PluginProcessConfiguration &&)=default
Default move assignment.
dqcsim::wrap::Plugin::with_free
Plugin && with_free(Args... args)
Assigns the free callback function by constructing the callback object implicitly.
Definition: dqcsim:8150
DQCS_LOG_WARN
@ DQCS_LOG_WARN
This loglevel is to be used for reporting that a called API/function is telling us we did something w...
Definition: dqcsim.h:369
dqcsim::wrap::callback::Free
Callback< void, PluginState &, QubitSet && > Free
Callback wrapper specialized for the allocate callback.
Definition: dqcsim:6924
dqcsim::raw::dqcs_cq_push
dqcs_return_t dqcs_cq_push(dqcs_handle_t cq, dqcs_handle_t cmd)
Pushes an ArbCmd object into the given ArbCmd queue.
dqcsim::raw::dqcs_scfg_dqcsim_verbosity_set
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.
dqcsim::wrap::Measurement::with_json_string
Measurement & with_json_string(const std::string &json)
Sets the arbitrary JSON data to the given serialized JSON string (builder pattern).
Definition: dqcsim:5710
dqcsim::wrap::Arb::set_arb_arg_string
void set_arb_arg_string(ssize_t index, const std::string &data)
Sets the arbitrary argument at the given index to a (binary) string.
Definition: dqcsim:2002
dqcsim::wrap::HandleType
HandleType
Represents the type of a raw handle.
Definition: dqcsim:214
dqcsim::wrap::ArbCmd::ArbCmd
ArbCmd(const std::string &iface, const std::string &oper)
Constructs an ArbCmd object.
Definition: dqcsim:2478
dqcsim::raw::dqcs_plugin_type_t::DQCS_PTYPE_INVALID
@ DQCS_PTYPE_INVALID
Invalid plugin type.
dqcsim::raw::dqcs_tcfg_tee
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.
dqcsim::wrap::GateMap::with_prep
GateMap && with_prep(Unbound &&key, Matrix &&basis, double epsilon=0.000001, int num_targets=-1)
Adds a prep gate mapping.
Definition: dqcsim:5281
dqcsim::raw::dqcs_pcfg_name
char * dqcs_pcfg_name(dqcs_handle_t pcfg)
Returns the configured name for the given plugin process.
dqcsim::wrap::ArbData::ArbData
ArbData(const ArbData &src)
Copy-constructs an ArbData object from another ArbData object.
Definition: dqcsim:2244
DQCS_GATE_INVALID
@ DQCS_GATE_INVALID
Invalid gate.
Definition: dqcsim.h:483
dqcsim::wrap::PluginThreadConfiguration::get_plugin_type
PluginType get_plugin_type() const override
Returns the plugin type.
Definition: dqcsim:9132
dqcsim::wrap::PluginConfiguration::add_init_cmd
void add_init_cmd(const ArbCmd &cmd)
Attaches an arbitrary initialization command to the plugin.
Definition: dqcsim:8605
dqcsim::raw::dqcs_gm_add_prep
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.
dqcsim::raw::dqcs_arb_json_get
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.
dqcsim::wrap::Measurement::Measurement
Measurement(const Measurement &src)
Copy-constructs a Measurement object.
Definition: dqcsim:5626
dqcsim::wrap::PluginThreadConfiguration::with_log_tee
PluginThreadConfiguration && with_log_tee(Loglevel verbosity, const std::string &filename)
Configures a plugin thread to also output its log messages to a file (builder pattern).
Definition: dqcsim:9231
dqcsim::wrap::Simulation::Simulation
Simulation(HandleIndex handle) noexcept
Wraps the given simulation handle.
Definition: dqcsim:9472
DQCS_LOG_INVALID
@ DQCS_LOG_INVALID
Invalid loglevel.
Definition: dqcsim.h:342
DQCS_GATE_H
@ DQCS_GATE_H
The hadamard gate matrix.
Definition: dqcsim.h:539
DQCS_GATE_RY_90
@ DQCS_GATE_RY_90
Ry(90°) gate.
Definition: dqcsim.h:631
dqcsim::wrap::Gate::custom
static Gate custom(const std::string &name, QubitSet &&targets, QubitSet &&controls, const Matrix &matrix)
Constructs a new custom gate with target qubits, control qubits, and a matrix.
Definition: dqcsim:4072
dqcsim::wrap::ArbCmdQueue::size
size_t size() const
Returns the number of ArbCmds in the queue.
Definition: dqcsim:2775
dqcsim::wrap::PluginState::gate
void gate(const Matrix &matrix, const QubitRef &q)
Shorthand for sending a single-qubit gate to the downstream plugin.
Definition: dqcsim:6337
DQCS_BASIS_Y
@ DQCS_BASIS_Y
The Y basis.
Definition: dqcsim.h:60
DQCS_GATE_RZ_180
@ DQCS_GATE_RZ_180
Rz(180°) gate.
Definition: dqcsim.h:702
dqcsim::raw::dqcs_gm_construct
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.
dqcsim::raw::dqcs_qbset_contains
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.
dqcsim::wrap::Callback::Callback
Callback(R(*cb)(T, Args...), T user) noexcept
Constructs the callback wrapper from a regular C-style function with a user argument bound to it.
Definition: dqcsim:6841
dqcsim::wrap::Simulation::recv
ArbData recv()
Waits for the simulated accelerator to send a message to us.
Definition: dqcsim:9647
dqcsim::raw::dqcs_scfg_repro_path_style_get
dqcs_path_style_t dqcs_scfg_repro_path_style_get(dqcs_handle_t scfg)
Returns the path style used when writing reproduction files.
dqcsim::wrap::Plugin::get_version
std::string get_version() const
Returns the version of the described plugin.
Definition: dqcsim:7742
dqcsim::wrap::Gate::get_controls
QubitSet get_controls() const
Returns a new qubit reference set with the control qubits for this gate.
Definition: dqcsim:4324
dqcsim::raw::dqcs_gm_add_fixed_unitary
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.
dqcsim::raw::dqcs_sim_get_version_idx
char * dqcs_sim_get_version_idx(dqcs_handle_t sim, ssize_t index)
Queries the version of a plugin, referenced by index.
dqcsim::wrap::PluginThreadConfiguration::operator=
PluginThreadConfiguration & operator=(PluginThreadConfiguration &&)=default
Default move assignment.
dqcsim::raw::dqcs_mat_get
double * dqcs_mat_get(dqcs_handle_t mat)
Returns a copy of the contained matrix as a C array.
dqcsim::wrap::Plugin::with_upstream_arb
Plugin && with_upstream_arb(const callback::Arb &cb)
Assigns the upstream-arb callback function from a pre-existing callback::Arb object by copy.
Definition: dqcsim:8378
dqcsim::raw::dqcs_plugin_wait
dqcs_return_t dqcs_plugin_wait(dqcs_handle_t pjoin)
Waits for a plugin worker thread to finish executing.
dqcsim::wrap::Plugin::with_free
Plugin && with_free(callback::Free &&cb)
Assigns the free callback function from a pre-existing callback::Free object by move.
Definition: dqcsim:8136
dqcsim::wrap::SimulationConfiguration::with_seed
SimulationConfiguration && with_seed(uint64_t seed)
Configures the random seed that the simulation should use (builder pattern).
Definition: dqcsim:9964
dqcsim::wrap::PluginProcessConfiguration::get_accept_timeout
double get_accept_timeout() const
Returns the configured timeout for the plugin process to connect to DQCsim.
Definition: dqcsim:9035
dqcsim::wrap::PluginState::PluginState
PluginState(raw::dqcs_plugin_state_t state)
Hidden constructor, only to be used by the callback wrappers.
Definition: dqcsim:6134
dqcsim::wrap::Measurement
Class representation of the measurement result for a single qubit.
Definition: dqcsim:5592
dqcsim::wrap::PluginThreadConfiguration::PluginThreadConfiguration
PluginThreadConfiguration(HandleIndex handle) noexcept
Wraps the given plugin thread configuration handle.
Definition: dqcsim:9109
dqcsim::wrap::Handle::Handle
Handle(Handle &&src)
Move constructor; simply moves ownership of the handle from the source object to the constructed obje...
Definition: dqcsim:1726
dqcsim::raw::dqcs_handle_delete
dqcs_return_t dqcs_handle_delete(dqcs_handle_t handle)
Destroys the object associated with a handle.
dqcsim::wrap::Gate::unitary
static Gate unitary(QubitSet &&targets, const Matrix &matrix)
Constructs a new custom unitary gate.
Definition: dqcsim:3674
dqcsim::raw::dqcs_gate_new_measurement
dqcs_handle_t dqcs_gate_new_measurement(dqcs_handle_t measures, dqcs_handle_t matrix)
Constructs a new measurement gate.
dqcsim::wrap::Simulation::operator=
Simulation & operator=(Simulation &&)=default
Default move assignment.
dqcsim::wrap::Matrix::Matrix
Matrix(PredefinedGate gate, ArbData &&parameters)
Constructs a predefined matrix, using ArbData to represent the parameters for parameterized gates.
Definition: dqcsim:3242
dqcsim::wrap::Plugin::with_modify_measurement
Plugin && with_modify_measurement(const callback::ModifyMeasurement &cb)
Assigns the modify-measurement callback function from a pre-existing callback::ModifyMeasurement obje...
Definition: dqcsim:8250
dqcsim::wrap::ArbCmd::with_cbor_string
ArbCmd & with_cbor_string(const std::string &cbor)
Sets the arbitrary JSON data to the given serialized CBOR string (builder pattern).
Definition: dqcsim:2566
dqcsim::wrap::Callback
Class template shared between all callback functions.
Definition: dqcsim:6749
dqcsim::wrap::PluginProcessConfiguration::add_init_cmd
void add_init_cmd(ArbCmd &&cmd) override
Attaches an arbitrary initialization command to the plugin.
Definition: dqcsim:8727
dqcsim::raw::dqcs_pcfg_verbosity_set
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_cmd_new
dqcs_handle_t dqcs_cmd_new(const char *iface, const char *oper)
Creates a new ArbCmd object.
dqcsim::wrap::ArbCmdQueue::next
void next()
Pops the first ArbCmd from the queue, allowing the next one to be accessed.
Definition: dqcsim:2765
dqcsim::wrap::QubitSet::from_iter
static QubitSet from_iter(const T &qubits)
Constructs a qubit set object from an iterable of qubit references.
Definition: dqcsim:3013
dqcsim::wrap::Plugin
Plugin definition class.
Definition: dqcsim:7594
DQCS_MEAS_ZERO
@ DQCS_MEAS_ZERO
Indicates that the qubit was measured to be zero.
Definition: dqcsim.h:417
dqcsim::wrap::PluginConfiguration::set_verbosity
virtual void set_verbosity(Loglevel level)=0
Sets the logging verbosity level of the plugin.
dqcsim::wrap::Gate::get_matrix
Matrix get_matrix() const
Returns the matrix that belongs to this gate.
Definition: dqcsim:4368
dqcsim::wrap::SimulationConfiguration::set_reproduction_style
void set_reproduction_style(PathStyle style)
Sets the path style used when writing reproduction files.
Definition: dqcsim:9995
dqcsim::wrap::ArbData
Class wrapper for ArbData handles.
Definition: dqcsim:2202
DQCS_GATE_R
@ DQCS_GATE_R
Arbitrary rotation matrix.
Definition: dqcsim.h:818
DQCS_GATE_PAULI_X
@ DQCS_GATE_PAULI_X
The Pauli X matrix.
Definition: dqcsim.h:505
dqcsim::raw::dqcs_gate_has_targets
dqcs_bool_return_t dqcs_gate_has_targets(dqcs_handle_t gate)
Returns whether the specified gate has target qubits.
DQCS_GATE_TYPE_UNITARY
@ DQCS_GATE_TYPE_UNITARY
Unitary gates have one or more target qubits, zero or more control qubits, and a unitary matrix,...
Definition: dqcsim.h:113
DQCS_HTYPE_BACK_PROCESS_CONFIG
@ DQCS_HTYPE_BACK_PROCESS_CONFIG
Indicates that the given handle belongs to a backend plugin process configuration object.
Definition: dqcsim.h:266
dqcsim::wrap::SimulationConfiguration::log_tee
void log_tee(Loglevel verbosity, const std::string &filename)
Configures DQCsim to also output its log messages to a file.
Definition: dqcsim:10146
DQCS_GATE_PHASE
@ DQCS_GATE_PHASE
The matrix for an arbitrary Z rotation.
Definition: dqcsim.h:783
dqcsim::wrap::ArbData::operator=
void operator=(const ArbData &src)
Copy assignment operator for ArbData objects.
Definition: dqcsim:2254
dqcsim::raw::dqcs_handle_dump
char * dqcs_handle_dump(dqcs_handle_t handle)
Returns a debug dump of the object associated with the given handle.
dqcsim::wrap::MeasurementSet::take_any
Measurement take_any()
Moves any measurement object out of the set.
Definition: dqcsim:5922
dqcsim::wrap::Arb::push_arb_arg
void push_arb_arg(const T &data)
Pushes a value of type T to the back of the arbitrary argument list.
Definition: dqcsim:2050
dqcsim::wrap::PathStyle::Keep
@ Keep
Specifies that paths should be saved the same way they were specified on the command line.
dqcsim::wrap::Gate::prep
static Gate prep(QubitSet &&targets, PauliBasis basis)
Constructs a new prep gate, putting the qubits in the base state for the given Pauli basis.
Definition: dqcsim:3868
dqcsim::wrap::PluginState::free
void free(const QubitRef &qubit)
Frees the given downstream qubit.
Definition: dqcsim:6305
dqcsim::wrap::PluginConfiguration::get_plugin_type
virtual PluginType get_plugin_type() const =0
Returns the plugin type.
dqcsim::wrap::Arb::set_arb_json
void set_arb_json(const JSON &json)
Sets the arbitrary JSON data to the given JSON object from nlohmann::json.
Definition: dqcsim:1924
dqcsim::raw::dqcs_pdef_set_allocate_cb
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.
dqcsim::wrap::Simulation::yield
void yield()
Yields to the simulator.
Definition: dqcsim:9664
dqcsim::wrap::UpstreamPluginState::random_f64
double random_f64() noexcept
Generates a random floating point number using the simulator random seed.
Definition: dqcsim:6085
dqcsim::wrap::GateMap::with_unitary
GateMap && with_unitary(const Unbound &key, const std::shared_ptr< CustomUnitaryGateConverter > &converter)
Adds a custom unitary gate mapping.
Definition: dqcsim:5035
dqcs_mat_new
dqcs_handle_t dqcs_mat_new(size_t num_qubits, const double *matrix)
Constructs a new gate matrix.
DQCS_MEAS_ONE
@ DQCS_MEAS_ONE
Indicates that the qubit was measured to be one.
Definition: dqcsim.h:421
DQCS_PATH_STYLE_INVALID
@ DQCS_PATH_STYLE_INVALID
Error value used to indicate that something went wrong.
Definition: dqcsim.h:435
dqcsim::wrap::Callback::Callback
Callback(R(*cb)(Args...)) noexcept
Constructs the callback wrapper from a regular C-style function.
Definition: dqcsim:6827
DQCS_HTYPE_ARB_DATA
@ DQCS_HTYPE_ARB_DATA
Indicates that the given handle belongs to an ArbData object.
Definition: dqcsim.h:187
dqcsim::raw::dqcs_plugin_state_t
void * dqcs_plugin_state_t
Type for a plugin state.
Definition: cdqcsim:750
dqcsim::wrap::GateMap::with_prep
GateMap && with_prep(Unbound &&key, PauliBasis basis=PauliBasis::Z, double epsilon=0.000001, int num_targets=-1)
Adds a prep gate mapping.
Definition: dqcsim:5211
dqcsim::wrap::HandleIndex
raw::dqcs_handle_t HandleIndex
C++-styled type name for raw::dqcs_handle_t.
Definition: dqcsim:95
dqcsim::wrap::Matrix::Matrix
Matrix(const Matrix &src)
Copy-constructs a matrix.
Definition: dqcsim:3278
dqcsim::wrap::Plugin::with_run
Plugin && with_run(const callback::Run &cb)
Assigns the run callback function from a pre-existing callback::Run object by copy.
Definition: dqcsim:7994
dqcsim::wrap::Matrix::strip_control
std::pair< std::vector< size_t >, Matrix > strip_control(double epsilon, bool ignore_global_phase) const
Splits a controlled matrix into its non-controlled submatrix and the indices of the control qubits.
Definition: dqcsim:3495
dqcsim::wrap::Arb::insert_arb_arg
void insert_arb_arg(ssize_t index, const T &data)
Inserts an arbitrary argument at the given index using a value of type T.
Definition: dqcsim:2131
dqcsim::wrap::PluginState::gate
void gate(const Matrix &matrix, const QubitRef &qa, const QubitRef &qb)
Shorthand for sending a two-qubit gate to the downstream plugin.
Definition: dqcsim:6361
dqcsim::wrap::callback::Allocate
Callback< void, PluginState &, QubitSet &&, ArbCmdQueue && > Allocate
Callback wrapper specialized for the allocate callback.
Definition: dqcsim:6919
dqcsim::raw::dqcs_pcfg_verbosity_get
dqcs_loglevel_t dqcs_pcfg_verbosity_get(dqcs_handle_t pcfg)
Returns the configured verbosity for the given plugin process.
dqcsim::wrap::PluginProcessConfiguration::get_executable
std::string get_executable() const
Returns the configured executable path for the plugin.
Definition: dqcsim:8700
dqcsim::wrap::Arb::get_arb_arg_string
std::string get_arb_arg_string(ssize_t index) const
Returns the arbitrary argument at the given index as a (binary) string.
Definition: dqcsim:1939
dqcsim::wrap::Plugin::Plugin
Plugin(Plugin &&)=default
Default move constructor.
dqcsim::wrap::PluginProcessConfiguration::with_accept_timeout
PluginProcessConfiguration && with_accept_timeout(double timeout)
Configures the timeout for the plugin process to connect to DQCsim (builder pattern).
Definition: dqcsim:9011
dqcsim::wrap::ArbData::ArbData
ArbData()
Constructs an empty ArbData object.
Definition: dqcsim:2222
dqcsim::wrap::PluginProcessConfiguration::with_work_dir
PluginProcessConfiguration && with_work_dir(const std::string &dir)
Overrides the working directory for the plugin process (builder pattern).
Definition: dqcsim:8829
dqcsim::raw::dqcs_scfg_tee
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.
dqcsim::wrap::Measurement::get_qubit
QubitRef get_qubit() const
Returns the qubit reference associated with this measurement.
Definition: dqcsim:5681
dqcsim::raw::dqcs_scfg_seed_set
dqcs_return_t dqcs_scfg_seed_set(dqcs_handle_t scfg, uint64_t seed)
Configures the random seed that the simulation should use.
dqcsim::wrap::Gate::predefined
static Gate predefined(PredefinedGate gate, QubitSet &&qubits)
Constructs a new non-parameterized predefined gate.
Definition: dqcsim:3639
dqcsim::wrap::ArbCmdQueue::operator=
ArbCmdQueue & operator=(ArbCmdQueue &&)=default
Default move assignment.
dqcsim::raw::dqcs_tcfg_verbosity_get
dqcs_loglevel_t dqcs_tcfg_verbosity_get(dqcs_handle_t tcfg)
Returns the configured verbosity for the given plugin thread.
dqcsim::raw::dqcs_mset_len
ssize_t dqcs_mset_len(dqcs_handle_t mset)
Returns the number of qubits measurements in the given measurement set.
dqcsim::wrap::QubitRef::operator!=
bool operator!=(const QubitRef &other) const noexcept
Qubit reference inequality operator.
Definition: dqcsim:2932
dqcsim::raw::dqcs_mset_remove
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.
dqcsim::raw::dqcs_gate_new_unitary
dqcs_handle_t dqcs_gate_new_unitary(dqcs_handle_t targets, dqcs_handle_t controls, dqcs_handle_t matrix)
Constructs a new unitary gate.
dqcsim::wrap::GateMap::construct
Gate construct(const Unbound &unbound, QubitSet &&qubits)
Uses a gate map object to construct a DQCsim gate from the plugin's representation.
Definition: dqcsim:5494
dqcsim::wrap::RunningPluginState::send
void send(const ArbData &message)
Sends a message to the host.
Definition: dqcsim:6721
dqcsim::wrap::PluginThreadConfiguration::with_init_cmd
PluginThreadConfiguration && with_init_cmd(ArbCmd &&cmd)
Attaches an arbitrary initialization command to the plugin (builder pattern).
Definition: dqcsim:9172
dqcsim::raw::dqcs_pcfg_tee
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.
dqcsim::wrap::Gate::get_name
std::string get_name() const
Returns the name of a custom gate.
Definition: dqcsim:4388
dqcsim::wrap::Gate::custom
static Gate custom(const std::string &name, QubitSet &&targets, const Matrix &matrix)
Constructs a new custom gate with target qubits and a matrix.
Definition: dqcsim:4182
dqcsim::wrap::Plugin::run
int run(int argc, char *argv[]) noexcept
Runs the defined plugin in the current thread with the given command line.
Definition: dqcsim:8503
dqcsim::wrap::Gate::measure
static Gate measure(QubitSet &&measures, PauliBasis basis)
Constructs a new measurement gate, measuring in the given Pauli basis.
Definition: dqcsim:3780
dqcsim::wrap::SimulationConfiguration::with_log_callback
SimulationConfiguration && with_log_callback(Loglevel verbosity, Args... args)
Configures DQCsim to also output its log messages to callback function (builder pattern).
Definition: dqcsim:10340
dqcsim::wrap::PluginThreadConfiguration::set_verbosity
void set_verbosity(Loglevel level) override
Sets the logging verbosity level of the plugin.
Definition: dqcsim:9183
dqcsim::wrap::Callback::Callback
Callback(const std::shared_ptr< std::function< R(Args...)>> &cb) noexcept
Constructs the callback wrapper by means of a copying a shared_ptr to a std::function.
Definition: dqcsim:6890
dqcsim::wrap::PluginProcessConfiguration::set_stderr_loglevel
void set_stderr_loglevel(Loglevel level)
Configures the capture mode for the stderr stream of the specified plugin process.
Definition: dqcsim:8955
dqcsim::wrap::ArbCmdQueue::from_iter
static ArbCmdQueue from_iter(const T &cmds)
Constructs an ArbCmd queue object from an iterable of ArbCmds by copying.
Definition: dqcsim:2725
dqcsim::wrap::Plugin::get_name
std::string get_name() const
Returns the name of the described plugin.
Definition: dqcsim:7716
dqcsim::wrap::Simulation
Wrapper class for a running simulation.
Definition: dqcsim:9461
DQCS_GATE_SQRT_SWAP
@ DQCS_GATE_SQRT_SWAP
The square-root of a swap gate matrix.
Definition: dqcsim.h:844
dqcsim::wrap::RunningPluginState::recv
ArbData recv()
Receives a message from the host.
Definition: dqcsim:6736
dqcsim::raw::dqcs_pdef_type
dqcs_plugin_type_t dqcs_pdef_type(dqcs_handle_t pdef)
Returns the plugin type for the given plugin definition object.
dqcsim::wrap::Gate::custom
static Gate custom(const std::string &name, const QubitSet &targets, const QubitSet &controls, const Matrix &matrix)
Constructs a new custom gate with target qubits, control qubits, and a matrix.
Definition: dqcsim:4105
dqcsim::wrap::PluginProcessConfiguration::with_verbosity
PluginProcessConfiguration && with_verbosity(Loglevel level)
Sets the logging verbosity level of the plugin (builder pattern).
Definition: dqcsim:8865
dqcsim::raw::dqcs_mat_approx_eq
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.
dqcsim::wrap::Gate::predefined
static Gate predefined(PredefinedGate gate, QubitSet &&qubits, ArbData &&parameters)
Constructs a new predefined gate.
Definition: dqcsim:3597
DQCS_HTYPE_BACK_THREAD_CONFIG
@ DQCS_HTYPE_BACK_THREAD_CONFIG
Indicates that the given handle belongs to a backend plugin thread configuration object.
Definition: dqcsim.h:290
DQCS_GATE_RZ
@ DQCS_GATE_RZ
The matrix for an arbitrary Z rotation.
Definition: dqcsim.h:747
dqcsim::wrap::Gate::get_measures
QubitSet get_measures() const
Returns a new qubit reference set with the measurement qubits for this gate.
Definition: dqcsim:4347
dqcsim::wrap::Plugin::with_drop
Plugin && with_drop(const callback::Drop &cb)
Assigns the drop callback function from a pre-existing callback::Drop object by copy.
Definition: dqcsim:7930
dqcsim::wrap::PluginProcessConfiguration::with_stdout_loglevel
PluginProcessConfiguration && with_stdout_loglevel(Loglevel level)
Configures the capture mode for the stdout stream of the specified plugin process (builder pattern).
Definition: dqcsim:8930
dqcsim::raw::dqcs_gate_has_name
dqcs_bool_return_t dqcs_gate_has_name(dqcs_handle_t gate)
Returns whether the specified gate has a name.
dqcsim::wrap::Gate::unitary
static Gate unitary(const QubitSet &targets, const Matrix &matrix)
Constructs a new custom unitary gate.
Definition: dqcsim:3693
dqcsim::raw::dqcs_cmd_oper_get
char * dqcs_cmd_oper_get(dqcs_handle_t cmd)
Returns the operation ID of an ArbCmd.
dqcsim::raw::dqcs_pcfg_shutdown_timeout_get
double dqcs_pcfg_shutdown_timeout_get(dqcs_handle_t pcfg)
Returns the configured timeout for the plugin process to shut down gracefully.
dqcsim::wrap::Measurement::set_qubit
void set_qubit(QubitRef qubit)
Sets the qubit reference associated with this measurement.
Definition: dqcsim:5691
dqcsim::wrap::Measurement::with_cbor_string
Measurement & with_cbor_string(const std::string &cbor)
Sets the arbitrary JSON data to the given serialized CBOR string (builder pattern).
Definition: dqcsim:5724
dqcsim::wrap::PluginConfiguration::add_init_cmd
virtual void add_init_cmd(ArbCmd &&cmd)=0
Attaches an arbitrary initialization command to the plugin.
dqcsim::wrap::PluginProcessConfiguration::set_env_var
void set_env_var(const std::string &key, const std::string &value)
Overrides an environment variable for the plugin process.
Definition: dqcsim:8756
dqcsim::wrap::Handle::handle
HandleIndex handle
The wrapped handle.
Definition: dqcsim:1624
dqcsim::wrap::QubitSet::pop
QubitRef pop()
Pops a qubit from the set.
Definition: dqcsim:3086
dqcsim::wrap::PluginProcessConfiguration
Wrapper class for plugin process configurations.
Definition: dqcsim:8640
dqcsim::wrap::PluginProcessConfiguration::get_work_dir
std::string get_work_dir() const
Returns the configured working directory for the given plugin process.
Definition: dqcsim:8841
dqcsim::wrap::Matrix::add_controls
Matrix add_controls(size_t number_of_controls) const
Constructs a controlled matrix from the given matrix.
Definition: dqcsim:3473
dqcsim::wrap::Gate::operator=
Gate & operator=(Gate &&)=default
Default move assignment.
dqcsim
Main DQCsim namespace.
Definition: cdqcsim:34
dqcsim::raw::dqcs_pcfg_init_cmd
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.
dqcsim::raw::dqcs_scfg_push_plugin
dqcs_return_t dqcs_scfg_push_plugin(dqcs_handle_t scfg, dqcs_handle_t xcfg)
Appends a plugin to a simulation configuration.
dqcsim::wrap::CustomGateConverter
Class that you can inherit from to make your own custom gate converter for use within DQCsim.
Definition: dqcsim:4498
DQCS_LOG_INFO
@ DQCS_LOG_INFO
This loglevel is to be used for reporting information NOT specifically requested by the user/API call...
Definition: dqcsim.h:382
dqcsim::wrap::Cmd::is_iface
bool is_iface(const std::string &iface) const
Returns whether this command has the given interface identifier.
Definition: dqcsim:2396
dqcsim::raw::dqcs_bool_return_t::DQCS_BOOL_FAILURE
@ DQCS_BOOL_FAILURE
The function has failed.
dqcsim::wrap::callback::Arb
Callback< ArbData, PluginState &, ArbCmd > Arb
Callback wrapper specialized for the *_arb callbacks.
Definition: dqcsim:6944
dqcsim::wrap::PluginState::allocate
QubitRef allocate(ArbCmdQueue &&cmds)
Allocates a single downstream qubit, copying in the given command queue as arbitrary additional data ...
Definition: dqcsim:6223
DQCS_FAILURE
@ DQCS_FAILURE
The function has failed.
Definition: dqcsim.h:873
DQCS_HTYPE_BACK_DEF
@ DQCS_HTYPE_BACK_DEF
Indicates that the given handle belongs to a backend plugin definition object.
Definition: dqcsim.h:324
dqcsim::wrap::MeasurementSet::set
void set(Measurement &&measurement)
Moves the given measurement object into the set.
Definition: dqcsim:5837
dqcsim::wrap::Simulation::arb
ArbData arb(ssize_t index, const ArbCmd &cmd)
Sends an ArbCmd (passed by copy) to the given plugin (referenced by index).
Definition: dqcsim:9744
dqcsim::raw::dqcs_arb_json_set
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
@ DQCS_HTYPE_SIM
Indicates that the given handle belongs to a simulator instance.
Definition: dqcsim.h:303