11 namespace instruction {
27 const std::string &name,
28 const std::string ¶m_types,
29 bool allow_conditional,
31 bool allow_reused_qubits,
32 bool allow_different_index_sizes
35 param_types(types::
from_spec(param_types)),
36 allow_conditional(allow_conditional),
37 allow_parallel(allow_parallel),
38 allow_reused_qubits(allow_reused_qubits),
39 allow_different_index_sizes(allow_different_index_sizes)
75 namespace primitives {
82 map.append_string(
"n", obj->name);
83 map.append_bool(
"c", obj->allow_conditional);
84 map.append_bool(
"p", obj->allow_parallel);
85 map.append_bool(
"r", obj->allow_reused_qubits);
86 map.append_bool(
"d", obj->allow_different_index_sizes);
87 auto aw = map.append_array(
"t");
88 for (
const auto &t : obj->param_types) {
96 if (!map.count(
"n")) {
99 auto insn = tree::make<instruction::Instruction>(
100 map.at(
"n").as_string(),
102 map.at(
"c").as_bool(),
103 map.at(
"p").as_bool(),
104 map.at(
"r").as_bool(),
105 map.at(
"d").as_bool()
107 auto ar = map.at(
"t").as_array();
108 for (
size_t i = 0; i < ar.size(); i++) {
109 insn->param_types.add(::tree::base::deserialize<types::Node>(ar.at(i).as_binary()));
111 return std::move(insn);
void serialize(const instruction::InstructionRef &obj, ::tree::cbor::MapWriter &map)
tree::Maybe< Instruction > InstructionRef
Optional reference to an instruction, used within the semantic tree.
This file contains the Instruction class and support types, each instance representing an instruction...
std::ostream & operator<<(std::ostream &os, const Instruction &insn)
Stream << overload for instructions.
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.
bool allow_reused_qubits
Whether to allow usage of the same qubit in different arguments.
bool allow_conditional
Whether this instruction supports conditional execution by means of the c- notation.
Defines various utility functions.
instruction::InstructionRef deserialize(const ::tree::cbor::MapReader &map)
Deserializes the given primitive object from CBOR.
bool allow_parallel
Whether this instruction can be used in a bundle.
Defines the types for the cQASM semantic tree, based on the classes from cqasm::tree.
Representation of an available instruction (also known as gate) in the instruction set...
bool operator==(const Instruction &rhs) const
Equality operator.
types::Types param_types
The vector of parameter types that this instruction expects.
Namespace for the "new" cQASM 1.x API.
bool case_insensitive_equals(const std::string &lhs, const std::string &rhs)
Case-insensitive string compare.
Instruction(const std::string &name, const std::string ¶m_types="", bool allow_conditional=true, bool allow_parallel=true, bool allow_reused_qubits=false, bool allow_different_index_sizes=false)
Creates a new instruction.
std::string name
The name of the instruction.