QuISP
Loading...
Searching...
No Matches
types.h
Go to the documentation of this file.
1
7#pragma once
8
9#include <omnetpp/simtime.h>
10#include <cstddef>
11#include <string>
12
14#include <modules/QRSA/QRSA.h>
15
16namespace quisp::runtime {
17
18using RuleId = int;
19
25using SequenceNumber = unsigned long;
26
32using MessageRecord = std::vector<int32_t>;
33
34// these types are mainly used for describing type name in def_instruction.h
35using String = std::string;
36
38
41
43using Time = omnetpp::SimTime;
45using PurType = int;
46
48enum class RegId : int { REG0, REG1, REG2, REG3, REG4 };
49std::ostream& operator<<(std::ostream& stream, const RegId& value);
50
55enum class ReturnCode : int {
57 NONE,
65 ERROR,
66};
67std::ostream& operator<<(std::ostream& stream, const ReturnCode& value);
68
70struct QNodeAddr {
71 QNodeAddr() : val(-1){};
72 QNodeAddr(int val);
73 int val;
74};
75std::ostream& operator<<(std::ostream& stream, const QNodeAddr& value);
76bool operator<(const QNodeAddr& a, const QNodeAddr& b);
77bool operator==(const QNodeAddr& a, const QNodeAddr& b);
78
83struct QubitId {
84 QubitId() : val(-1){};
85 QubitId(int val);
87 size_t operator()(const QubitId&) const;
88 int val;
89};
90std::ostream& operator<<(std::ostream& stream, const QubitId& value);
91bool operator<(const QubitId& a, const QubitId& b);
92bool operator==(const QubitId& a, const QubitId& b);
93
95struct Label {
96 Label(std::string val);
97 std::string val;
98};
99std::ostream& operator<<(std::ostream& stream, const Label& value);
100bool operator==(const Label& a, const Label& b);
101
103struct MemoryKey {
104 MemoryKey(std::string key);
105 std::string val;
106};
107std::ostream& operator<<(std::ostream& stream, const MemoryKey& key);
108bool operator==(const MemoryKey& a, const MemoryKey& b);
109
110using None = std::nullptr_t;
111
113using LabelMap = std::unordered_map<Label, int>;
114
116enum class Basis : int { Z, X, Y, RANDOM };
117std::ostream& operator<<(std::ostream& stream, const Basis& value);
118
119} // namespace quisp::runtime
120
121namespace std {
122// hash functions
123template <>
124struct ::std::hash<quisp::runtime::QNodeAddr> {
125 public:
126 size_t operator()(const quisp::runtime::QNodeAddr& addr) const { return std::hash<int>()(addr.val); }
127};
128
129template <>
130struct ::std::hash<quisp::runtime::QubitId> {
131 public:
132 size_t operator()(const quisp::runtime::QubitId& id) const { return std::hash<int>()(id.val); }
133};
134
135template <>
136struct ::std::hash<quisp::runtime::MemoryKey> {
137 public:
138 size_t operator()(const quisp::runtime::MemoryKey& key) const { return std::hash<std::string>()(key.val); }
139};
140
141template <>
142struct ::std::hash<quisp::runtime::Label> {
143 public:
144 size_t operator()(const quisp::runtime::Label& label) const { return std::hash<std::string>()(label.val); }
145};
146
147template <>
148struct ::std::hash<std::pair<quisp::runtime::QNodeAddr, quisp::runtime::RuleId>> {
149 public:
150 size_t operator()(const std::pair<quisp::runtime::QNodeAddr, quisp::runtime::RuleId>& p) const {
151 auto seed = std::hash<int>()(p.first.val);
152 // https://stackoverflow.com/questions/4948780/magic-number-in-boosthash-combine
153 seed ^= std::hash<int>()(p.second) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
154 return seed;
155 }
156};
157
158} // namespace std
The QubitRecord interface.
Definition IQubitRecord.h:17
quisp::modules::qubit_record::IQubitRecord IQubitRecord
Definition QRSA.h:8
Definition InstructionVisitor.cc:7
omnetpp::SimTime Time
alias for omnetpp's simulation time.
Definition types.h:43
bool operator<(const QNodeAddr &a, const QNodeAddr &b)
Definition types.cc:14
Basis
basis for measurement instruction in a Program.
Definition types.h:116
RegId
internal register id representation for Instructions.
Definition types.h:48
unsigned long SequenceNumber
describes the order which Qubit is assigned to a Stage/Rule. This allows us to make assumptions that ...
Definition types.h:25
bool operator==(const QNodeAddr &a, const QNodeAddr &b)
Definition types.cc:15
int RuleId
Definition types.h:18
std::ostream & operator<<(std::ostream &stream, const QNodeAddr &value)
Definition types.cc:10
int PurType
purification type for Instructions. see rules::PurType enum.
Definition types.h:45
std::string String
Definition types.h:35
std::vector< int32_t > MessageRecord
describes message received that takes part in decision making of RuleSet.
Definition types.h:32
ReturnCode
Program specify a ReturnCode during the execution. Then, the Runtime determines to perform the action...
Definition types.h:55
@ COND_PASSED
condition passed. will perform the action.
@ RS_TERMINATED
RuleSet terminated. will delete the RuleSet and the Runtime.
@ ERROR
unrecorverable error raised. stop the simulation.
@ COND_FAILED
condition failed. stop the rule execution.
std::unordered_map< Label, int > LabelMap
utility type for storing a label and corresponding instruction index.
Definition types.h:113
std::nullptr_t None
Definition types.h:110
Definition QNIC.h:49
label to annotate the instruction index in a Program.
Definition types.h:95
Label(std::string val)
Definition types.cc:26
std::string val
Definition types.h:97
a key of memory key-value store in a RuleSet
Definition types.h:103
std::string val
Definition types.h:105
MemoryKey(std::string key)
Definition types.cc:33
internal class to describe QNode's address.
Definition types.h:70
QNodeAddr()
Definition types.h:71
int val
Definition types.h:73
describes Qubit id in a Program. This is like a local variable name in a runtime::Program....
Definition types.h:83
QubitId()
Definition types.h:84
int val
Definition types.h:88
size_t operator()(const QubitId &) const
hash function for unordered map
Definition types.cc:18