16 map.append_binary(
"x", obj);
21 return map.at(
"x").as_binary();
29 map.append_bool(
"x", obj);
34 return map.at(
"x").as_bool();
43 case Axis::X: map.append_int(
"x", 0);
break;
44 case Axis::Y: map.append_int(
"x", 1);
break;
45 case Axis::Z: map.append_int(
"x", 2);
break;
51 switch (map.at(
"x").as_int()) {
56 throw std::runtime_error(
"invalid value for axis enum during deserialization");
64 map.append_int(
"x", obj);
69 return map.at(
"x").as_int();
77 map.append_float(
"x", obj);
82 return map.at(
"x").as_float();
87 map.append_float(
"r", obj.real());
88 map.append_float(
"i", obj.imag());
93 return {map.at(
"r").as_float(), map.at(
"i").as_float()};
99 auto aw = map.append_array(
"d");
100 for (
const auto &value : obj.
get_data()) {
101 aw.append_float(value);
108 size_t num_cols = map.at(
"c").as_int();
109 auto ar = map.at(
"d").as_array();
110 std::vector<Real> data;
111 data.reserve(ar.size());
112 for (
size_t i = 0; i < ar.size(); i++) {
113 data[i] = ar.at(i).as_float();
115 return {data, num_cols};
121 auto aw = map.append_array(
"d");
122 for (
const auto &value : obj.
get_data()) {
123 aw.append_float(value.real());
124 aw.append_float(value.imag());
131 size_t num_cols = map.at(
"c").as_int();
132 auto ar = map.at(
"d").as_array();
133 std::vector<Complex> data;
134 data.reserve(ar.size() / 2);
135 for (
size_t i = 0; i < ar.size() / 2; i++) {
136 data[i] = {ar.at(i*2).as_float(), ar.at(i*2+1).as_float()};
138 return {data, num_cols};
143 auto aw = map.append_array(
"x");
152 auto ar = map.at(
"x").as_array();
154 v.reserve(ar.size());
155 for (
size_t i = 0; i < ar.size(); i++) {
156 v.push_back(ar.at(i).as_int());
Two-dimensional matrix of some kind of type.
std::complex< double > Complex
Complex number primitive used within the semantic trees.
error_model::ErrorModelRef deserialize(const ::tree::cbor::MapReader &map)
Deserializes the given primitive object from CBOR.
Toplevel namespace with entry points for the new API.
double Real
Real number primitive used within the AST and semantic trees.
std::int64_t Int
Integer primitive used within the AST and semantic trees.
Version number primitive used within the AST and semantic trees.
void serialize(const error_model::ErrorModelRef &obj, ::tree::cbor::MapWriter &map)
Bool initialize< Bool >()
bool Bool
Boolean primitive used within the semantic trees.
Defines primitive types for use in trees generated by tree-gen.
Namespace for the "new" cQASM 1.x API.
Real initialize< Real >()
Axis initialize< Axis >()
std::string Str
String primitive used within the AST and semantic trees.
version::Version Version
Version number primitive used within the AST and semantic trees.
std::ostream & operator<<(std::ostream &os, const Axis &axis)
Stream << overload for axis nodes.
size_t size_cols() const
Returns the number of columns.
const std::vector< T > & get_data() const
Returns access to the raw data vector.
Axis
Axis primitive used within the semantic trees.