Go to the documentation of this file.
3 #ifndef _DQCSIM_INCLUDED_
4 #define _DQCSIM_INCLUDED_
156 inline unsigned long long check(
unsigned long long handle) {
190 return static_cast<size_t>(size);
265 FrontendProcessConfig = 200,
271 OperatorProcessConfig = 201,
277 BackendProcessConfig = 203,
283 FrontendThreadConfig = 204,
289 OperatorThreadConfig = 205,
295 BackendThreadConfig = 206,
300 SimulationConfig = 207,
310 FrontendDefinition = 300,
315 OperatorDefinition = 301,
320 BackendDefinition = 302,
358 std::cerr <<
"unknown handle type" << std::endl;
396 throw std::invalid_argument(
"unknown handle type");
499 std::cerr <<
"unknown loglevel" << std::endl;
525 throw std::invalid_argument(
"unknown loglevel");
562 switch (measurement) {
567 std::cerr <<
"unknown measurement value" << std::endl;
581 switch (measurement) {
587 throw std::invalid_argument(
"unknown measurement value");
631 std::cerr <<
"unknown path style" << std::endl;
651 throw std::invalid_argument(
"unknown path style");
691 std::cerr <<
"unknown plugin type" << std::endl;
711 throw std::invalid_argument(
"unknown plugin type");
806 std::cerr <<
"unknown gate type" << std::endl;
827 throw std::invalid_argument(
"unknown gate type");
888 std::cerr <<
"unknown basis" << std::endl;
908 throw std::invalid_argument(
"unknown basis");
1367 std::cerr <<
"unknown plugin type" << std::endl;
1413 throw std::invalid_argument(
"unknown plugin type");
1424 template <
typename T>
1426 if (pointer ==
nullptr) {
1458 template<
typename... Args>
1461 const std::string &module,
1462 const std::string &file,
1463 unsigned int line_nr,
1464 const std::string &format,
1467 raw::dqcs_log_format(
1497 const std::string &module,
1498 const std::string &file,
1499 unsigned int line_nr,
1500 const std::string &message
1519 #define DQCSIM_LOG(level, fmt, ...) \
1520 ::dqcsim::wrap::log( \
1521 level, "C++", __FILE__, __LINE__, \
1531 #define DQCSIM_TRACE(fmt, ...) DQCSIM_LOG(::dqcsim::wrap::Loglevel::Trace, fmt, ##__VA_ARGS__)
1540 #define DQCSIM_DEBUG(fmt, ...) DQCSIM_LOG(::dqcsim::wrap::Loglevel::Debug, fmt, ##__VA_ARGS__)
1549 #define DQCSIM_INFO(fmt, ...) DQCSIM_LOG(::dqcsim::wrap::Loglevel::Info, fmt, ##__VA_ARGS__)
1558 #define DQCSIM_NOTE(fmt, ...) DQCSIM_LOG(::dqcsim::wrap::Loglevel::Note, fmt, ##__VA_ARGS__)
1567 #define DQCSIM_WARN(fmt, ...) DQCSIM_LOG(::dqcsim::wrap::Loglevel::Warn, fmt, ##__VA_ARGS__)
1576 #define DQCSIM_WARNING(fmt, ...) DQCSIM_LOG(::dqcsim::wrap::Loglevel::Warn, fmt, ##__VA_ARGS__)
1585 #define DQCSIM_ERROR(fmt, ...) DQCSIM_LOG(::dqcsim::wrap::Loglevel::Error, fmt, ##__VA_ARGS__)
1594 #define DQCSIM_FATAL(fmt, ...) DQCSIM_LOG(::dqcsim::wrap::Loglevel::Fatal, fmt, ##__VA_ARGS__)
1681 }
catch (std::runtime_error) {
1712 void operator=(
const Handle&) =
delete;
1772 std::string
dump(dump_c);
1832 std::string json(json_c);
1902 template <
class JSON>
1905 std::vector<uint8_t> cbor;
1908 return JSON::from_cbor(cbor);
1923 template <
class JSON>
1925 std::vector<uint8_t> cbor = JSON::to_cbor(json);
1963 template <
typename T>
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");
1985 template <
typename T>
1988 for (
const std::string &
string : strings) {
2021 template <
typename T>
2049 template <
typename T>
2086 template <
typename T>
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");
2130 template <
typename T>
2272 #define ARB_BUILDER_SUBCLASS ArbData
2313 template <
class JSON>
2347 template <
typename T>
2353 #undef ARB_BUILDER_SUBCLASS
2384 std::string iface(iface_c);
2408 std::string oper(oper_c);
2479 iface.c_str(), oper.c_str()
2541 #define ARB_BUILDER_SUBCLASS ArbCmd
2582 template <
class JSON>
2616 template <
typename T>
2622 #undef ARB_BUILDER_SUBCLASS
2709 for (
Cmd &cmd : cmds) {
2710 result.
push(std::move(cmd));
2727 for (
const Cmd &cmd : cmds) {
2741 push(std::move(cmd));
2742 return std::move(*
this);
2755 return std::move(*
this);
2787 std::vector<ArbCmd> cmds;
2789 cmds.emplace_back(*
this);
2892 throw std::runtime_error(
"Qubit indices cannot be zero in DQCsim");
2923 return index == other.index;
2933 return index != other.index;
2944 out <<
'q' << qubit.index;
2962 inline QubitRef operator "" _q(
unsigned long long int qubit) {
3015 for (
const QubitRef &qubit : qubits) {
3076 return std::move(*
this);
3123 std::vector<QubitRef> qubits;
3125 qubits.emplace_back(
pop());
3343 std::vector<complex>
get()
const {
3345 std::vector<complex> vec(s);
3347 std::memcpy(vec.data(), data, s *
sizeof(
complex));
3360 std::vector<double> vec(s * 2);
3362 std::memcpy(vec.data(), data, 2 * s *
sizeof(
double));
3384 double epsilon = 0.000001,
3385 bool ignore_global_phase =
true
3409 double epsilon = 0.000001
3451 double epsilon = 0.000001,
3452 bool ignore_global_phase =
true,
3458 if (!match)
return false;
3459 *parameters =
ArbData(param_data);
3496 ssize_t *indices =
nullptr;
3497 std::pair<std::vector<size_t>,
Matrix> result(
3498 std::vector<size_t>(),
3501 while (*indices != -1) {
3502 result.first.push_back(*indices++);
3568 void operator=(
const Gate&) =
delete;
3600 qubits.get_handle(),
3601 parameters.get_handle()
3642 qubits.get_handle(),
3676 targets.get_handle(),
3713 targets.get_handle(),
3714 controls.get_handle(),
3938 const std::string &name,
3946 targets.get_handle(),
3947 controls.get_handle(),
3948 measures.get_handle(),
3976 const std::string &name,
4009 const std::string &name,
4016 targets.get_handle(),
4017 controls.get_handle(),
4018 measures.get_handle(),
4042 const std::string &name,
4073 const std::string &name,
4080 targets.get_handle(),
4081 controls.get_handle(),
4106 const std::string &name,
4132 const std::string &name,
4138 targets.get_handle(),
4139 controls.get_handle(),
4159 const std::string &name,
4183 const std::string &name,
4189 targets.get_handle(),
4210 const std::string &name,
4232 const std::string &name,
4237 targets.get_handle(),
4256 const std::string &name,
4275 const std::string &name
4390 std::string name(data);
4409 #define ARB_BUILDER_SUBCLASS Gate
4450 template <
class JSON>
4484 template <
typename T>
4490 #undef ARB_BUILDER_SUBCLASS
4503 template <
class Unbound,
class Bound>
4510 const void *user_data,
4516 auto converter =
reinterpret_cast<const std::shared_ptr<CustomGateConverter>*
>(user_data);
4520 params_wrapper.
set_arb(gate_wrapper);
4521 if (!(*converter)->detect(std::move(gate_wrapper), qubits_wrapper, params_wrapper)) {
4527 }
catch (
const std::exception &e) {
4537 const void *user_data,
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) {
4553 static void raw_deleter(
void *user_data) noexcept {
4554 auto converter =
reinterpret_cast<const std::shared_ptr<CustomGateConverter>*
>(user_data);
4597 throw std::runtime_error(
"detector function not implemented");
4611 template <
class Unbound,
class Bound>
4618 const void *user_data,
4620 size_t num_controls,
4624 auto converter =
reinterpret_cast<const std::shared_ptr<CustomUnitaryGateConverter>*
>(user_data);
4626 if (!(*converter)->detect(
Matrix(matrix), num_controls, params_wrapper)) {
4629 *params = params_wrapper.take_handle();
4631 }
catch (
const std::exception &e) {
4641 const void *user_data,
4643 ssize_t *num_controls
4646 auto converter =
reinterpret_cast<const std::shared_ptr<CustomUnitaryGateConverter>*
>(user_data);
4648 Matrix matrix = (*converter)->construct(params_wrapper, *num_controls);
4649 *params = params_wrapper.take_handle();
4651 }
catch (
const std::exception &e) {
4660 static void raw_deleter(
void *user_data) noexcept {
4661 auto converter =
reinterpret_cast<const std::shared_ptr<CustomUnitaryGateConverter>*
>(user_data);
4709 throw std::runtime_error(
"detector function not implemented");
4749 template <
class Unbound,
class Bound=Unbound>
4757 static bool unbound_equality(
const void *a,
const void *b) {
4758 return *(
const Unbound*)a == *(
const Unbound*)b;
4764 static uint64_t unbound_hash(
const void *a) {
4765 return (uint64_t)std::hash<Unbound>{}(*(
const Unbound*)a);
4771 static void unbound_delete(
void *a) {
4807 GateMap(
bool strip_qubit_refs =
false,
bool strip_data =
false)
4813 void operator=(
const GateMap&) =
delete;
4850 int num_controls = -1,
4851 double epsilon = 0.000001,
4852 bool ignore_global_phase =
true
4857 new Unbound(std::move(key)),
4863 return std::move(*
this);
4891 int num_controls = -1,
4892 double epsilon = 0.000001,
4893 bool ignore_global_phase =
true
4904 return std::move(*
this);
4932 int num_controls = -1,
4933 double epsilon = 0.000001,
4934 bool ignore_global_phase =
true
4939 new Unbound(std::move(key)),
4940 matrix.get_handle(),
4945 return std::move(*
this);
4973 int num_controls = -1,
4974 double epsilon = 0.000001,
4975 bool ignore_global_phase =
true
4986 return std::move(*
this);
5005 const std::shared_ptr<CustomUnitaryGateConverter> &converter
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)
5018 return std::move(*
this);
5037 const std::shared_ptr<CustomUnitaryGateConverter> &converter
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)
5050 return std::move(*
this);
5074 double epsilon = 0.000001,
5075 int num_measures = -1
5080 new Unbound(std::move(key)),
5085 return std::move(*
this);
5109 double epsilon = 0.000001,
5110 int num_measures = -1
5120 return std::move(*
this);
5144 double epsilon = 0.000001,
5145 int num_measures = -1
5150 new Unbound(std::move(key)),
5155 return std::move(*
this);
5179 double epsilon = 0.000001,
5180 int num_measures = -1
5190 return std::move(*
this);
5214 double epsilon = 0.000001,
5215 int num_targets = -1
5220 new Unbound(std::move(key)),
5225 return std::move(*
this);
5249 double epsilon = 0.000001,
5250 int num_targets = -1
5260 return std::move(*
this);
5284 double epsilon = 0.000001,
5285 int num_targets = -1
5290 new Unbound(std::move(key)),
5295 return std::move(*
this);
5319 double epsilon = 0.000001,
5320 int num_targets = -1
5330 return std::move(*
this);
5349 const std::shared_ptr<CustomGateConverter> &converter
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)
5362 return std::move(*
this);
5381 const std::shared_ptr<CustomGateConverter> &converter
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)
5394 return std::move(*
this);
5419 const Unbound **unbound,
5430 (
const void**)unbound,
5434 if (qubits && qubits_handle) *qubits =
QubitSet(qubits_handle);
5435 if (params && params_handle) *params =
ArbData(params_handle);
5452 const Unbound &unbound,
5459 qubits.get_handle(),
5477 const Unbound &unbound,
5495 const Unbound &unbound,
5501 qubits.get_handle(),
5518 const Unbound &unbound,
5539 const Unbound *unbound =
nullptr;
5542 if (!
detect(gate, &unbound, &qubits, ¶ms)) {
5543 throw std::runtime_error(
"unknown gate");
5545 return unbound->bind(std::move(qubits), std::move(params));
5565 bound.get_unbound(),
5699 #define ARB_BUILDER_SUBCLASS Measurement
5740 template <
class JSON>
5774 template <
typename T>
5780 #undef ARB_BUILDER_SUBCLASS
5822 for (
const Measurement &measurement : measurements) {
5823 result.
set(measurement);
5865 set(std::move(measurement));
5866 return std::move(*
this);
5881 return std::move(*
this);
5973 std::vector<Measurement> measurements;
5975 measurements.emplace_back(
take_any());
5977 return measurements;
6068 friend class CallbackEntryPoints;
6107 template <
typename T>
6109 uint64_t data[(
sizeof(T) + 7) / 8];
6110 for (
size_t i = 0; i < (
sizeof(T) + 7) / 8; i++) {
6114 std::memcpy(&retval, data,
sizeof(T));
6138 friend class CallbackEntryPoints;
6224 return allocate(1, std::move(cmds)).pop();
6338 if (matrix.
size() == 2) {
6341 throw std::invalid_argument(
"matrix has incorrect size");
6362 if (matrix.
size() == 2) {
6364 }
else if (matrix.
size() == 4) {
6367 throw std::invalid_argument(
"matrix has incorrect size");
6398 if (matrix.
size() == 2) {
6400 }
else if (matrix.
size() == 4) {
6402 }
else if (matrix.
size() == 8) {
6405 throw std::invalid_argument(
"matrix has incorrect size");
6460 for (
auto &q : qs_vec)
gate(
Matrix(PredefinedGate::H), q);
6462 for (
auto &q : qs_vec)
gate(
Matrix(PredefinedGate::H), q);
6519 for (
auto &q : qs_vec)
gate(
Matrix(PredefinedGate::S), q);
6520 for (
auto &q : qs_vec)
gate(
Matrix(PredefinedGate::Z), q);
6522 for (
auto &q : qs_vec)
gate(
Matrix(PredefinedGate::S), q);
6685 friend class CallbackEntryPoints;
6748 template <
class R,
class... Args>
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);
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);
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);
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);
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);
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);
6815 std::shared_ptr<std::function<R(Args...)>> cb;
6818 friend class CallbackEntryPoints;
6828 : cb(std::make_shared<std::function<R(Args...)>>(cb))
6842 : cb(std::make_shared<std::function<R(Args...)>>(bind_first<T, R, Args...>(cb, user)))
6854 : cb(std::make_shared<std::function<R(Args...)>>(bind_instance<T, R, Args...>(instance, cb)))
6863 : cb(std::make_shared<std::function<R(Args...)>>(std::move(cb)))
6872 : cb(std::make_shared<std::function<R(Args...)>>(cb))
6881 Callback(std::shared_ptr<std::function<R(Args...)>> &&cb) noexcept : cb(cb) {
6890 Callback(
const std::shared_ptr<std::function<R(Args...)>> &cb) noexcept : cb(cb) {
6899 namespace callback {
6982 std::chrono::system_clock::time_point&&,
6998 class CallbackEntryPoints {
7021 (*(cb_wrapper->cb))(state_wrapper, std::move(init_cmds_wrapper));
7023 }
catch (
const std::exception &e) {
7039 PluginState state_wrapper(state);
7044 (*(cb_wrapper->cb))(state_wrapper);
7046 }
catch (
const std::exception &e) {
7063 RunningPluginState state_wrapper(state);
7064 ArbData args_wrapper(args);
7069 return (*(cb_wrapper->cb))(state_wrapper, std::move(args_wrapper)).take_handle();
7070 }
catch (
const std::exception &e) {
7088 PluginState state_wrapper(state);
7089 QubitSet qubits_wrapper(qubits);
7090 ArbCmdQueue alloc_cmds_wrapper(alloc_cmds);
7095 (*(cb_wrapper->cb))(state_wrapper, std::move(qubits_wrapper), std::move(alloc_cmds_wrapper));
7097 }
catch (
const std::exception &e) {
7114 PluginState state_wrapper(state);
7115 QubitSet qubits_wrapper(qubits);
7120 (*(cb_wrapper->cb))(state_wrapper, std::move(qubits_wrapper));
7122 }
catch (
const std::exception &e) {
7139 PluginState state_wrapper(state);
7140 Gate gate_wrapper(gate);
7145 return (*(cb_wrapper->cb))(state_wrapper, std::move(gate_wrapper)).take_handle();
7146 }
catch (
const std::exception &e) {
7163 UpstreamPluginState state_wrapper(state);
7164 Measurement meas_wrapper(meas);
7169 return (*(cb_wrapper->cb))(state_wrapper, std::move(meas_wrapper)).take_handle();
7170 }
catch (
const std::exception &e) {
7187 PluginState state_wrapper(state);
7192 (*(cb_wrapper->cb))(state_wrapper, cycles);
7194 }
catch (
const std::exception &e) {
7211 PluginState state_wrapper(state);
7212 ArbCmd cmd_wrapper(cmd);
7217 return (*(cb_wrapper->cb))(state_wrapper, std::move(cmd_wrapper)).take_handle();
7218 }
catch (
const std::exception &e) {
7235 PluginState state_wrapper(state);
7236 ArbCmd cmd_wrapper(cmd);
7241 return (*(cb_wrapper->cb))(state_wrapper, std::move(cmd_wrapper)).take_handle();
7242 }
catch (
const std::exception &e) {
7251 static void spawn_plugin(
7253 const char *simulator
7258 std::string simulator_wrapper(simulator);
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());
7274 const char *message,
7292 (*(cb_wrapper->cb))(
7293 std::string(message ? message :
""),
7294 std::string(logger ? logger :
""),
7296 std::string(module ? module :
""),
7297 std::string(file ? file :
""),
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)
7308 }
catch (
const std::exception &e) {
7309 std::cerr <<
"DQCsim caught std::exception in log callback: " << e.what() << std::endl;
7317 static void user_free(
void *user_data) noexcept {
7318 T *cb_wrapper =
reinterpret_cast<T*
>(user_data);
7621 const std::string &name,
7622 const std::string &author,
7623 const std::string &version
7625 to_raw(type), name.c_str(), author.c_str(), version.c_str()
7641 const std::string &name,
7642 const std::string &author,
7643 const std::string &version
7660 const std::string &name,
7661 const std::string &author,
7662 const std::string &version
7679 const std::string &name,
7680 const std::string &author,
7681 const std::string &version
7688 void operator=(
const Plugin&) =
delete;
7718 std::string str(cstr);
7731 std::string str(cstr);
7744 std::string str(cstr);
7846 CallbackEntryPoints::initialize,
7847 CallbackEntryPoints::user_free<callback::Initialize>,
7868 return std::move(*
this);
7882 return std::move(*
this);
7893 template<
typename... Args>
7896 return std::move(*
this);
7910 CallbackEntryPoints::drop,
7911 CallbackEntryPoints::user_free<callback::Drop>,
7932 return std::move(*
this);
7946 return std::move(*
this);
7957 template<
typename... Args>
7960 return std::move(*
this);
7974 CallbackEntryPoints::run,
7975 CallbackEntryPoints::user_free<callback::Run>,
7996 return std::move(*
this);
8010 return std::move(*
this);
8021 template<
typename... Args>
8024 return std::move(*
this);
8038 CallbackEntryPoints::allocate,
8039 CallbackEntryPoints::user_free<callback::Allocate>,
8060 return std::move(*
this);
8074 return std::move(*
this);
8085 template<
typename... Args>
8088 return std::move(*
this);
8102 CallbackEntryPoints::free,
8103 CallbackEntryPoints::user_free<callback::Free>,
8124 return std::move(*
this);
8138 return std::move(*
this);
8149 template<
typename... Args>
8152 return std::move(*
this);
8166 CallbackEntryPoints::gate,
8167 CallbackEntryPoints::user_free<callback::Gate>,
8188 return std::move(*
this);
8202 return std::move(*
this);
8213 template<
typename... Args>
8216 return std::move(*
this);
8230 CallbackEntryPoints::modify_measurement,
8231 CallbackEntryPoints::user_free<callback::ModifyMeasurement>,
8252 return std::move(*
this);
8266 return std::move(*
this);
8277 template<
typename... Args>
8280 return std::move(*
this);
8294 CallbackEntryPoints::advance,
8295 CallbackEntryPoints::user_free<callback::Advance>,
8316 return std::move(*
this);
8330 return std::move(*
this);
8341 template<
typename... Args>
8344 return std::move(*
this);
8358 CallbackEntryPoints::upstream_arb,
8359 CallbackEntryPoints::user_free<callback::Arb>,
8380 return std::move(*
this);
8394 return std::move(*
this);
8405 template<
typename... Args>
8408 return std::move(*
this);
8422 CallbackEntryPoints::host_arb,
8423 CallbackEntryPoints::user_free<callback::Arb>,
8444 return std::move(*
this);
8458 return std::move(*
this);
8469 template<
typename... Args>
8472 return std::move(*
this);
8487 void run(
const char *simulator) {
8503 int run(
int argc,
char *argv[]) noexcept {
8505 DQCSIM_FATAL(
"Expecting exactly one command-line argument, but got %d", argc);
8510 }
catch (
const std::exception &e) {
8511 DQCSIM_FATAL(
"Returning failure because of the following: %s", e.what());
8514 DQCSIM_FATAL(
"Returning failure because of an unknown exception");
8606 add_init_cmd(
ArbCmd(cmd));
8689 std::string retval(ptr);
8702 std::string retval(ptr);
8715 std::string retval(ptr);
8741 add_init_cmd(std::move(cmd));
8742 return std::move(*
this);
8774 set_env_var(key, value);
8775 return std::move(*
this);
8806 return std::move(*
this);
8831 return std::move(*
this);
8843 std::string retval(ptr);
8866 set_verbosity(level);
8867 return std::move(*
this);
8903 log_tee(verbosity, filename);
8904 return std::move(*
this);
8931 set_stdout_loglevel(level);
8932 return std::move(*
this);
8970 set_stderr_loglevel(level);
8971 return std::move(*
this);
9012 set_accept_timeout(timeout);
9013 return std::move(*
this);
9024 set_accept_timeout(std::numeric_limits<double>::infinity());
9025 return std::move(*
this);
9066 set_shutdown_timeout(timeout);
9067 return std::move(*
this);
9078 set_shutdown_timeout(std::numeric_limits<double>::infinity());
9079 return std::move(*
this);
9147 std::string retval(ptr);
9173 add_init_cmd(std::move(cmd));
9174 return std::move(*
this);
9195 set_verbosity(level);
9196 return std::move(*
this);
9232 log_tee(verbosity, filename);
9233 return std::move(*
this);
9274 return std::move(*
this);
9290 to_raw(type), name.c_str(), spec.c_str()
9309 to_raw(type), name.c_str(), executable.c_str(), script.c_str()
9324 if (plugin.get_type() != type) {
9325 throw std::invalid_argument(
"plugin type does not match callback object type");
9328 plugin.get_handle(), name.c_str()
9353 CallbackEntryPoints::spawn_plugin,
9354 CallbackEntryPoints::user_free<callback::SpawnPlugin>,
9415 template<
typename... Args>
9578 start(std::move(data));
9701 return arb(name,
ArbCmd(cmd));
9745 return arb(index,
ArbCmd(cmd));
9758 std::string str(ptr);
9777 std::string str(ptr);
9792 std::string str(ptr);
9811 std::string str(ptr);
9826 std::string str(ptr);
9845 std::string str(ptr);
9936 add_plugin(std::move(plugin));
9937 return std::move(*
this);
9966 return std::move(*
this);
10015 set_reproduction_style(style);
10016 return std::move(*
this);
10055 return std::move(*
this);
10079 set_dqcsim_verbosity(level);
10080 return std::move(*
this);
10120 set_stderr_verbosity(level);
10121 return std::move(*
this);
10161 log_tee(verbosity, filename);
10162 return std::move(*
this);
10195 CallbackEntryPoints::user_free<callback::Log>,
10243 set_log_callback_ptr(verbosity,
new callback::Log(std::move(data)));
10264 template<
typename... Args>
10266 set_log_callback_ptr(verbosity,
new callback::Log(args...));
10291 return std::move(*
this);
10315 set_log_callback_ptr(verbosity,
new callback::Log(std::move(data)));
10316 return std::move(*
this);
10339 template<
typename... Args>
10341 set_log_callback_ptr(verbosity,
new callback::Log(args...));
10342 return std::move(*
this);
10402 sim.
run(std::move(data));
10437 #ifdef DQCSIM_SHORT_LOGGING_MACROS
10440 #ifndef _DQCSIM_LOGGING_INCLUDED_
10441 #define _DQCSIM_LOGGING_INCLUDED_
10452 #define TRACE DQCSIM_TRACE
10461 #define DEBUG DQCSIM_DEBUG
10470 #define INFO DQCSIM_INFO
10479 #define NOTE DQCSIM_NOTE
10488 #define WARN DQCSIM_WARN
10497 #define WARNING DQCSIM_WARNING
10506 #define ERROR DQCSIM_ERROR
10515 #define FATAL DQCSIM_FATAL
10524 #define LOG DQCSIM_LOG
10526 #endif // _DQCSIM_LOGGING_INCLUDED_
10529 #endif // DQCSIM_SHORT_LOGGING_MACROS
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.
RunningPluginState(raw::dqcs_plugin_state_t state)
Hidden constructor, only to be used by the callback wrappers.
bool is_oper(const std::string &oper) const
Returns whether this command has the given operation identifier.
Measurement(Measurement &&handle)=default
Default move constructor.
QubitSet & operator=(QubitSet &&)=default
Default move assignment.
PluginProcessConfiguration && with_stderr_loglevel(Loglevel level)
Configures the capture mode for the stderr stream of the specified plugin process (builder pattern).
ssize_t dqcs_cq_len(dqcs_handle_t cq)
Returns the number of ArbCmd objects in the given ArbCmd queue.
virtual ~Handle() noexcept
Delete the handle and its wrapper.
dqcs_return_t dqcs_meas_value_set(dqcs_handle_t meas, dqcs_measurement_t value)
Sets the measurement value associated with a measurement object.
MeasurementValue get_value() const
Returns the measurement value.
dqcs_handle_t dqcs_qbset_copy(dqcs_handle_t qbset)
Returns a copy of the given qubit set, intended for non-destructive iteration.
@ Gate
Indicates that a handle is a Gate.
dqcs_handle_t dqcs_sim_new(dqcs_handle_t scfg)
Constructs a DQCsim simulation.
Plugin && with_gate(callback::Gate &&cb)
Assigns the gate callback function from a pre-existing callback::Gate object by move.
QubitIndex get_index() const noexcept
Returns the raw qubit index.
Matrix(Matrix &&)=default
Default move constructor.
@ DQCS_GATE_TYPE_INVALID
Invalid gate type.
static Gate predefined(PredefinedGate gate, const QubitSet &qubits, const ArbData ¶meters)
Constructs a new predefined gate.
QubitRef(const QubitRef &)=default
Default copy constructor.
Simulation build()
Constructs the DQCsim simulation from this configuration object.
Plugin && with_advance(const callback::Advance &cb)
Assigns the advance callback function from a pre-existing callback::Advance object by copy.
@ DQCS_GATE_U2
Any two-qubit unitary gate, parameterized as a full unitary matrix.
uint64_t random_u64() noexcept
Generates a random integer using the simulator random seed.
dqcs_handle_t dqcs_sim_recv(dqcs_handle_t sim)
Waits for the simulated accelerator to send a message to us.
dqcs_handle_t dqcs_gate_new_custom(const char *name, dqcs_handle_t targets, dqcs_handle_t controls, dqcs_handle_t measures, dqcs_handle_t matrix)
Constructs a new custom gate.
unsigned long long dqcs_handle_t
Type for a handle.
Matrix(PredefinedGate gate, const ArbData ¶meters)
Constructs a predefined matrix, using ArbData to represent the parameters for parameterized gates.
bool approx_eq(const Matrix &other, double epsilon=0.000001, bool ignore_global_phase=true) const
Approximate equality operator for two matrices.
void set_accept_timeout(double timeout)
Configures the timeout for the plugin process to connect to DQCsim.
Class wrapper for handles that support the arb interface.
char * dqcs_tcfg_name(dqcs_handle_t tcfg)
Returns the configured name for the given plugin thread.
ArbData arb(ssize_t index, ArbCmd &&cmd)
Sends an ArbCmd (passed by move) to the given plugin (referenced by index).
@ DQCS_HTYPE_MEAS_SET
Indicates that the given handle belongs to a set of qubit measurement results.
void start()
Starts a program on the simulated accelerator without an argument.
QubitSet()
Constructs an empty qubit set.
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.
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.
ssize_t dqcs_arb_cbor_get(dqcs_handle_t arb, void *obj, size_t obj_size)
Returns the JSON/CBOR object of an ArbData object in the form of a CBOR object.
@ DQCS_GATE_RY_180
Ry(180°) gate.
ArbCmdQueue && with(const Cmd &cmd)
Pushes an ArbCmd into the queue by copying (builder pattern).
static Gate measure(const QubitSet &measures)
Constructs a new Z-axis measurement gate.
void set_stdout_loglevel(Loglevel level)
Configures the capture mode for the stdout stream of the specified plugin process.
PluginThreadConfiguration && with_verbosity(Loglevel level)
Sets the logging verbosity level of the plugin (builder pattern).
void set_arb(const Arb &src)
Assigns all arb data from the given arb to this one.
static Gate unitary(QubitSet &&targets, QubitSet &&controls, const Matrix &matrix)
Constructs a new custom unitary gate with control qubits.
ArbData & operator=(ArbData &&)=default
Default move assignment.
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.
void disable_reproduction()
Disables the reproduction logging system.
PluginJoinHandle(HandleIndex handle) noexcept
Wraps the given plugin join handle.
T random() noexcept
Generates a random value using the simulator random seed.
ArbData(ArbData &&)=default
Default move constructor.
Plugin && with_upstream_arb(callback::Arb &&cb)
Assigns the upstream-arb callback function from a pre-existing callback::Arb object by move.
ArbData arb(const std::string &name, ArbCmd &&cmd)
Sends an ArbCmd (passed by move) to the given plugin (referenced by instance name).
ArbData & with_arg(const T &data)
Pushes a value of type T to the back of the arbitrary argument list (builder pattern).
PluginConfigurationBuilder(PluginType type) noexcept
Constructs a plugin configuration builder for the given plugin type.
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.
raw::dqcs_handle_type_t to_raw(HandleType type) noexcept
Converts a HandleType to its raw C enum.
@ DQCS_HTYPE_GATE_MAP
Indicates that the given handle belongs to a gate map.
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.
@ DQCS_GATE_RX_M90
Rx(-90°) gate.
std::string get_version(const std::string &name)
Queries the version of a plugin, referenced by instance name.
Simulation run(const ArbData &data)
Constructs the DQCsim simulation from this configuration object, and runs a program on the simulated ...
Callback(T *instance, R(T::*cb)(Args...)) noexcept
Constructs the callback wrapper from a member function.
bool contains(const QubitRef &qubit) const
Returns whether the given qubit is contained in the set.
GateType get_type() const
Returns the type of this gate.
virtual bool detect(Gate &&gate, QubitSet &qubits, ArbData ¶ms) const
The to-be-implemented detector function.
dqcs_return_t dqcs_arb_assign(dqcs_handle_t dest, dqcs_handle_t src)
Copies the data from one object to another.
@ DQCS_HTYPE_INVALID
Indicates that the given handle is invalid.
@ DQCS_HTYPE_GATE
Indicates that the given handle belongs to a quantum gate description.
dqcs_bool_return_t dqcs_mat_basis_approx_eq(dqcs_handle_t a, dqcs_handle_t b, double epsilon)
Approximately compares two basis matrices.
void unset_env_var(const std::string &key)
Removes/unsets an environment variable for the plugin process.
MeasurementSet & operator=(MeasurementSet &&)=default
Default move assignment.
@ DQCS_GATE_RX_90
Rx(90°) gate.
MeasurementSet & operator=(MeasurementSet &src)
Copy-assigns a measurement set object.
dqcs_return_t dqcs_pdef_set_drop_cb(dqcs_handle_t pdef, dqcs_return_t(*callback)(void *user_data, dqcs_plugin_state_t state), void(*user_free)(void *user_data), void *user_data)
Sets the user logic drop/cleanup callback.
@ DQCS_GATE_S
The S matrix, also known as a 90 degree Z rotation.
dqcs_handle_t dqcs_gate_new_prep(dqcs_handle_t targets, dqcs_handle_t matrix)
Constructs a new prep gate.
bool has_controls() const
Returns whether this gate has control qubits.
static Gate custom(const std::string &name, QubitSet &&targets)
Constructs a new custom gate with only target qubits.
dqcs_handle_t dqcs_plugin_recv(dqcs_plugin_state_t plugin)
Waits for a message from the host.
@ DQCS_GATE_RX_180
Rx(180°) gate.
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.
@ Matrix
Indicates that a handle is a Matrix.
ArbCmd(const ArbCmd &src)
Copy-constructs an ArbCmd object from another ArbCmd object.
@ DQCS_HTYPE_ARB_CMD_QUEUE
Indicates that the given handle belongs to a queue of ArbCmd object.
char * dqcs_pdef_name(dqcs_handle_t pdef)
Returns the plugin name for the given plugin definition object.
Measurement take(const QubitRef &qubit)
Moves the measurement object for the given qubit out of the set.
Cycle advance(Cycle cycles)
Tells the downstream plugin to run for the specified number of cycles.
Plugin && with_host_arb(callback::Arb &&cb)
Assigns the host-arb callback function from a pre-existing callback::Arb object by move.
Wrapper class for configuring a simulation.
dqcs_return_t dqcs_sim_send(dqcs_handle_t sim, dqcs_handle_t data)
Sends a message to the simulated accelerator.
Class that you can inherit from to make your own unitary gate converter for use within DQCsim.
dqcs_return_t dqcs_sim_start(dqcs_handle_t sim, dqcs_handle_t data)
Starts a program on the simulated accelerator.
@ DQCS_BOOL_FAILURE
The function has failed.
ssize_t dqcs_qbset_len(dqcs_handle_t qbset)
Returns the number of qubits in the given set.
Loglevel get_stderr_loglevel() const
Returns the configured stderr capture mode for the specified plugin process.
Plugin && with_gate(const callback::Gate &cb)
Assigns the gate callback function from a pre-existing callback::Gate object by copy.
dqcs_return_t dqcs_pdef_set_host_arb_cb(dqcs_handle_t pdef, dqcs_handle_t(*callback)(void *user_data, dqcs_plugin_state_t state, dqcs_handle_t cmd), void(*user_free)(void *user_data), void *user_data)
Sets the callback function function for handling an arb from the host.
@ DQCS_GATE_S_DAG
The S-dagger matrix, also known as a negative 90 degree Z rotation.
void set_arb_arg_strings(const T &strings)
Sets the arbitrary argument list to the given iterable of std::strings.
dqcs_handle_type_t
Enumeration of types that can be associated with a handle.
HandleIndex get_handle() const noexcept
Returns the raw handle without relinquishing ownership.
static Gate predefined(PredefinedGate gate, const QubitSet &qubits)
Constructs a new non-parameterized predefined gate.
@ DQCS_BASIS_X
The X basis.
dqcs_return_t dqcs_arb_remove(dqcs_handle_t arb, ssize_t index)
Removes the specified unstructured string argument from the list.
@ DQCS_GATE_RX
The matrix for an arbitrary X rotation.
Plugin && with_allocate(callback::Allocate &&cb)
Assigns the allocate callback function from a pre-existing callback::Allocate object by move.
Matrix(HandleIndex handle) noexcept
Wraps the given matrix handle.
ArbCmdQueue(ArbCmdQueue &src)
Copy-constructs a queue of ArbCmds.
void add_init_cmd(ArbCmd &&cmd) override
Attaches an arbitrary initialization command to the plugin.
Class wrapper for queues (lists) of ArbCmds.
void set_arb_cbor_string(const std::string &cbor)
Sets the arbitrary JSON data to the given serialized CBOR string.
dqcs_loglevel_t
Enumeration of loglevels and logging modes.
SimulationConfiguration(HandleIndex handle) noexcept
Wraps the given simulation configuration handle.
GateMap && with_measure(const Unbound &key, const Matrix &basis, double epsilon=0.000001, int num_measures=-1)
Adds a measurement gate mapping.
ArbData arb(const ArbCmd &cmd)
Sends an arbitrary command downstream.
@ DQCS_GATE_INVALID
Invalid gate. Used as an error return value.
PluginJoinHandle(PluginJoinHandle &&)=default
Default move constructor.
void set_arb_arg(ssize_t index, const T &data)
Sets the arbitrary argument at the given index to a value of type T.
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.
ArbData arb(const std::string &name, const ArbCmd &cmd)
Sends an ArbCmd (passed by copy) to the given plugin (referenced by instance name).
char * dqcs_sim_get_author_idx(dqcs_handle_t sim, ssize_t index)
Queries the author of a plugin, referenced by index.
std::string get_author() const
Returns the author of the described plugin.
Measurement(HandleIndex handle) noexcept
Wraps the given measurement handle.
dqcs_return_t dqcs_plugin_gate(dqcs_plugin_state_t plugin, dqcs_handle_t gate)
Tells the downstream plugin to execute a gate.
static Gate custom(const std::string &name, const QubitSet &targets)
Constructs a new custom gate with only target qubits.
SimulationConfiguration && with_reproduction_style(PathStyle style)
Sets the path style used when writing reproduction files (builder pattern).
dqcs_handle_t dqcs_mat_predef(dqcs_predefined_gate_t gate_type, dqcs_handle_t param_data)
Constructs a new gate matrix for one of DQCsim's predefined gates.
dqcs_loglevel_t dqcs_pcfg_stdout_mode_get(dqcs_handle_t pcfg)
Returns the configured stdout capture mode for the specified plugin process.
void push_arb_arg_string(const std::string &data)
Pushes a (binary) string to the back of the arbitrary argument list.
dqcs_return_t dqcs_pcfg_work_set(dqcs_handle_t pcfg, const char *work)
Overrides the working directory for the plugin process.
void free(QubitSet &&qubits)
Frees the given downstream qubits.
Loglevel get_stdout_loglevel() const
Returns the configured stdout capture mode for the specified plugin process.
std::string pop_arb_arg_string()
Pops from the back of the arbitrary argument list as a (binary) string.
std::string get_script() const
Returns the configured script path for the plugin.
GateMap && with_unitary(Unbound &&key, const std::shared_ptr< CustomUnitaryGateConverter > &converter)
Adds a custom unitary gate mapping.
void set_value(MeasurementValue value)
Sets the measurement value.
PluginThreadConfiguration with_callbacks(Plugin &&plugin)
Builds a plugin thread configuration object from a plugin definition object, containing a bunch of ca...
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.
@ Simulation
Indicates that a handle is a Simulation.
bool has_matrix() const
Returns whether this gate has a matrix.
QubitRef(QubitIndex index)
Wraps a raw reference.
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 ...
Gate & with_json_string(const std::string &json)
Sets the arbitrary JSON data to the given serialized JSON string (builder pattern).
ArbCmd & with_json_string(const std::string &json)
Sets the arbitrary JSON data to the given serialized JSON string (builder pattern).
@ DQCS_LOG_ERROR
This loglevel is to be used for reporting or propagating a non-fatal error caused by the API caller d...
Measurement & with_arg(const T &data)
Pushes a value of type T to the back of the arbitrary argument list (builder pattern).
Plugin && with_drop(Args... args)
Assigns the drop callback function by constructing the callback object implicitly.
dqcs_handle_t dqcs_mat_strip_control(dqcs_handle_t mat, double epsilon, bool ignore_global_phase, ssize_t **control_indices)
Splits a controlled matrix into its non-controlled submatrix and the indices of the control qubits.
ssize_t dqcs_mat_len(dqcs_handle_t mat)
Returns the number of complex entries in the given matrix.
PluginThreadConfiguration with_spawner(const callback::SpawnPlugin &data)
Builds a plugin thread configuration object using a single callback that spawns the entire plugin.
Builder class used to construct plugin configurations.
Gate construct(const Unbound &unbound, const QubitSet &qubits)
Uses a gate map object to construct a DQCsim gate from the plugin's representation.
double get_shutdown_timeout() const
Returns the configured timeout for the plugin process to shut down gracefully.
dqcs_loglevel_t dqcs_pcfg_stderr_mode_get(dqcs_handle_t pcfg)
Returns the configured stderr capture mode for the specified plugin process.
dqcs_return_t dqcs_mset_set(dqcs_handle_t mset, dqcs_handle_t meas)
Adds a measurement result to a measurement result set.
ssize_t dqcs_arb_len(dqcs_handle_t arb)
Returns the number of unstructured arguments, or -1 to indicate failure.
void add_plugin(PluginConfiguration &&plugin)
Appends a plugin to a simulation configuration.
char * dqcs_sim_get_version(dqcs_handle_t sim, const char *name)
Queries the version of a plugin, referenced by instance name.
@ DQCS_HTYPE_FRONT_PROCESS_CONFIG
Indicates that the given handle belongs to a frontend plugin process configuration object.
PluginThreadConfiguration(PluginThreadConfiguration &&)=default
Default move constructor.
SimulationConfiguration && with_log_tee(Loglevel verbosity, const std::string &filename)
Configures DQCsim to also output its log messages to a file (builder pattern).
dqcs_return_t dqcs_plugin_run(dqcs_handle_t pdef, const char *simulator)
Executes a plugin in the current thread.
raw::dqcs_qubit_t QubitIndex
C++-styled type name for raw::dqcs_qubit_t.
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).
dqcs_handle_t dqcs_gate_matrix(dqcs_handle_t gate)
Returns a copy of the unitary matrix associated with this gate, if one exists.
void 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.
static Plugin Backend(const std::string &name, const std::string &author, const std::string &version)
Shorthand for constructing a new backend plugin.
std::string dump() const
Returns a string containing a debug dump of the handle.
dqcs_plugin_type_t dqcs_tcfg_type(dqcs_handle_t tcfg)
Returns the type of the given plugin thread configuration.
dqcs_handle_t dqcs_mset_take_any(dqcs_handle_t mset)
Returns the measurement result for any of the qubits contained in a measurement result set and remove...
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.
GateType
Enumeration of gate types supported by DQCsim.
dqcs_handle_t dqcs_pdef_new(dqcs_plugin_type_t typ, const char *name, const char *author, const char *version)
Creates a new PluginDefinition object.
dqcs_return_t dqcs_cq_next(dqcs_handle_t cq)
Advances an ArbCmd queue to the next command.
Plugin && with_host_arb(const callback::Arb &cb)
Assigns the host-arb callback function from a pre-existing callback::Arb object by copy.
QubitRef & operator=(const QubitRef &)=default
Default copy assignment.
dqcs_handle_t dqcs_qbset_new(void)
Creates a new set of qubit references.
dqcs_return_t
Default return type for functions that don't need to return anything.
dqcs_bool_return_t dqcs_mat_approx_unitary(dqcs_handle_t matrix, double epsilon)
Returns whether the matrix is approximately unitary.
QubitSet && with(const QubitRef &qubit)
Pushes a qubit into the set (builder pattern).
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.
char * dqcs_sim_get_author(dqcs_handle_t sim, const char *name)
Queries the author of a plugin, referenced by instance name.
dqcs_return_t dqcs_meas_qubit_set(dqcs_handle_t meas, dqcs_qubit_t qubit)
Sets the qubit reference associated with a measurement object.
@ DQCS_LOG_OFF
Turns logging off.
@ ArbCmd
Indicates that a handle is an ArbCmd.
Plugin && with_initialize(Args... args)
Assigns the initialize callback function by constructing the callback object implicitly.
Represents a set of measurements.
Gate & with_arg_string(const std::string &data)
Pushes a (binary) string to the back of the arbitrary argument list (builder pattern).
Measurement & operator=(Measurement &&)=default
Default move assignment.
@ DQCS_GATE_TYPE_INVALID
Invalid gate type. Used as an error return value.
dqcs_return_t dqcs_pdef_set_gate_cb(dqcs_handle_t pdef, dqcs_handle_t(*callback)(void *user_data, dqcs_plugin_state_t state, dqcs_handle_t gate), void(*user_free)(void *user_data), void *user_data)
Sets the gate execution callback for operators and backends.
void measure_z(const QubitRef &q)
Shorthand for sending a single-qubit Z-axis measurement to the downstream plugin.
void set_arb_json_string(const std::string &json)
Sets the arbitrary JSON data to the given serialized JSON string.
dqcs_handle_t dqcs_arb_new(void)
Creates a new ArbData object.
void log_tee(Loglevel verbosity, const std::string &filename) override
Configures a plugin thread to also output its log messages to a file.
MeasurementSet()
Constructs an empty measurement set.
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.
QubitSet(HandleIndex handle) noexcept
Wraps the given qubit set handle.
@ DQCS_HTYPE_OPER_PROCESS_CONFIG
Indicates that the given handle belongs to an operator plugin process configuration object.
ArbCmd & with_arg_string(const std::string &data)
Pushes a (binary) string to the back of the arbitrary argument list (builder pattern).
static Gate custom(const std::string &name)
Constructs a new custom gate without qubit operands.
friend std::ostream & operator<<(std::ostream &out, const QubitRef &qubit)
Allow qubit references to be printed.
dqcs_cycle_t dqcs_plugin_get_cycle(dqcs_plugin_state_t plugin)
Returns the current value of the downstream cycle counter.
dqcs_return_t dqcs_pcfg_accept_timeout_set(dqcs_handle_t pcfg, double timeout)
Configures the timeout for the plugin process to connect to DQCsim.
GateMap && with_measure(Unbound &&key, PauliBasis basis=PauliBasis::Z, double epsilon=0.000001, int num_measures=-1)
Adds a measurement gate mapping.
Plugin & operator=(Plugin &&)=default
Default move assignment.
PluginProcessConfiguration && with_init_cmd(ArbCmd &&cmd)
Attaches an arbitrary initialization command to the plugin (builder pattern).
dqcs_bool_return_t dqcs_mat_is_predef(dqcs_handle_t mat, dqcs_predefined_gate_t gate_type, dqcs_handle_t *param_data, double epsilon, bool ignore_gphase)
Returns whether this matrix is of the given predefined form and, if it is, any parameters needed to d...
dqcs_return_t dqcs_scfg_stderr_verbosity_set(dqcs_handle_t scfg, dqcs_loglevel_t level)
Configures the stderr sink verbosity for a simulation.
PluginConfiguration(HandleIndex handle) noexcept
Wraps the given plugin process or thread configuration handle.
@ DQCS_GATE_TYPE_PREP
Prep gates have one or more target qubits and a 2x2 unitary matrix representing the basis.
dqcs_return_t dqcs_plugin_send(dqcs_plugin_state_t plugin, dqcs_handle_t arb)
Sends a message to the host.
Plugin && with_gate(Args... args)
Assigns the gate callback function by constructing the callback object implicitly.
@ DQCS_FAILURE
The function has failed.
ArbData arb(ArbCmd &&cmd)
Sends an arbitrary command downstream.
@ GateMap
Indicates that a handle is a GateMap.
dqcs_gate_type_t
Types of DQCsim gates.
bool basis_approx_eq(const Matrix &other, double epsilon=0.000001) const
Approximate equality operator for two basis matrices.
@ DQCS_PTYPE_FRONT
Frontend plugin.
void set_log_callback(Loglevel verbosity, const callback::Log &data)
Configures DQCsim to also output its log messages to callback function.
QubitSet allocate(size_t num_qubits)
Allocates a number of default downstream qubits.
PluginConfigurationBuilder && with_name(const std::string &name) noexcept
Builder function for naming the plugin instance.
UpstreamPluginState(raw::dqcs_plugin_state_t state)
Hidden constructor, only to be used by the callback wrappers.
static Gate unitary(const QubitSet &targets, const QubitSet &controls, const Matrix &matrix)
Constructs a new custom unitary gate with control qubits.
void start(ArbData &&data)
Starts a program on the simulated accelerator using the given ArbData object as an argument (passed b...
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.
void set_work_dir(const std::string &dir)
Overrides the working directory for the plugin process.
std::vector< ArbCmd > drain_into_vector()
Drains the queue into a vector of ArbCmds.
static Gate measure(const QubitSet &measures, PauliBasis basis)
Constructs a new measurement gate, measuring in the given Pauli basis.
void set_dqcsim_verbosity(Loglevel level)
Configures the logging verbosity for DQCsim's own messages.
GateMap & operator=(GateMap &&)=default
Default move assignment.
void set_stderr_verbosity(Loglevel level)
Configures the stderr sink verbosity for a simulation.
Callback< void, PluginState & > Drop
Callback wrapper specialized for the drop callback.
@ DQCS_GATE_U1
Any single-qubit unitary gate, parameterized as a full unitary matrix.
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.
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.
void gate(Gate &&gate)
Sends a gate to the downstream plugin.
std::vector< Measurement > drain_into_vector()
Drains the measurement set into a vector.
Matrix(PauliBasis basis)
Constructs a Pauli basis matrix.
std::string get_name() const override
Returns the name given to the plugin.
PluginType
Enumeration of the three types of plugins.
Callback< ArbData, RunningPluginState &, ArbData && > Run
Callback wrapper specialized for the run callback.
void log_tee(Loglevel verbosity, const std::string &filename) override
Configures a plugin thread to also output its log messages to a file.
@ DQCS_PTYPE_INVALID
Invalid plugin type.
size_t size() const
Returns the number of measurements in the set.
static Gate prep(const QubitSet &targets)
Constructs a new Z-axis prep gate, putting the qubits in the |0> state.
PluginConfigurationBuilder Frontend(const std::string &name="") noexcept
Shorthand for constructing a frontend plugin configuration builder.
std::vector< complex > get() const
Returns the data contained by the matrix in row-major form as complex numbers.
dqcs_loglevel_t dqcs_scfg_stderr_verbosity_get(dqcs_handle_t scfg)
Returns the configured stderr sink verbosity for a simulation.
std::string get_name() const override
Returns the name given to the plugin.
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.
static MeasurementSet from_iter(const T &measurements)
Constructs a measurement set object from an iterable of measurements.
@ DQCS_GATE_TYPE_MEASUREMENT
Measurement gates have one or more measured qubits and a 2x2 unitary matrix representing the basis.
dqcs_return_t dqcs_tcfg_verbosity_set(dqcs_handle_t tcfg, dqcs_loglevel_t level)
Configures the logging verbosity for the given plugin thread.
Loglevel
Represents the loglevel of a message, a loglevel filter level, or one of the possible actions to take...
GateMap(HandleIndex handle) noexcept
Wraps the given gate map handle.
const raw::dqcs_plugin_state_t state
The wrapped plugin state.
Cmd(HandleIndex handle) noexcept
Wraps the given cmd handle.
@ DQCS_MEAS_INVALID
Error value used to indicate that something went wrong.
QubitRef & operator=(QubitRef &&)=default
Default move assignment.
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.
Bound convert(const Gate &gate)
Wrapper function for detect(), converting from DQCsim's gate representation directly to the plugin's ...
@ DQCS_HTYPE_FRONT_DEF
Indicates that the given handle belongs to a frontend plugin definition object.
@ DQCS_PATH_STYLE_INVALID
Error value used to indicate that something went wrong.
dqcs_measurement_t dqcs_meas_value_get(dqcs_handle_t meas)
Returns the measurement value associated with a measurement object.
@ Off
In the context of a filter, turns logging off.
@ DQCS_HTYPE_MEAS
Indicates that the given handle belongs to a qubit measurement result.
Provides DQCsim's raw C API symbols in the dqcsim::raw namespace.
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.
SimulationConfiguration && with_log_callback(Loglevel verbosity, const callback::Log &data)
Configures DQCsim to also output its log messages to callback function (builder pattern).
static Plugin Frontend(const std::string &name, const std::string &author, const std::string &version)
Shorthand for constructing a new frontend plugin.
Plugin && with_drop(callback::Drop &&cb)
Assigns the drop callback function from a pre-existing callback::Drop object by move.
PluginJoinHandle & operator=(PluginJoinHandle &&)=default
Default move assignment.
std::string get_version(ssize_t index)
Queries the version of a plugin, referenced by index.
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.
Plugin(PluginType type, const std::string &name, const std::string &author, const std::string &version)
Constructs a new plugin definition object.
dqcs_return_t dqcs_arb_clear(dqcs_handle_t arb)
Clears the unstructured argument list.
static Gate custom(const std::string &name, const QubitSet &targets, const Matrix &matrix)
Constructs a new custom gate with target qubits and a matrix.
void set_verbosity(Loglevel level) override
Sets the logging verbosity level of the plugin.
dqcs_handle_t dqcs_mat_add_controls(dqcs_handle_t mat, size_t number_of_controls)
Constructs a controlled matrix from the given matrix.
const char * dqcs_error_get()
Returns a pointer to the latest error message.
friend std::ostream & operator<<(std::ostream &out, const Handle &handle)
Write the debug dump string of the handle to the given output stream.
GateMap && with_custom(const Unbound &key, const std::shared_ptr< CustomGateConverter > &converter)
Adds a custom gate mapping.
@ DQCS_HTYPE_MATRIX
Indicates that the given handle belongs to a matrix.
dqcs_loglevel_t dqcs_scfg_dqcsim_verbosity_get(dqcs_handle_t scfg)
Returns the configured verbosity for DQCsim's own messages.
ArbData(HandleIndex handle) noexcept
Wraps the given ArbData handle.
@ PluginJoinHandle
Indicates that a handle is a PluginJoinHandle.
@ DQCS_LOG_TRACE
This loglevel is to be used for reporting debugging information useful for debugging the internals of...
Cycle get_cycle()
Returns the current value of the downstream cycle counter.
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.
Wrapper class for local plugin thread configurations.
T pop_arb_arg_as() const
Pops from the back of the arbitrary argument list as a value of type T.
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.
@ QubitSet
Indicates that a handle is a QubitSet.
Gate(Gate &&)=default
Default move constructor.
Plugin && with_allocate(const callback::Allocate &cb)
Assigns the allocate callback function from a pre-existing callback::Allocate object by copy.
Simulation run()
Constructs the DQCsim simulation from this configuration object, and runs a program on the simulated ...
void operator=(const Measurement &src)
Copy assignment operator for Measurement objects.
dqcs_handle_t dqcs_gate_controls(dqcs_handle_t gate)
Returns a handle to a new qubit reference set containing the qubits that control this gate.
dqcs_return_t dqcs_pcfg_stdout_mode_set(dqcs_handle_t pcfg, dqcs_loglevel_t level)
Configures the capture mode for the stdout stream of the specified plugin process.
ArbCmd & with_arg(const T &data)
Pushes a value of type T to the back of the arbitrary argument list (builder pattern).
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.
GateMap && with_measure(Unbound &&key, Matrix &&basis, double epsilon=0.000001, int num_measures=-1)
Adds a measurement gate mapping.
ArbData run()
Runs a program on the simulated accelerator without an argument.
@ MeasurementSet
Indicates that a handle is a MeasurementSet.
Cycle get_cycles_since_measure(const QubitRef &qubit)
Returns the number of downstream cycles since the latest measurement of the given downstream qubit.
void wait()
Waits for the plugin to terminate.
Plugin && with_modify_measurement(callback::ModifyMeasurement &&cb)
Assigns the modify-measurement callback function from a pre-existing callback::ModifyMeasurement obje...
PauliBasis
Enumeration of Pauli bases.
void operator=(const ArbCmd &src)
Copy assignment operator for ArbCmd objects.
void measure_y(const QubitRef &q)
Shorthand for sending a single-qubit Y-axis measurement to the downstream plugin.
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.
Plugin && with_upstream_arb(Args... args)
Assigns the upstream-arb callback function by constructing the callback object implicitly.
dqcs_basis_t
Enumeration of Pauli bases.
Simulation(Simulation &&)=default
Default move constructor.
size_t size() const
Returns the number of qubits in the set.
ArbCmdQueue()
Constructs an empty ArbCmd queue object.
void run(const char *simulator)
Runs the defined plugin in the current thread with the given simulator connection descriptor string.
void set_log_callback(Loglevel verbosity, callback::Log &&data)
Configures DQCsim to also output its log messages to callback function.
@ DQCS_PTYPE_OPER
Operator plugin.
dqcs_return_t dqcs_arb_set_raw(dqcs_handle_t arb, ssize_t index, const void *obj, size_t obj_size)
Replaces the unstructured argument at the specified index with the specified raw object.
PluginConfigurationBuilder Operator(const std::string &name="") noexcept
Shorthand for constructing an operator plugin configuration builder.
virtual Matrix construct(ArbData ¶ms, ssize_t &num_controls) const
The to-be-implemented constructor function.
bool has_name() const
Returns whether this gate has a name.
QubitSet allocate(size_t num_qubits, ArbCmdQueue &&cmds)
Allocates a number of downstream qubits, copying in the given command queue as arbitrary additional d...
static ArbCmdQueue from_iter(T &&cmds)
Constructs an ArbCmd queue object from an iterable of ArbCmds by moving.
PredefinedGate
Enumeration of unitary gates defined by DQCsim.
@ Zero
Qubit measurement returned zero.
@ Frontend
Frontend plugin.
Gate construct(const Unbound &unbound, const QubitSet &qubits, const ArbData ¶ms)
Uses a gate map object to construct a DQCsim gate from the plugin's representation.
dqcs_return_t dqcs_pdef_set_run_cb(dqcs_handle_t pdef, dqcs_handle_t(*callback)(void *user_data, dqcs_plugin_state_t state, dqcs_handle_t args), void(*user_free)(void *user_data), void *user_data)
Sets the run callback for frontends.
dqcs_plugin_type_t dqcs_pcfg_type(dqcs_handle_t pcfg)
Returns the type of the given plugin process configuration.
Base class for wrapping any handle.
dqcs_handle_t dqcs_meas_new(dqcs_qubit_t qubit, dqcs_measurement_t value)
Constructs a new measurement object.
std::vector< QubitRef > copy_into_vector() const
Copies the qubit set into a vector.
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.
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.
Callback< void, PluginState &, ArbCmdQueue && > Initialize
Callback wrapper specialized for the initialize callback.
Loglevel get_verbosity() const override
Returns the current logging verbosity level of the plugin.
dqcs_bool_return_t dqcs_gate_has_controls(dqcs_handle_t gate)
Returns whether the specified gate has control qubits.
Simulation run(ArbData &&data)
Constructs the DQCsim simulation from this configuration object, and runs a program on the simulated ...
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.
MeasurementSet(MeasurementSet &&handle)=default
Default move constructor.
Cycle get_cycles_between_measures(const QubitRef &qubit)
Returns the number of downstream cycles between the last two measurements of the given downstream qub...
PluginProcessConfiguration && without_accept_timeout()
Disables the timeout for the plugin process to connect to DQCsim (builder pattern).
dqcs_gate_type_t dqcs_gate_type(dqcs_handle_t gate)
Returns the gate type of the given gate.
void push(const QubitRef &qubit)
Pushes a qubit into the set.
@ ArbCmdQueue
Indicates that a handle is an ArbCmdQueue.
@ DQCS_PATH_STYLE_KEEP
Specifies that paths should be saved the same way they were specified on the command line.
GateMap && with_prep(const Unbound &key, PauliBasis basis=PauliBasis::Z, double epsilon=0.000001, int num_targets=-1)
Adds a prep gate mapping.
Generic class for plugin configurations.
char * dqcs_pdef_version(dqcs_handle_t pdef)
Returns the plugin version for the given plugin definition object.
unsigned long long dqcs_qubit_t
Type for a qubit reference.
static Gate custom(const std::string &name, const QubitSet &targets, const QubitSet &controls)
Constructs a new custom gate with target qubits and control qubits.
void measure_x(const QubitSet &qs)
Shorthand for sending a multi-qubit X-axis measurement to the downstream plugin.
bool contains(const QubitRef &qubit) const
Returns whether the set contains measurement data for the given qubit.
Plugin && with_initialize(callback::Initialize &&cb)
Assigns the initialize callback function from a pre-existing callback::Initialize object by move.
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.
char * dqcs_gate_name(dqcs_handle_t gate)
Returns the name of a custom gate.
dqcs_return_t dqcs_tcfg_init_cmd(dqcs_handle_t tcfg, dqcs_handle_t cmd)
Appends an ArbCmd to the list of initialization commands of a plugin thread.
size_t dimension() const
Returns the number of rows/columns in the matrix.
static Gate prep(QubitSet &&targets, Matrix &&basis)
Constructs a new prep gate for a custom initial state.
std::string get_arb_cbor_string() const
Returns the current arbitrary JSON data as a serialized CBOR string.
dqcs_return_t dqcs_pcfg_env_unset(dqcs_handle_t pcfg, const char *key)
Removes/unsets an environment variable for the plugin process.
Plugin && with_allocate(Args... args)
Assigns the allocate callback function by constructing the callback object implicitly.
void free(const QubitSet &qubits)
Frees the given downstream qubits.
void remove_arb_arg(ssize_t index)
Removes the arbitrary argument at the given index.
PluginConfiguration & operator=(PluginConfiguration &&)=default
Default move assignment.
dqcs_handle_t dqcs_mat_add_controls(dqcs_handle_t mat, size_t number_of_controls)
Constructs a controlled matrix from the given matrix.
dqcs_qubit_t dqcs_qbset_pop(dqcs_handle_t qbset)
Pops a qubit reference off of a qubit reference set.
PluginProcessConfiguration && with_shutdown_timeout(double timeout)
Configures the timeout for the plugin process to shut down gracefully (builder pattern).
MeasurementValue
Represents the result of a qubit measurement.
Loglevel get_verbosity() const override
Returns the current logging verbosity level of the plugin.
virtual Gate construct(QubitSet &&qubits, ArbData &¶ms) const
The to-be-implemented constructor function.
double dqcs_pcfg_accept_timeout_get(dqcs_handle_t pcfg)
Returns the configured timeout for the plugin process to connect to DQCsim.
dqcs_return_t dqcs_pdef_set_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.
std::string get_arb_json_string() const
Returns the current arbitrary JSON data as a serialized JSON string.
PluginJoinHandle start(const char *simulator)
Starts the defined plugin in the current thread.
dqcs_return_t dqcs_pdef_set_advance_cb(dqcs_handle_t pdef, dqcs_return_t(*callback)(void *user_data, dqcs_plugin_state_t state, dqcs_cycle_t cycles), void(*user_free)(void *user_data), void *user_data)
Sets the callback for advancing time for operators and backends.
dqcs_return_t dqcs_pcfg_shutdown_timeout_set(dqcs_handle_t pcfg, double timeout)
Configures the timeout for the plugin process to shut down gracefully.
dqcs_handle_t dqcs_gate_measures(dqcs_handle_t gate)
Returns a handle to a new qubit reference set containing the qubits measured by this gate.
@ Unitary
Unitary gates have one or more target qubits, zero or more control qubits, and a unitary matrix,...
Matrix(size_t num_qubits, const complex *matrix)
Constructs a matrix from a row-major flattened array of 4**num_qubits complexs.
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.
Plugin && with_host_arb(Args... args)
Assigns the host-arb callback function by constructing the callback object implicitly.
long long dqcs_cycle_t
Type for a simulation cycle timestamp.
dqcs_return_t dqcs_sim_yield(dqcs_handle_t sim)
Yields to the simulator.
MeasurementSet(MeasurementSet &src)
Copy-constructs a measurement set object.
Represents an ordered set of qubit references.
QubitRef allocate()
Allocates a single downstream qubit.
Gate & with_json(const JSON &json)
Sets the arbitrary JSON data to the given JSON object from nlohmann::json (builder pattern).
ArbCmd(const Cmd &src)
Copy-constructs an ArbCmd object from any object supporting the Cmd interface.
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_handle_t dqcs_cq_new(void)
Creates a new ArbCmd queue object.
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.
Gate(HandleIndex handle) noexcept
Wraps the given Gate handle.
@ DQCS_LOG_DEBUG
This loglevel is to be used for reporting debugging information useful for debugging the user of the ...
static Gate custom(const std::string &name, QubitSet &&targets, QubitSet &&controls)
Constructs a new custom gate with target qubits and control qubits.
void clear_arb_args()
Clears the arbitrary argument list.
void measure_y(const QubitSet &qs)
Shorthand for sending a multi-qubit Y-axis measurement to the downstream plugin.
#define ARB_BUILDER_SUBCLASS
Helper macro to prevent code repetition; not visible outside of the header.
@ ArbData
Indicates that a handle is an ArbData.
Wrapper for DQCsim's internal plugin state within the context of upstream-synchronous plugin callback...
std::vector< ArbCmd > copy_into_vector()
Copies the queue into a vector of ArbCmds.
@ DQCS_GATE_RZ_M90
Rz(-90°) gate.
dqcs_bool_return_t dqcs_gm_detect(dqcs_handle_t gm, dqcs_handle_t gate, const void **key_data, dqcs_handle_t *qubits, dqcs_handle_t *param_data)
Uses a gate map object to convert an incoming DQCsim gate to the plugin's representation.
void send(const ArbData &data)
Sends the given ArbData message to the simulated accelerator (passed by copy).
ArbData & with_cbor_string(const std::string &cbor)
Sets the arbitrary JSON data to the given serialized CBOR string (builder pattern).
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.
Measurement & with_json(const JSON &json)
Sets the arbitrary JSON data to the given JSON object from nlohmann::json (builder pattern).
Matrix & operator=(Matrix &&)=default
Default move assignment.
Plugin && with_run(callback::Run &&cb)
Assigns the run callback function from a pre-existing callback::Run object by move.
dqcs_handle_t dqcs_tcfg_new(dqcs_handle_t pdef, const char *name)
Creates a new plugin thread configuration object from a plugin definition.
Matrix(size_t num_qubits, const double *matrix)
Constructs a matrix from a row-major flattened array of 2 * 4**num_qubits complexs.
Gate construct(const Unbound &unbound, QubitSet &&qubits, ArbData &¶ms)
Uses a gate map object to construct a DQCsim gate from the plugin's representation.
static Plugin Operator(const std::string &name, const std::string &author, const std::string &version)
Shorthand for constructing a new operator plugin.
Gate convert(const Bound &bound)
Wrapper function for construct(), converting directly from the plugin's Bound gate type to DQCsim's g...
SimulationConfiguration(SimulationConfiguration &&)=default
Default move constructor.
void remove(const QubitRef &qubit)
Removes the measurement object for the given qubit from the set.
dqcs_bool_return_t dqcs_gate_has_measures(dqcs_handle_t gate)
Returns whether the specified gate measures any qubits.
Handle() noexcept
Constructs an empty wrapper.
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.
Measurement get_measurement(const QubitRef &qubit)
Returns the latest measurement of the given downstream qubit.
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.
SimulationConfiguration()
Creates a new simulation configuration.
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.
@ Measurement
Indicates that a handle is a Measurement.
GateMap && with_prep(const Unbound &key, const Matrix &basis, double epsilon=0.000001, int num_targets=-1)
Adds a prep gate mapping.
static Gate prep(QubitSet &&targets)
Constructs a new Z-axis prep gate, putting the qubits in the |0> state.
void set_log_callback(Loglevel verbosity, Args... args)
Configures DQCsim to also output its log messages to callback function.
SimulationConfiguration && with_stderr_verbosity(Loglevel level)
Configures the stderr sink verbosity for a simulation (builder pattern).
@ DQCS_GATE_PAULI_I
The identity gate for a single qubit.
char * dqcs_cmd_iface_get(dqcs_handle_t cmd)
Returns the interface ID of an ArbCmd.
dqcs_return_t dqcs_sim_write_reproduction_file(dqcs_handle_t sim, const char *filename)
Writes a reproduction file for the simulation so far.
Callback< MeasurementSet, UpstreamPluginState &, Measurement && > ModifyMeasurement
Callback wrapper specialized for the modify_measurement callback.
@ DQCS_GATE_RY
The matrix for an arbitrary Y rotation.
ArbCmd(ArbCmd &&)=default
Default move constructor.
uint64_t get_seed() const noexcept
Returns the configured random seed.
void operator=(const Matrix &src)
Copy assignment operator for matrices.
void start(const ArbData &data)
Starts a program on the simulated accelerator using the given ArbData object as an argument (passed b...
MeasurementSet && with(Measurement &&measurement)
Moves the given measurement object into the set (builder pattern).
SimulationConfiguration & operator=(SimulationConfiguration &&)=default
Default move assignment.
char * dqcs_pcfg_executable(dqcs_handle_t pcfg)
Returns the configured executable path for the given plugin process.
dqcs_return_t dqcs_gm_add_custom_unitary(dqcs_handle_t gm, void(*key_free)(void *key_data), void *key_data, dqcs_bool_return_t(*detector)(const void *user_data, dqcs_handle_t matrix, size_t num_controls, dqcs_handle_t *param_data), void(*detector_user_free)(void *user_data), void *detector_user_data, dqcs_handle_t(*constructor)(const void *user_data, dqcs_handle_t *param_data, intptr_t *num_controls), void(*constructor_user_free)(void *user_data), void *constructor_user_data)
Adds a custom unitary gate mapping to the given gate map.
dqcs_return_t dqcs_qbset_push(dqcs_handle_t qbset, dqcs_qubit_t qubit)
Pushes a qubit reference into a qubit reference set.
ArbCmd & with_json(const JSON &json)
Sets the arbitrary JSON data to the given JSON object from nlohmann::json (builder pattern).
@ DQCS_HTYPE_INVALID
Indicates that the given handle is invalid.
std::vector< double > get_as_doubles() const
Returns the data contained by the matrix in row-major form as pairs of real/imag doubles.
dqcs_bool_return_t dqcs_gate_has_matrix(dqcs_handle_t gate)
Returns whether a unitary matrix is associated with this gate.
Plugin && with_free(const callback::Free &cb)
Assigns the free callback function from a pre-existing callback::Free object by copy.
Class wrapper for handles that support the cmd interface.
ArbCmd & operator=(ArbCmd &&)=default
Default move assignment.
@ DQCS_HTYPE_FRONT_THREAD_CONFIG
Indicates that the given handle belongs to a frontend plugin thread configuration object.
dqcs_handle_t dqcs_plugin_arb(dqcs_plugin_state_t plugin, dqcs_handle_t cmd)
Sends an arbitrary command downstream.
size_t size() const
Returns the number of elements in the matrix.
ArbData & with_json_string(const std::string &json)
Sets the arbitrary JSON data to the given serialized JSON string (builder pattern).
Loglevel get_stderr_verbosity() const
Returns the configured stderr sink verbosity for a simulation.
@ DQCS_HTYPE_OPER_THREAD_CONFIG
Indicates that the given handle belongs to an operator plugin thread configuration object.
std::string get_author(ssize_t index)
Queries the author of a plugin, referenced by index.
ArbData(const Arb &src)
Copy-constructs an ArbData object from any object supporting the Arb interface.
@ DQCS_HTYPE_ARB_CMD
Indicates that the given handle belongs to an ArbCmd object.
std::string get_iface() const
Returns the interface identifier of this command.
Plugin && with_run(Args... args)
Assigns the run callback function by constructing the callback object implicitly.
GateMap(GateMap &&)=default
Default move constructor.
@ DQCS_HTYPE_QUBIT_SET
Indicates that the given handle belongs to a set of qubit references.
void set(const Measurement &measurement)
Copies the given measurement object into the set.
bool is_valid() const noexcept
Returns whether this wrapper (still) contains a valid handle.
Plugin && with_advance(Args... args)
Assigns the advance callback function by constructing the callback object implicitly.
@ DQCS_LOG_FATAL
This loglevel is to be used for reporting a fatal error, resulting from the owner of the logger getti...
void push(ArbCmd &&cmd)
Pushes an ArbCmd into the queue by moving.
QubitRef allocate(ArbCmdQueue &cmds)
Allocates a single downstream qubit, moving in the given command queue as arbitrary additional data f...
SimulationConfiguration && with_plugin(PluginConfiguration &&plugin)
Appends a plugin to a simulation configuration (builder pattern).
ArbCmd(HandleIndex handle) noexcept
Wraps the given ArbCmd handle.
void measure_z(const QubitSet &qs)
Shorthand for sending a multi-qubit Z-axis measurement to the downstream plugin.
Callback< MeasurementSet, PluginState &, Gate && > Gate
Callback wrapper specialized for the gate callback.
dqcs_handle_t dqcs_sim_wait(dqcs_handle_t sim)
Waits for the simulated accelerator to finish its current program.
ssize_t dqcs_mat_dimension(dqcs_handle_t mat)
Returns the dimension (number of rows == number of columns) of the given matrix.
ArbCmdQueue(ArbCmdQueue &&)=default
Default move constructor.
std::vector< QubitRef > drain_into_vector()
Drains the qubit set into a vector.
Matrix(PredefinedGate gate)
Constructs a non-parameterized predefined matrix.
Class wrapper for plugin join handles.
@ Measurement
Measurement gates have one or more measured qubits and a 2x2 unitary matrix representing the basis.
size_t get_arb_arg_count() const
Returns the number of arbitrary arguments.
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...
PluginProcessConfiguration with_spec(const std::string &spec)
Builds a plugin process configuration object from a "sugared" plugin specification string,...
ArbCmdQueue & operator=(ArbCmdQueue &src)
Copy-assigns a queue of ArbCmds.
PluginProcessConfiguration && with_env_var(const std::string &key, const std::string &value)
Overrides an environment variable for the plugin process (builder pattern).
virtual Loglevel get_verbosity() const =0
Returns the current logging verbosity level of the plugin.
T get_arb_arg_as(ssize_t index) const
Returns the arbitrary argument at the given index as the given type.
dqcs_return_t dqcs_scfg_log_callback(dqcs_handle_t scfg, dqcs_loglevel_t verbosity, void(*callback)(void *user_data, const char *message, const char *logger, dqcs_loglevel_t level, const char *module, const char *file, uint32_t line, uint64_t time_s, uint32_t time_ns, uint32_t pid, uint64_t tid), void(*user_free)(void *user_data), void *user_data)
Configures DQCsim to also output its log messages to callback function.
dqcs_bool_return_t
Return type for functions that normally return a boolean but can also fail.
dqcs_predefined_gate_t
Enumeration of gates defined by DQCsim.
Plugin(HandleIndex handle) noexcept
Wraps the given plugin definition handle.
@ DQCS_GATE_PAULI_Z
The Pauli Z matrix.
QubitSet allocate(size_t num_qubits, ArbCmdQueue &cmds)
Allocates a number of downstream qubits, moving in the given command queue as arbitrary additional da...
GateMap && with_custom(Unbound &&key, const std::shared_ptr< CustomGateConverter > &converter)
Adds a custom gate mapping.
dqcs_qubit_t dqcs_meas_qubit_get(dqcs_handle_t meas)
Returns the qubit reference associated with a measurement object.
@ DQCS_HTYPE_OPER_DEF
Indicates that the given handle belongs to an operator plugin definition object.
PluginProcessConfiguration(PluginProcessConfiguration &&)=default
Default move constructor.
dqcs_measurement_t
Qubit measurement value.
MeasurementSet(HandleIndex handle) noexcept
Wraps the given measurement set handle.
@ DQCS_FALSE
The function did what it was supposed to and returned false.
std::vector< Measurement > copy_into_vector()
Copies the qubit set into a vector.
ArbData & with_json(const JSON &json)
Sets the arbitrary JSON data to the given JSON object from nlohmann::json (builder pattern).
raw::dqcs_cycle_t Cycle
C++-styled type name for raw::dqcs_cycle_t.
PluginProcessConfiguration(HandleIndex handle) noexcept
Wraps the given plugin process configuration handle.
PluginConfiguration(PluginConfiguration &&)=default
Default move constructor.
void push(const Cmd &cmd)
Pushes an ArbCmd into the queue by copying.
@ DQCS_LOG_INVALID
Invalid loglevel.
SimulationConfiguration && without_reproduction()
Disables the reproduction logging system (builder pattern).
GateMap(bool strip_qubit_refs=false, bool strip_data=false)
Constructs a new gate map.
void measure_x(const QubitRef &q)
Shorthand for sending a single-qubit X-axis measurement to the downstream plugin.
PluginThreadConfiguration with_spawner(callback::SpawnPlugin &&data)
Builds a plugin thread configuration object using a single callback that spawns the entire plugin.
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.
QubitSet(const QubitSet &src)
Copy-constructs a qubit set.
Measurement(const QubitRef &qubit, MeasurementValue value)
Constructs a measurement object.
@ DQCS_GATE_T
The T matrix, also known as a 45 degree Z rotation.
@ DQCS_LOG_NOTE
This loglevel is to be used for reporting information specifically requested by the user/API caller,...
void measure_z(QubitSet &&qs)
Shorthand for sending a multi-qubit Z-axis measurement to the downstream plugin.
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.
SimulationConfiguration && with_log_callback(Loglevel verbosity, callback::Log &&data)
Configures DQCsim to also output its log messages to callback function (builder pattern).
ArbData run(const ArbData &data)
Runs a program on the simulated accelerator using the given ArbData object as an argument (passed by ...
void send(ArbData &&message)
Sends a message to the host.
char * dqcs_pcfg_script(dqcs_handle_t pcfg)
Returns the configured script path for the given plugin process.
dqcs_return_t dqcs_plugin_free(dqcs_plugin_state_t plugin, dqcs_handle_t qbset)
Free the given downstream qubits.
@ DQCS_PATH_STYLE_RELATIVE
Specifies that all paths should be saved relative to DQCsim's working directory.
uint64_t dqcs_scfg_seed_get(dqcs_handle_t scfg)
Returns the configured random seed.
QubitSet(QubitSet &&)=default
Default move constructor.
Gate & with_cbor_string(const std::string &cbor)
Sets the arbitrary JSON data to the given serialized CBOR string (builder pattern).
Class wrapper for ArbCmd handles.
ArbData & with_arg_string(const std::string &data)
Pushes a (binary) string to the back of the arbitrary argument list (builder pattern).
dqcs_handle_type_t dqcs_handle_type(dqcs_handle_t handle)
Returns the type of object associated with the given handle.
SimulationConfiguration && with_dqcsim_verbosity(Loglevel level)
Configures the logging verbosity for DQCsim's own messages (builder pattern).
char * dqcs_pdef_author(dqcs_handle_t pdef)
Returns the plugin author for the given plugin definition object.
dqcs_cycle_t dqcs_plugin_get_cycles_since_measure(dqcs_plugin_state_t plugin, dqcs_qubit_t qubit)
Returns the number of downstream cycles since the latest measurement of the given downstream qubit.
ArbCmdQueue && with(ArbCmd &&cmd)
Pushes an ArbCmd into the queue by moving (builder pattern).
Measurement & with_arg_string(const std::string &data)
Pushes a (binary) string to the back of the arbitrary argument list (builder pattern).
std::string get_oper() const
Returns the operation identifier of this command.
PluginThreadConfiguration with_spawner(Args... args)
Builds a plugin thread configuration object using a single callback that spawns the entire plugin.
virtual std::string get_name() const =0
Returns the name given to the plugin.
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...
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.
size_t num_qubits() const
Returns the number of qubits associated with the matrix.
static Gate prep(const QubitSet &targets, const Matrix &basis)
Constructs a new prep gate for a custom initial state.
ssize_t dqcs_mat_num_qubits(dqcs_handle_t mat)
Returns the number of qubits targeted by the given matrix.
@ DQCS_GATE_T_DAG
The T-dagger matrix, also known as a negative 45 degree Z rotation.
@ I
The identity gate for a single qubit.
Wrapper for DQCsim's internal plugin state within the context of downstream-synchronous plugin callba...
dqcs_handle_t dqcs_mset_take(dqcs_handle_t mset, dqcs_qubit_t qubit)
Returns the measurement result for the given qubit from a measurement result set and removes it from ...
@ DQCS_BASIS_INVALID
Invalid basis. Used as an error return value.
void operator=(const QubitSet &src)
Copy assignment operator for qubit sets.
PathStyle get_reproduction_style() const
Returns the path style used when writing reproduction files.
bool has_measures() const
Returns whether this gate has measurement qubits.
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.
Callback< void, std::string && > SpawnPlugin
Callback wrapper specialized for the manual plugin spawning callback.
Gate & with_arg(const T &data)
Pushes a value of type T to the back of the arbitrary argument list (builder pattern).
dqcs_path_style_t
Reproduction file path style.
std::complex< double > complex
Typedef for the complex numbers used within the gate matrices.
@ DQCS_GATE_RZ_90
Rz(90°) gate.
PluginProcessConfiguration && without_env_var(const std::string &key)
Removes/unsets an environment variable for the plugin process (builder pattern).
@ DQCS_GATE_RY_M90
Ry(-90°) gate.
dqcs_handle_t dqcs_scfg_new(void)
Constructs an empty simulation configuration.
@ DQCS_GATE_PHASE_K
The matrix for a Z rotation with angle π/2^k.
static Gate measure(const QubitSet &measures, const Matrix &basis)
Constructs a new measurement gate, measuring in the given custom basis.
dqcs_return_t dqcs_gm_add_measure(dqcs_handle_t gm, void(*key_free)(void *user_data), void *key_data, intptr_t num_measures, dqcs_handle_t basis, double epsilon)
Adds a measurement gate mapping to the given gate map.
dqcs_plugin_type_t
Enumeration of the three types of plugins.
PluginProcessConfiguration && without_shutdown_timeout()
Disables the timeout for the plugin process to shut down gracefully (builder pattern).
bool has_targets() const
Returns whether this gate has target qubits.
ssize_t dqcs_arb_pop_raw(dqcs_handle_t arb, void *obj, size_t obj_size)
Pops an unstructured raw argument from the back of the list.
dqcs_handle_t dqcs_pcfg_new_raw(dqcs_plugin_type_t typ, const char *name, const char *executable, const char *script)
Creates a new plugin process configuration object using raw paths.
dqcs_handle_t dqcs_plugin_get_measurement(dqcs_plugin_state_t plugin, dqcs_qubit_t qubit)
Returns the latest measurement of the given downstream qubit.
Arb(HandleIndex handle) noexcept
Wraps the given arb handle.
JSON get_arb_json() const
Returns the current arbitrary JSON data as a JSON object from nlohmann::json.
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.
dqcs_handle_t dqcs_mset_get(dqcs_handle_t mset, dqcs_qubit_t qubit)
Returns a copy of the measurement result for the given qubit from a measurement result set.
char * dqcs_sim_get_name_idx(dqcs_handle_t sim, ssize_t index)
Queries the implementation name of a plugin, referenced by index.
std::string get_name(const std::string &name)
Queries the class name of a plugin, referenced by instance name.
void send(ArbData &&data)
Sends the given ArbData message to the simulated accelerator (passed by move).
@ DQCS_BASIS_INVALID
Invalid basis.
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.
Handle(HandleIndex handle) noexcept
Wraps the given raw handle.
Wrapper for DQCsim's internal plugin state within the context of the run callback in a frontend.
MeasurementSet && with(const Measurement &measurement)
Copies the given measurement object into the set (builder pattern).
void dqcs_error_set(const char *msg)
Sets the latest error message string.
Plugin && with_initialize(const callback::Initialize &cb)
Assigns the initialize callback function from a pre-existing callback::Initialize object by copy.
void set_shutdown_timeout(double timeout)
Configures the timeout for the plugin process to shut down gracefully.
ArbData run(ArbData &&data)
Runs a program on the simulated accelerator using the given ArbData object as an argument (passed by ...
Plugin && with_modify_measurement(Args... args)
Assigns the modify-measurement callback function by constructing the callback object implicitly.
static Gate measure(QubitSet &&measures, Matrix &&basis)
Constructs a new measurement gate, measuring in the given custom basis.
#define DQCSIM_FATAL(fmt,...)
Convenience macro for calling log() with fatal loglevel and automatically determined filename and lin...
char * dqcs_pcfg_work_get(dqcs_handle_t pcfg)
Returns the configured working directory for the given plugin process.
Plugin && with_advance(callback::Advance &&cb)
Assigns the advance callback function from a pre-existing callback::Advance object by move.
void write_reproduction_file(const std::string &filename)
Writes a reproduction file for the simulation so far.
Loglevel get_dqcsim_verbosity() const
Returns the configured verbosity for DQCsim's own messages.
@ DQCS_GATE_PAULI_Y
The Pauli Y matrix.
PluginConfigurationBuilder Backend(const std::string &name="") noexcept
Shorthand for constructing a backend plugin configuration builder.
std::string get_author(const std::string &name)
Queries the author of a plugin, referenced by instance name.
void set_seed(uint64_t seed)
Configures the random seed that the simulation should use.
static Gate measure(QubitSet &&measures)
Constructs a new Z-axis measurement gate.
HandleType type() const
Returns the type of this handle.
Represents any kind of gate with qubits bound to it.
QubitSet get_targets() const
Returns a new qubit reference set with the target qubits for this gate.
std::string get_name(ssize_t index)
Queries the class name of a plugin, referenced by index.
dqcs_handle_t dqcs_plugin_random_u64(dqcs_plugin_state_t plugin)
Generates a random unsigned 64-bit number using the simulator random seed.
dqcs_handle_t dqcs_sim_arb_idx(dqcs_handle_t sim, ssize_t index, dqcs_handle_t cmd)
Sends an ArbCmd message to one of the plugins, referenced by index.
char * dqcs_sim_get_name(dqcs_handle_t sim, const char *name)
Queries the implementation name of a plugin, referenced by instance name.
virtual bool detect(Matrix &&matrix, ssize_t num_controls, ArbData ¶ms) const
The to-be-implemented detector function.
Callback(std::function< R(Args...)> &&cb) noexcept
Constructs the callback wrapper by moving a std::function.
double dqcs_plugin_random_f64(dqcs_plugin_state_t plugin)
Generates a random floating point number using the simulator random seed.
Measurement get(const QubitRef &qubit) const
Returns a copy of the measurement object for the given qubit.
@ DQCS_GATE_SWAP
The swap gate matrix.
ArbData wait()
Waits for the simulated accelerator to finish its current program.
QubitRef(QubitRef &&)=default
Default move constructor.
@ DQCS_HTYPE_SIM_CONFIG
Indicates that the given handle belongs to a simulator configuration object.
dqcs_handle_t dqcs_tcfg_new_raw(dqcs_plugin_type_t plugin_type, const char *name, void(*callback)(void *user_data, const char *simulator), void(*user_free)(void *user_data), void *user_data)
Creates a new plugin thread configuration object from a callback.
Callback< void, PluginState &, Cycle > Advance
Callback wrapper specialized for the advance callback.
bool operator==(const QubitRef &other) const noexcept
Qubit reference equality operator.
bool approx_unitary(double epsilon=0.000001) const
Approximate unitary check.
dqcs_handle_t dqcs_mset_new(void)
Creates a new set of qubit measurement results.
@ Operator
Operator plugin.
void insert_arb_arg_string(ssize_t index, const std::string &data)
Inserts an arbitrary argument at the given index using a (binary) string.
Represents a square matrix used for describing N-qubit gates.
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.
void send()
Sends an empty message to the simulated accelerator.
Callback(const std::function< R(Args...)> &cb) noexcept
Constructs the callback wrapper by copying a std::function.
dqcs_return_t dqcs_scfg_repro_disable(dqcs_handle_t scfg)
Disables the reproduction logging system.
ArbCmdQueue(HandleIndex handle) noexcept
Wraps the given ArbCmdQueue handle.
PathStyle
Represents the possible options for dealing with paths when writing a reproduction file.
dqcs_handle_t dqcs_plugin_start(dqcs_handle_t pdef, const char *simulator)
Executes a plugin in a worker thread.
@ DQCS_MEAS_INVALID
Error value used to indicate that something went wrong.
Handle & operator=(Handle &&src)
Move constructor; simply moves ownership of the handle from the source object to the assignment targe...
PluginType get_plugin_type() const override
Returns the plugin type.
void free()
Explicitly delete the handle, allowing errors to be caught.
GateMap && with_measure(const Unbound &key, PauliBasis basis=PauliBasis::Z, double epsilon=0.000001, int num_measures=-1)
Adds a measurement gate mapping.
HandleIndex take_handle() noexcept
Returns the raw handle and relinquishes ownership.
PluginType get_type() const
Returns the plugin type described by this object.
PluginProcessConfiguration & operator=(PluginProcessConfiguration &&)=default
Default move assignment.
Plugin && with_free(Args... args)
Assigns the free callback function by constructing the callback object implicitly.
@ DQCS_LOG_WARN
This loglevel is to be used for reporting that a called API/function is telling us we did something w...
Callback< void, PluginState &, QubitSet && > Free
Callback wrapper specialized for the allocate callback.
dqcs_return_t dqcs_cq_push(dqcs_handle_t cq, dqcs_handle_t cmd)
Pushes an ArbCmd object into the given ArbCmd queue.
dqcs_return_t dqcs_scfg_dqcsim_verbosity_set(dqcs_handle_t scfg, dqcs_loglevel_t level)
Configures the logging verbosity for DQCsim's own messages.
Measurement & with_json_string(const std::string &json)
Sets the arbitrary JSON data to the given serialized JSON string (builder pattern).
void set_arb_arg_string(ssize_t index, const std::string &data)
Sets the arbitrary argument at the given index to a (binary) string.
HandleType
Represents the type of a raw handle.
ArbCmd(const std::string &iface, const std::string &oper)
Constructs an ArbCmd object.
@ DQCS_PTYPE_INVALID
Invalid plugin type.
dqcs_return_t dqcs_tcfg_tee(dqcs_handle_t tcfg, dqcs_loglevel_t verbosity, const char *filename)
Configures a plugin thread to also output its log messages to a file.
GateMap && with_prep(Unbound &&key, Matrix &&basis, double epsilon=0.000001, int num_targets=-1)
Adds a prep gate mapping.
char * dqcs_pcfg_name(dqcs_handle_t pcfg)
Returns the configured name for the given plugin process.
ArbData(const ArbData &src)
Copy-constructs an ArbData object from another ArbData object.
@ DQCS_GATE_INVALID
Invalid gate.
PluginType get_plugin_type() const override
Returns the plugin type.
void add_init_cmd(const ArbCmd &cmd)
Attaches an arbitrary initialization command to the plugin.
dqcs_return_t dqcs_gm_add_prep(dqcs_handle_t gm, void(*key_free)(void *user_data), void *key_data, intptr_t num_targets, dqcs_handle_t basis, double epsilon)
Adds a prep gate mapping to the given gate map.
char * dqcs_arb_json_get(dqcs_handle_t arb)
Returns the JSON/CBOR object of an ArbData object in the form of a JSON string.
Measurement(const Measurement &src)
Copy-constructs a Measurement object.
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).
Simulation(HandleIndex handle) noexcept
Wraps the given simulation handle.
@ DQCS_LOG_INVALID
Invalid loglevel.
@ DQCS_GATE_H
The hadamard gate matrix.
@ DQCS_GATE_RY_90
Ry(90°) gate.
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.
size_t size() const
Returns the number of ArbCmds in the queue.
void gate(const Matrix &matrix, const QubitRef &q)
Shorthand for sending a single-qubit gate to the downstream plugin.
@ DQCS_BASIS_Y
The Y basis.
@ DQCS_GATE_RZ_180
Rz(180°) gate.
dqcs_handle_t dqcs_gm_construct(dqcs_handle_t gm, const void *key_data, dqcs_handle_t qubits, dqcs_handle_t param_data)
Uses a gate map object to construct a multi-qubit DQCsim gate from the plugin's representation.
dqcs_bool_return_t dqcs_qbset_contains(dqcs_handle_t qbset, dqcs_qubit_t qubit)
Returns whether the given qubit set contains the given qubit.
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.
ArbData recv()
Waits for the simulated accelerator to send a message to us.
dqcs_path_style_t dqcs_scfg_repro_path_style_get(dqcs_handle_t scfg)
Returns the path style used when writing reproduction files.
std::string get_version() const
Returns the version of the described plugin.
QubitSet get_controls() const
Returns a new qubit reference set with the control qubits for this gate.
dqcs_return_t dqcs_gm_add_fixed_unitary(dqcs_handle_t gm, void(*key_free)(void *key_data), void *key_data, dqcs_handle_t matrix, intptr_t num_controls, double epsilon, bool ignore_gphase)
Adds a unitary gate mapping for the given gate matrix to the given gate map.
char * dqcs_sim_get_version_idx(dqcs_handle_t sim, ssize_t index)
Queries the version of a plugin, referenced by index.
PluginThreadConfiguration & operator=(PluginThreadConfiguration &&)=default
Default move assignment.
double * dqcs_mat_get(dqcs_handle_t mat)
Returns a copy of the contained matrix as a C array.
Plugin && with_upstream_arb(const callback::Arb &cb)
Assigns the upstream-arb callback function from a pre-existing callback::Arb object by copy.
dqcs_return_t dqcs_plugin_wait(dqcs_handle_t pjoin)
Waits for a plugin worker thread to finish executing.
Plugin && with_free(callback::Free &&cb)
Assigns the free callback function from a pre-existing callback::Free object by move.
SimulationConfiguration && with_seed(uint64_t seed)
Configures the random seed that the simulation should use (builder pattern).
double get_accept_timeout() const
Returns the configured timeout for the plugin process to connect to DQCsim.
PluginState(raw::dqcs_plugin_state_t state)
Hidden constructor, only to be used by the callback wrappers.
Class representation of the measurement result for a single qubit.
PluginThreadConfiguration(HandleIndex handle) noexcept
Wraps the given plugin thread configuration handle.
Handle(Handle &&src)
Move constructor; simply moves ownership of the handle from the source object to the constructed obje...
dqcs_return_t dqcs_handle_delete(dqcs_handle_t handle)
Destroys the object associated with a handle.
static Gate unitary(QubitSet &&targets, const Matrix &matrix)
Constructs a new custom unitary gate.
dqcs_handle_t dqcs_gate_new_measurement(dqcs_handle_t measures, dqcs_handle_t matrix)
Constructs a new measurement gate.
Simulation & operator=(Simulation &&)=default
Default move assignment.
Matrix(PredefinedGate gate, ArbData &¶meters)
Constructs a predefined matrix, using ArbData to represent the parameters for parameterized gates.
Plugin && with_modify_measurement(const callback::ModifyMeasurement &cb)
Assigns the modify-measurement callback function from a pre-existing callback::ModifyMeasurement obje...
ArbCmd & with_cbor_string(const std::string &cbor)
Sets the arbitrary JSON data to the given serialized CBOR string (builder pattern).
Class template shared between all callback functions.
void add_init_cmd(ArbCmd &&cmd) override
Attaches an arbitrary initialization command to the plugin.
dqcs_return_t dqcs_pcfg_verbosity_set(dqcs_handle_t pcfg, dqcs_loglevel_t level)
Configures the logging verbosity for the given plugin process.
dqcs_handle_t dqcs_cmd_new(const char *iface, const char *oper)
Creates a new ArbCmd object.
void next()
Pops the first ArbCmd from the queue, allowing the next one to be accessed.
static QubitSet from_iter(const T &qubits)
Constructs a qubit set object from an iterable of qubit references.
@ DQCS_MEAS_ZERO
Indicates that the qubit was measured to be zero.
virtual void set_verbosity(Loglevel level)=0
Sets the logging verbosity level of the plugin.
Matrix get_matrix() const
Returns the matrix that belongs to this gate.
void set_reproduction_style(PathStyle style)
Sets the path style used when writing reproduction files.
Class wrapper for ArbData handles.
@ DQCS_GATE_R
Arbitrary rotation matrix.
@ DQCS_GATE_PAULI_X
The Pauli X matrix.
dqcs_bool_return_t dqcs_gate_has_targets(dqcs_handle_t gate)
Returns whether the specified gate has target qubits.
@ DQCS_GATE_TYPE_UNITARY
Unitary gates have one or more target qubits, zero or more control qubits, and a unitary matrix,...
@ DQCS_HTYPE_BACK_PROCESS_CONFIG
Indicates that the given handle belongs to a backend plugin process configuration object.
void log_tee(Loglevel verbosity, const std::string &filename)
Configures DQCsim to also output its log messages to a file.
@ DQCS_GATE_PHASE
The matrix for an arbitrary Z rotation.
void operator=(const ArbData &src)
Copy assignment operator for ArbData objects.
char * dqcs_handle_dump(dqcs_handle_t handle)
Returns a debug dump of the object associated with the given handle.
Measurement take_any()
Moves any measurement object out of the set.
void push_arb_arg(const T &data)
Pushes a value of type T to the back of the arbitrary argument list.
@ Keep
Specifies that paths should be saved the same way they were specified on the command line.
static Gate prep(QubitSet &&targets, PauliBasis basis)
Constructs a new prep gate, putting the qubits in the base state for the given Pauli basis.
void free(const QubitRef &qubit)
Frees the given downstream qubit.
virtual PluginType get_plugin_type() const =0
Returns the plugin type.
void set_arb_json(const JSON &json)
Sets the arbitrary JSON data to the given JSON object from nlohmann::json.
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.
void yield()
Yields to the simulator.
double random_f64() noexcept
Generates a random floating point number using the simulator random seed.
GateMap && with_unitary(const Unbound &key, const std::shared_ptr< CustomUnitaryGateConverter > &converter)
Adds a custom unitary gate mapping.
dqcs_handle_t dqcs_mat_new(size_t num_qubits, const double *matrix)
Constructs a new gate matrix.
@ DQCS_MEAS_ONE
Indicates that the qubit was measured to be one.
@ DQCS_PATH_STYLE_INVALID
Error value used to indicate that something went wrong.
Callback(R(*cb)(Args...)) noexcept
Constructs the callback wrapper from a regular C-style function.
@ DQCS_HTYPE_ARB_DATA
Indicates that the given handle belongs to an ArbData object.
void * dqcs_plugin_state_t
Type for a plugin state.
GateMap && with_prep(Unbound &&key, PauliBasis basis=PauliBasis::Z, double epsilon=0.000001, int num_targets=-1)
Adds a prep gate mapping.
raw::dqcs_handle_t HandleIndex
C++-styled type name for raw::dqcs_handle_t.
Matrix(const Matrix &src)
Copy-constructs a matrix.
Plugin && with_run(const callback::Run &cb)
Assigns the run callback function from a pre-existing callback::Run object by copy.
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.
void insert_arb_arg(ssize_t index, const T &data)
Inserts an arbitrary argument at the given index using a value of type T.
void gate(const Matrix &matrix, const QubitRef &qa, const QubitRef &qb)
Shorthand for sending a two-qubit gate to the downstream plugin.
Callback< void, PluginState &, QubitSet &&, ArbCmdQueue && > Allocate
Callback wrapper specialized for the allocate callback.
dqcs_loglevel_t dqcs_pcfg_verbosity_get(dqcs_handle_t pcfg)
Returns the configured verbosity for the given plugin process.
std::string get_executable() const
Returns the configured executable path for the plugin.
std::string get_arb_arg_string(ssize_t index) const
Returns the arbitrary argument at the given index as a (binary) string.
Plugin(Plugin &&)=default
Default move constructor.
PluginProcessConfiguration && with_accept_timeout(double timeout)
Configures the timeout for the plugin process to connect to DQCsim (builder pattern).
ArbData()
Constructs an empty ArbData object.
PluginProcessConfiguration && with_work_dir(const std::string &dir)
Overrides the working directory for the plugin process (builder pattern).
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.
QubitRef get_qubit() const
Returns the qubit reference associated with this measurement.
dqcs_return_t dqcs_scfg_seed_set(dqcs_handle_t scfg, uint64_t seed)
Configures the random seed that the simulation should use.
static Gate predefined(PredefinedGate gate, QubitSet &&qubits)
Constructs a new non-parameterized predefined gate.
ArbCmdQueue & operator=(ArbCmdQueue &&)=default
Default move assignment.
dqcs_loglevel_t dqcs_tcfg_verbosity_get(dqcs_handle_t tcfg)
Returns the configured verbosity for the given plugin thread.
ssize_t dqcs_mset_len(dqcs_handle_t mset)
Returns the number of qubits measurements in the given measurement set.
bool operator!=(const QubitRef &other) const noexcept
Qubit reference inequality operator.
dqcs_return_t dqcs_mset_remove(dqcs_handle_t mset, dqcs_qubit_t qubit)
Removes the measurement result for the given qubit from a measurement result set.
dqcs_handle_t dqcs_gate_new_unitary(dqcs_handle_t targets, dqcs_handle_t controls, dqcs_handle_t matrix)
Constructs a new unitary gate.
Gate construct(const Unbound &unbound, QubitSet &&qubits)
Uses a gate map object to construct a DQCsim gate from the plugin's representation.
void send(const ArbData &message)
Sends a message to the host.
PluginThreadConfiguration && with_init_cmd(ArbCmd &&cmd)
Attaches an arbitrary initialization command to the plugin (builder pattern).
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.
std::string get_name() const
Returns the name of a custom gate.
static Gate custom(const std::string &name, QubitSet &&targets, const Matrix &matrix)
Constructs a new custom gate with target qubits and a matrix.
int run(int argc, char *argv[]) noexcept
Runs the defined plugin in the current thread with the given command line.
static Gate measure(QubitSet &&measures, PauliBasis basis)
Constructs a new measurement gate, measuring in the given Pauli basis.
SimulationConfiguration && with_log_callback(Loglevel verbosity, Args... args)
Configures DQCsim to also output its log messages to callback function (builder pattern).
void set_verbosity(Loglevel level) override
Sets the logging verbosity level of the plugin.
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.
void set_stderr_loglevel(Loglevel level)
Configures the capture mode for the stderr stream of the specified plugin process.
static ArbCmdQueue from_iter(const T &cmds)
Constructs an ArbCmd queue object from an iterable of ArbCmds by copying.
std::string get_name() const
Returns the name of the described plugin.
Wrapper class for a running simulation.
@ DQCS_GATE_SQRT_SWAP
The square-root of a swap gate matrix.
ArbData recv()
Receives a message from the host.
dqcs_plugin_type_t dqcs_pdef_type(dqcs_handle_t pdef)
Returns the plugin type for the given plugin definition object.
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.
PluginProcessConfiguration && with_verbosity(Loglevel level)
Sets the logging verbosity level of the plugin (builder pattern).
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.
static Gate predefined(PredefinedGate gate, QubitSet &&qubits, ArbData &¶meters)
Constructs a new predefined gate.
@ DQCS_HTYPE_BACK_THREAD_CONFIG
Indicates that the given handle belongs to a backend plugin thread configuration object.
@ DQCS_GATE_RZ
The matrix for an arbitrary Z rotation.
QubitSet get_measures() const
Returns a new qubit reference set with the measurement qubits for this gate.
Plugin && with_drop(const callback::Drop &cb)
Assigns the drop callback function from a pre-existing callback::Drop object by copy.
PluginProcessConfiguration && with_stdout_loglevel(Loglevel level)
Configures the capture mode for the stdout stream of the specified plugin process (builder pattern).
dqcs_bool_return_t dqcs_gate_has_name(dqcs_handle_t gate)
Returns whether the specified gate has a name.
static Gate unitary(const QubitSet &targets, const Matrix &matrix)
Constructs a new custom unitary gate.
char * dqcs_cmd_oper_get(dqcs_handle_t cmd)
Returns the operation ID of an ArbCmd.
double dqcs_pcfg_shutdown_timeout_get(dqcs_handle_t pcfg)
Returns the configured timeout for the plugin process to shut down gracefully.
void set_qubit(QubitRef qubit)
Sets the qubit reference associated with this measurement.
Measurement & with_cbor_string(const std::string &cbor)
Sets the arbitrary JSON data to the given serialized CBOR string (builder pattern).
virtual void add_init_cmd(ArbCmd &&cmd)=0
Attaches an arbitrary initialization command to the plugin.
void set_env_var(const std::string &key, const std::string &value)
Overrides an environment variable for the plugin process.
HandleIndex handle
The wrapped handle.
QubitRef pop()
Pops a qubit from the set.
Wrapper class for plugin process configurations.
std::string get_work_dir() const
Returns the configured working directory for the given plugin process.
Matrix add_controls(size_t number_of_controls) const
Constructs a controlled matrix from the given matrix.
Gate & operator=(Gate &&)=default
Default move assignment.
dqcs_return_t dqcs_pcfg_init_cmd(dqcs_handle_t pcfg, dqcs_handle_t cmd)
Appends an ArbCmd to the list of initialization commands of a plugin process.
dqcs_return_t dqcs_scfg_push_plugin(dqcs_handle_t scfg, dqcs_handle_t xcfg)
Appends a plugin to a simulation configuration.
Class that you can inherit from to make your own custom gate converter for use within DQCsim.
@ DQCS_LOG_INFO
This loglevel is to be used for reporting information NOT specifically requested by the user/API call...
bool is_iface(const std::string &iface) const
Returns whether this command has the given interface identifier.
@ DQCS_BOOL_FAILURE
The function has failed.
Callback< ArbData, PluginState &, ArbCmd > Arb
Callback wrapper specialized for the *_arb callbacks.
QubitRef allocate(ArbCmdQueue &&cmds)
Allocates a single downstream qubit, copying in the given command queue as arbitrary additional data ...
@ DQCS_FAILURE
The function has failed.
@ DQCS_HTYPE_BACK_DEF
Indicates that the given handle belongs to a backend plugin definition object.
void set(Measurement &&measurement)
Moves the given measurement object into the set.
ArbData arb(ssize_t index, const ArbCmd &cmd)
Sends an ArbCmd (passed by copy) to the given plugin (referenced by index).
dqcs_return_t dqcs_arb_json_set(dqcs_handle_t arb, const char *json)
Sets the JSON/CBOR object of an ArbData object by means of a JSON string.
@ DQCS_HTYPE_SIM
Indicates that the given handle belongs to a simulator instance.