libqasm
library for handling cQASM files
cqasm-v1-error-model.cpp
Go to the documentation of this file.
1 
5 #include "cqasm-utils.hpp"
7 #include "cqasm-v1-semantic.hpp"
8 
9 namespace cqasm {
10 namespace v1 {
11 namespace error_model {
12 
19  const std::string &name,
20  const std::string &param_types
21 ) :
22  name(name),
23  param_types(types::from_spec(param_types))
24 {}
25 
29 bool ErrorModel::operator==(const ErrorModel &rhs) const {
31 }
32 
36 std::ostream &operator<<(std::ostream &os, const ErrorModel &model) {
37  os << model.name << model.param_types;
38  return os;
39 }
40 
44 std::ostream &operator<<(std::ostream &os, const ErrorModelRef &model) {
45  if (model.empty()) {
46  os << "unresolved";
47  } else {
48  os << *model;
49  }
50  return os;
51 }
52 
53 } // namespace error_model
54 
55 namespace primitives {
56 
57 template <>
58 void serialize(const error_model::ErrorModelRef &obj, ::tree::cbor::MapWriter &map) {
59  if (obj.empty()) {
60  return;
61  }
62  map.append_string("n", obj->name);
63  auto aw = map.append_array("t");
64  for (const auto &t : obj->param_types) {
65  aw.append_binary(::tree::base::serialize(t));
66  }
67  aw.close();
68 }
69 
70 template <>
71 error_model::ErrorModelRef deserialize(const ::tree::cbor::MapReader &map) {
72  if (!map.count("n")) {
73  return {};
74  }
75  auto model = tree::make<error_model::ErrorModel>(map.at("n").as_string(), "");
76  auto ar = map.at("t").as_array();
77  for (size_t i = 0; i < ar.size(); i++) {
78  model->param_types.add(::tree::base::deserialize<types::Node>(ar.at(i).as_binary()));
79  }
80  return std::move(model);
81 }
82 
83 } // namespace primitives
84 } // namespace v1
85 } // namespace cqasm
tree::Maybe< ErrorModel > ErrorModelRef
Optional reference to an error model, used within the semantic tree.
std::string name
The name of the error model.
types::Types param_types
The vector of parameter types that this error model expects.
This file contains the ErrorModel class and support types, each instance representing an error model ...
error_model::ErrorModelRef deserialize(const ::tree::cbor::MapReader &map)
Deserializes the given primitive object from CBOR.
Types from_spec(const std::string &spec)
Constructs a set of types from a shorthand string representation.
Toplevel namespace with entry points for the new API.
Defines various utility functions.
Defines the types for the cQASM semantic tree, based on the classes from cqasm::tree.
void serialize(const error_model::ErrorModelRef &obj, ::tree::cbor::MapWriter &map)
Representation of an error model.
Namespace for the "new" cQASM 1.x API.
bool case_insensitive_equals(const std::string &lhs, const std::string &rhs)
Case-insensitive string compare.
Definition: cqasm-utils.cpp:26
std::ostream & operator<<(std::ostream &os, const ErrorModel &model)
Stream << overload for error models.
ErrorModel(const std::string &name, const std::string &param_types="")
Creates a new error model.
bool operator==(const ErrorModel &rhs) const
Equality operator.