8#include <unordered_map>
42using Memory = std::unordered_map<MemoryKey, MemoryValue>;
86 const int measurement_result,
PurType protocol) = 0;
88 const int sequence_number,
const int frame_correction) = 0;
The QubitRecord interface.
Definition IQubitRecord.h:17
memory value
Definition Value.h:21
The Program is a list of Instructions with metadata. The Runtime can execute the Program.
Definition RuleSet.h:17
The Runtime executable Rule in a RuleSet.
Definition RuleSet.h:40
The RuleSet.
Definition RuleSet.h:80
Runtime class is responsible for executing the given RuleSet and the states' management.
Definition Runtime.h:48
LabelMap const * label_map
The label_map is a map of the instruction index and its label to allow to jump or branch.
Definition Runtime.h:439
MessageResources messages
currently evaluating rule id
Definition Runtime.h:386
QubitNameMap named_qubits
This contains a map for a QubitId and a qubit.
Definition Runtime.h:406
bool qubit_found
The GET_QUBIT instruction sets this flag. if it's true, the GET_QUBIT instruction successfully found ...
Definition Runtime.h:471
void purifyY(RegId result, int bitset_index, QubitId qubit_id, QubitId trash_qubit_id)
perform Y purification and store the measurement result
Definition Runtime.cc:393
RuleSet ruleset
The assigned RuleSet for this Runtime instance.
Definition Runtime.h:423
InstructionVisitor visitor
The visitor handles all instruction types for Program execution.
Definition Runtime.h:346
unsigned int pc
program counter for Program execution.
Definition Runtime.h:368
void promoteQubit(IQubitRecord *qubit_record)
promote the qubit to the next rule.
Definition Runtime.cc:157
Memory memory
The memory contains a variety of values during the RuleSet execution.
Definition Runtime.h:415
ReturnCode return_code
The return_code describes the program's exit status.
Definition Runtime.h:451
bool message_found
The GET_MESSAGE instruction sets this flag. if it's true, the GET_MESSAGE instruction successfully fo...
Definition Runtime.h:478
void gateZ(QubitId)
apply Z gate
Definition Runtime.cc:347
void cleanup()
this method resets the state before each Program execution.
Definition Runtime.cc:108
IQubitRecord * getQubitByQubitId(QubitId qubit_id) const
Get the Qubit By QubitId.
Definition Runtime.cc:224
void exec()
public method to execute the assigned RuleSet.
Definition Runtime.cc:49
QubitResourcesWithSequenceNumbers sequence_number_to_qubit
currently evaluating rule id
Definition Runtime.h:388
int receive_tag
currently evaluating rule id
Definition Runtime.h:359
SequenceNumberCounter resource_counter
This stores the latest sequence no. of resource assigned to the Stage/Rule.
Definition Runtime.h:393
int32_t getRegVal(RegId reg_id) const
Get the Register's value.
Definition Runtime.cc:199
void assignQubitToRule(QNodeAddr partner_addr, RuleId rule_id, IQubitRecord *qubit_record)
assign the entangled qubit to the rule
Definition Runtime.cc:191
void purifyX(RegId result, int bitset_index, QubitId qubit_id, QubitId trash_qubit_id)
perform X purification and store the measurement result
Definition Runtime.cc:371
void gateCNOT(QubitId control_qubit_id, QubitId target_qubit_id)
apply CNOT gate
Definition Runtime.cc:363
void assignMessageToRuleSet(int shared_rule_tag, MessageRecord &msg_content)
assign the message to the rule
Definition Runtime.cc:128
IQubitRecord * getQubitBySequenceNumber(QNodeAddr, RuleId, SequenceNumber)
Get the qubit record by sequence number.
Definition Runtime.cc:217
void execProgram(const Program &program)
execute the given Program in a Rule
Definition Runtime.cc:81
bool should_exit
if this flag is true, the Runtime stops the Program execution.
Definition Runtime.h:456
void measureQubit(QubitId qubit_id, MemoryKey result_key, Basis basis)
measure qubit with the given basis and store the result to the memory.
Definition Runtime.cc:254
~Runtime()
Definition Runtime.cc:47
void assignRuleSet(const RuleSet &ruleset)
Definition Runtime.cc:122
void gateX(QubitId)
apply X gate
Definition Runtime.cc:339
SequenceNumberTracker qubit_to_sequence_number
currently evaluating rule id
Definition Runtime.h:389
std::unordered_map< RuleId, int > rule_id_to_shared_tag
currently evaluating rule id
Definition Runtime.h:399
IQubitRecord * getQubitByPartnerAddr(QNodeAddr, int index)
Get the qubit record by partner's QNodeAddr.
Definition Runtime.cc:206
int send_tag
currently evaluating send/receive tag of this rule id (if it is defined)
Definition Runtime.h:358
QubitResources::iterator findQubit(IQubitRecord *)
find the qubit iterator that match with this rule_id and sequence_number
Definition Runtime.cc:148
void setRegVal(RegId reg_id, int32_t val)
Set the given value to the Register.
Definition Runtime.cc:200
Runtime()
Definition Runtime.cc:26
void debugSource(const Program &program) const
Definition Runtime.cc:429
Register registers[5]
Registers are temporary memory for Program execution.
Definition Runtime.h:375
bool debugging
if the flag is true, show debug information during RuleSet execution.
Definition Runtime.h:486
void purifyZ(RegId result, int bitset_index, QubitId qubit_id, QubitId trash_qubit_id)
perform Z purification and store the measurement result
Definition Runtime.cc:382
std::string debugInstruction(const InstructionTypes &instr) const
Definition Runtime.cc:438
RuleId rule_id
currently evaluating rule id
Definition Runtime.h:355
void setQubit(IQubitRecord *qubit_record, QubitId qubit_id)
bind the assigned Qubit to the given qubit id to use it in a Program.
Definition Runtime.cc:201
ICallBack * callback
The callback provides a way to access the RuleEngine.
Definition Runtime.h:349
void assignQubitToRuleSet(QNodeAddr partner_addr, IQubitRecord *qubit_record)
assign the entangled qubit to the RuleSet. The Runtime assign it to the first rule and the Rule can u...
Definition Runtime.cc:138
void gateY(QubitId)
apply Y gate
Definition Runtime.cc:355
void loadVal(MemoryKey key, RegId reg_id)
load the value from memory, and put it into the given register.
Definition Runtime.cc:241
bool terminated
This flag is enabled when the RuleSet finishes its tasks.
Definition Runtime.h:464
const Register & getReg(RegId reg_id) const
Get the Register in registers by RegId.
Definition Runtime.cc:198
void storeVal(MemoryKey key, MemoryValue val)
store the value into memory.
Definition Runtime.cc:240
Runtime & operator=(Runtime &&runtime)
Definition Runtime.cc:28
QubitResources qubits
This stores the entangled qubits that are assigned to the ruleset.
Definition Runtime.h:384
std::unordered_map< int, RuleId > shared_tag_to_rule_id
[shared_rule_tag] => [rule_id]
Definition Runtime.h:398
void debugRuntimeState()
Definition Runtime.cc:405
void promoteQubitWithNewPartner(IQubitRecord *qubit_record, QNodeAddr new_partner_addr)
promote the qubit that has new entangled partner.
Definition Runtime.cc:169
void jumpTo(const Label &label)
jump to the instruction that has the given label
Definition Runtime.cc:232
bool isQubitLocked(IQubitRecord *const)
check the qubit is locked or not. Purification uses the lock state in a qubit.
Definition Runtime.cc:404
void execInstruction(const InstructionTypes &op)
execute the one Instruction
Definition Runtime.cc:120
void freeQubit(QubitId)
free qubit and release it from the Rule and the RuleSet
Definition Runtime.cc:322
std::set< QNodeAddr > partners
The partners store the possible entangled partners' QNodeAddr. The RuleEngine looks at this variable ...
Definition Runtime.h:430
Definition InstructionVisitor.cc:7
omnetpp::SimTime Time
alias for omnetpp's simulation time.
Definition types.h:43
std::unordered_map< QubitId, IQubitRecord * > QubitNameMap
QubitId and qubit record map. This is initialized in before each Program execution.
Definition Runtime.h:39
Basis
basis for measurement instruction in a Program.
Definition types.h:116
std::unordered_map< MemoryKey, MemoryValue > Memory
Memory is a simple dict to store the value during RuleSet execution.
Definition Runtime.h:42
std::map< IQubitRecord *, std::tuple< QNodeAddr, RuleId, SequenceNumber > > SequenceNumberTracker
Definition Runtime.h:30
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
std::map< std::tuple< QNodeAddr, RuleId, SequenceNumber >, IQubitRecord * > QubitResourcesWithSequenceNumbers
(partner's qnode addr, assigned RuleId, sequence number) => [local half of the stationary bell pair q...
Definition Runtime.h:29
std::map< std::pair< QNodeAddr, RuleId >, SequenceNumber > SequenceNumberCounter
ResourceId needs to be increment each time a qubit of certain properties (same <QNodeAddr>) is added ...
Definition Runtime.h:33
std::map< RuleId, std::deque< MessageRecord > > MessageResources
Store messages for each rule for decision making mainly used for WaitRules (e.g., purification,...
Definition Runtime.h:36
std::variant< #define INSTR(Opcode,...) #define INSTR_LAST(Opcode,...) # 1 "/github/workspace/quisp/runtime/def_instructions.h" 1 # 87 "/github/workspace/quisp/runtime/opcode.h" 2 > InstructionTypes
a variant that is capable of storing all instructions
Definition opcode.h:84
int RuleId
Definition types.h:18
int PurType
purification type for Instructions. see rules::PurType enum.
Definition types.h:45
std::multimap< std::pair< QNodeAddr, RuleId >, IQubitRecord * > QubitResources
(partner's qnode addr, assigned RuleId) => [local half of the bell pair qubit record]
Definition Runtime.h:26
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
std::unordered_map< Label, int > LabelMap
utility type for storing a label and corresponding instruction index.
Definition types.h:113
this file contains the definitions of all the user-defined types widely used alongside the runtime::R...
Visitor class for instructions in a Program.
Definition InstructionVisitor.h:18
label to annotate the instruction index in a Program.
Definition types.h:95
a key of memory key-value store in a RuleSet
Definition types.h:103
internal class to describe QNode's address.
Definition types.h:70
describes Qubit id in a Program. This is like a local variable name in a runtime::Program....
Definition types.h:83
int32_t value
Definition Runtime.h:22
ICallBack is an interface for the callback of the Runtime.
Definition Runtime.h:58
virtual MeasurementOutcome measureQubitRandomly(IQubitRecord *)=0
virtual MeasurementOutcome measureQubitX(IQubitRecord *)=0
virtual MeasurementOutcome measureQubitY(IQubitRecord *)=0
virtual MeasurementOutcome measureQubitZ(IQubitRecord *)=0
virtual void sendLinkTomographyResult(const unsigned long ruleset_id, const Rule &rule, const int action_index, const QNodeAddr partner_addr, int count, MeasurementOutcome outcome, int max_count, Time start_time)=0
virtual int purifyX(IQubitRecord *qubit_rec, IQubitRecord *trash_qubit_rec)=0
virtual void gateX(IQubitRecord *)=0
virtual void sendSwappingResult(const unsigned long ruleset_id, const QNodeAddr partner_addr, const QNodeAddr new_partner_addr, const int shared_rule_tag, const int sequence_number, const int frame_correction)=0
virtual ~ICallBack()
Definition Runtime.h:59
virtual void freeAndResetQubit(IQubitRecord *)=0
virtual void sendPurificationResult(const unsigned long ruleset_id, const QNodeAddr partner_addr, const int shared_rule_tag, const int sequence_number, const int measurement_result, PurType protocol)=0
virtual int purifyY(IQubitRecord *qubit_rec, IQubitRecord *trash_qubit_rec)=0
virtual int getActionIndex(IQubitRecord *const)=0
virtual void gateY(IQubitRecord *)=0
virtual bool isQubitLocked(IQubitRecord *const)=0
virtual std::string getNodeInfo()
Definition Runtime.h:90
virtual int purifyZ(IQubitRecord *qubit_rec, IQubitRecord *trash_qubit_rec)=0
virtual void lockQubit(IQubitRecord *const, unsigned long rs_id, int rule_id, int action_index)=0
virtual void gateCNOT(IQubitRecord *control_qubit_rec, IQubitRecord *target_qubit_rec)=0
virtual void gateZ(IQubitRecord *)=0