QuISP
|
Runtime class is responsible for executing the given RuleSet and the states' management. More...
#include <Runtime.h>
Classes | |
struct | ICallBack |
ICallBack is an interface for the callback of the Runtime. More... | |
Public Member Functions | |
Runtime () | |
Runtime (const RuleSet &ruleset, ICallBack *callback) | |
Runtime (const Runtime &) | |
Runtime & | operator= (Runtime &&runtime) |
~Runtime () | |
void | assignRuleSet (const RuleSet &ruleset) |
void | cleanup () |
this method resets the state before each Program execution. | |
void | exec () |
public method to execute the assigned RuleSet. | |
void | execProgram (const Program &program) |
execute the given Program in a Rule | |
void | execInstruction (const InstructionTypes &op) |
execute the one Instruction | |
void | assignMessageToRuleSet (int shared_rule_tag, MessageRecord &msg_content) |
assign the message to the rule | |
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 use the qubit. | |
void | assignQubitToRule (QNodeAddr partner_addr, RuleId rule_id, IQubitRecord *qubit_record) |
assign the entangled qubit to the rule | |
QubitResources::iterator | findQubit (IQubitRecord *) |
find the qubit iterator that match with this rule_id and sequence_number | |
register operations | |
const Register & | getReg (RegId reg_id) const |
Get the Register in registers by RegId. | |
int32_t | getRegVal (RegId reg_id) const |
Get the Register's value. | |
void | setRegVal (RegId reg_id, int32_t val) |
Set the given value to the Register. | |
void | jumpTo (const Label &label) |
jump to the instruction that has the given label | |
memory operations | |
void | storeVal (MemoryKey key, MemoryValue val) |
store the value into memory. | |
void | loadVal (MemoryKey key, RegId reg_id) |
load the value from memory, and put it into the given register. | |
MemoryValue | loadVal (MemoryKey key) |
load the value from memory. | |
qubit record operations | |
bool | isQubitLocked (IQubitRecord *const) |
check the qubit is locked or not. Purification uses the lock state in a qubit. | |
IQubitRecord * | getQubitBySequenceNumber (QNodeAddr, RuleId, SequenceNumber) |
Get the qubit record by sequence number. | |
IQubitRecord * | getQubitByPartnerAddr (QNodeAddr, int index) |
Get the qubit record by partner's QNodeAddr. | |
IQubitRecord * | getQubitByQubitId (QubitId qubit_id) const |
Get the Qubit By QubitId. | |
void | setQubit (IQubitRecord *qubit_record, QubitId qubit_id) |
bind the assigned Qubit to the given qubit id to use it in a Program. | |
void | promoteQubit (IQubitRecord *qubit_record) |
promote the qubit to the next rule. | |
void | promoteQubitWithNewPartner (IQubitRecord *qubit_record, QNodeAddr new_partner_addr) |
promote the qubit that has new entangled partner. | |
quantum operations | |
void | measureQubit (QubitId qubit_id, MemoryKey result_key, Basis basis) |
measure qubit with the given basis and store the result to the memory. | |
void | measureQubit (QubitId qubit_id, RegId result_reg, Basis basis) |
measure qubit with given basis and put result into register | |
void | measureQubit (QubitId qubit_id, RegId result_reg, int bitset_index, Basis basis) |
measure qubit with given basis and put result into register | |
void | freeQubit (QubitId) |
free qubit and release it from the Rule and the RuleSet | |
void | gateX (QubitId) |
apply X gate | |
void | gateZ (QubitId) |
apply Z gate | |
void | gateY (QubitId) |
apply Y gate | |
void | gateCNOT (QubitId control_qubit_id, QubitId target_qubit_id) |
apply CNOT gate | |
void | purifyX (RegId result, int bitset_index, QubitId qubit_id, QubitId trash_qubit_id) |
perform X purification and store the measurement result | |
void | purifyZ (RegId result, int bitset_index, QubitId qubit_id, QubitId trash_qubit_id) |
perform Z purification and store the measurement result | |
void | purifyY (RegId result, int bitset_index, QubitId qubit_id, QubitId trash_qubit_id) |
perform Y purification and store the measurement result | |
debugging | |
void | debugRuntimeState () |
void | debugSource (const Program &program) const |
std::string | debugInstruction (const InstructionTypes &instr) const |
Public Attributes | |
related components | |
InstructionVisitor | visitor |
The visitor handles all instruction types for Program execution. | |
ICallBack * | callback |
The callback provides a way to access the RuleEngine. | |
states | |
RuleId | rule_id = -1 |
currently evaluating rule id | |
int | send_tag = -1 |
currently evaluating send/receive tag of this rule id (if it is defined) | |
int | receive_tag = -1 |
currently evaluating rule id | |
unsigned int | pc = 0 |
program counter for Program execution. | |
Register | registers [5] |
Registers are temporary memory for Program execution. | |
QubitResources | qubits |
This stores the entangled qubits that are assigned to the ruleset. | |
MessageResources | messages |
currently evaluating rule id | |
QubitResourcesWithSequenceNumbers | sequence_number_to_qubit |
currently evaluating rule id | |
SequenceNumberTracker | qubit_to_sequence_number |
currently evaluating rule id | |
SequenceNumberCounter | resource_counter |
This stores the latest sequence no. of resource assigned to the Stage/Rule. | |
std::unordered_map< int, RuleId > | shared_tag_to_rule_id |
[shared_rule_tag] => [rule_id] | |
std::unordered_map< RuleId, int > | rule_id_to_shared_tag |
currently evaluating rule id | |
QubitNameMap | named_qubits |
This contains a map for a QubitId and a qubit. | |
Memory | memory |
The memory contains a variety of values during the RuleSet execution. | |
RuleSet | ruleset |
The assigned RuleSet for this Runtime instance. | |
std::set< QNodeAddr > | partners |
The partners store the possible entangled partners' QNodeAddr. The RuleEngine looks at this variable to determine which entangled qubit to assign to which rule set. | |
LabelMap const * | label_map = nullptr |
The label_map is a map of the instruction index and its label to allow to jump or branch. | |
flags | |
ReturnCode | return_code = ReturnCode::NONE |
The return_code describes the program's exit status. | |
bool | should_exit = false |
if this flag is true, the Runtime stops the Program execution. | |
bool | terminated = false |
This flag is enabled when the RuleSet finishes its tasks. | |
bool | qubit_found = false |
The GET_QUBIT instruction sets this flag. if it's true, the GET_QUBIT instruction successfully found the qubit. if not, the instruction cannot find qubit. | |
bool | message_found = false |
The GET_MESSAGE instruction sets this flag. if it's true, the GET_MESSAGE instruction successfully found the corresponding message. if not, the instruction cannot find a message meant for this Program. | |
bool | debugging = false |
if the flag is true, show debug information during RuleSet execution. | |
quisp::runtime::Runtime::Runtime | ( | ) |
quisp::runtime::Runtime::Runtime | ( | const Runtime & | rt | ) |
quisp::runtime::Runtime::~Runtime | ( | ) |
void quisp::runtime::Runtime::assignMessageToRuleSet | ( | int | shared_rule_tag, |
MessageRecord & | msg_content ) |
assign the message to the rule
partner_addr | the entangled partner QNode address for the qubit. |
rule_id | the rule id to assign the qubit |
msg | the content of the message (e.g., purification [measurement_result, sequence_number, pur_type], swapping [frame_correction, sequence_number]) |
void quisp::runtime::Runtime::assignQubitToRule | ( | QNodeAddr | partner_addr, |
RuleId | rule_id, | ||
IQubitRecord * | qubit_record ) |
assign the entangled qubit to the rule
partner_addr | the entangled partner QNode address for the qubit. |
rule_id | the rule id to assign the qubit |
qubit_record | the entangled qubit's record |
void quisp::runtime::Runtime::assignQubitToRuleSet | ( | QNodeAddr | partner_addr, |
IQubitRecord * | qubit_record ) |
void quisp::runtime::Runtime::assignRuleSet | ( | const RuleSet & | ruleset | ) |
void quisp::runtime::Runtime::cleanup | ( | ) |
this method resets the state before each Program execution.
std::string quisp::runtime::Runtime::debugInstruction | ( | const InstructionTypes & | instr | ) | const |
void quisp::runtime::Runtime::debugRuntimeState | ( | ) |
void quisp::runtime::Runtime::debugSource | ( | const Program & | program | ) | const |
void quisp::runtime::Runtime::exec | ( | ) |
public method to execute the assigned RuleSet.
void quisp::runtime::Runtime::execInstruction | ( | const InstructionTypes & | op | ) |
execute the one Instruction
void quisp::runtime::Runtime::execProgram | ( | const Program & | program | ) |
QubitResources::iterator quisp::runtime::Runtime::findQubit | ( | IQubitRecord * | qubit_record | ) |
find the qubit iterator that match with this rule_id and sequence_number
void quisp::runtime::Runtime::freeQubit | ( | QubitId | qubit_id | ) |
apply CNOT gate
void quisp::runtime::Runtime::gateX | ( | QubitId | qubit_id | ) |
apply X gate
void quisp::runtime::Runtime::gateY | ( | QubitId | qubit_id | ) |
apply Y gate
void quisp::runtime::Runtime::gateZ | ( | QubitId | qubit_id | ) |
apply Z gate
IQubitRecord * quisp::runtime::Runtime::getQubitByPartnerAddr | ( | QNodeAddr | partner_addr, |
int | index ) |
IQubitRecord * quisp::runtime::Runtime::getQubitByQubitId | ( | QubitId | qubit_id | ) | const |
Get the Qubit By QubitId.
This method finds a qubit record named with the given QubitId in the named_qubits member.
qubit_id |
IQubitRecord * quisp::runtime::Runtime::getQubitBySequenceNumber | ( | QNodeAddr | partner_addr, |
RuleId | rule_id, | ||
SequenceNumber | sequence_number ) |
Get the qubit record by sequence number.
This method finds a qubit record with the associated sequence number. If the Runtime cannot find the qubit, this returns nullptr. Reminder, sequence number is the order in which the qubit is assisgned to the Program.
partner_address | |
rule_id | |
sequence_number |
int32_t quisp::runtime::Runtime::getRegVal | ( | RegId | reg_id | ) | const |
bool quisp::runtime::Runtime::isQubitLocked | ( | IQubitRecord * const | qubit | ) |
check the qubit is locked or not. Purification uses the lock state in a qubit.
void quisp::runtime::Runtime::jumpTo | ( | const Label & | label | ) |
jump to the instruction that has the given label
label | label to jump. |
MemoryValue quisp::runtime::Runtime::loadVal | ( | MemoryKey | key | ) |
load the value from memory, and put it into the given register.
key | |
reg_id |
measure qubit with the given basis and store the result to the memory.
qubit_id | the measurement target qubit's id |
result_key | the key to store the measurement result |
basis | the measurement result |
measure qubit with given basis and put result into register
qubit_id | qubit to measure |
result_reg | register to put result into |
basis | measurement basis |
void quisp::runtime::Runtime::measureQubit | ( | QubitId | qubit_id, |
RegId | result_reg, | ||
int | bitset_index, | ||
Basis | basis ) |
measure qubit with given basis and put result into register
qubit_id | qubit to measure |
result_reg | register to put result into |
basis | measurement basis |
void quisp::runtime::Runtime::promoteQubit | ( | IQubitRecord * | qubit_record | ) |
void quisp::runtime::Runtime::promoteQubitWithNewPartner | ( | IQubitRecord * | qubit_record, |
QNodeAddr | new_partner_addr ) |
promote the qubit that has new entangled partner.
entanglement swapping operations need the promotion of the qubit
qubit_record | the entangled qubit's record already assigned to the RuleSet |
new_partner_addr | new entangled partner's QNode address. |
void quisp::runtime::Runtime::purifyX | ( | RegId | result, |
int | bitset_index, | ||
QubitId | qubit_id, | ||
QubitId | trash_qubit_id ) |
perform X purification and store the measurement result
void quisp::runtime::Runtime::purifyY | ( | RegId | result, |
int | bitset_index, | ||
QubitId | qubit_id, | ||
QubitId | trash_qubit_id ) |
perform Y purification and store the measurement result
void quisp::runtime::Runtime::purifyZ | ( | RegId | result, |
int | bitset_index, | ||
QubitId | qubit_id, | ||
QubitId | trash_qubit_id ) |
perform Z purification and store the measurement result
void quisp::runtime::Runtime::setQubit | ( | IQubitRecord * | qubit_record, |
QubitId | qubit_id ) |
bind the assigned Qubit to the given qubit id to use it in a Program.
qubit_record | |
qubit_id |
void quisp::runtime::Runtime::setRegVal | ( | RegId | reg_id, |
int32_t | val ) |
Set the given value to the Register.
reg_id | the id for the register |
val | the value to set the register |
void quisp::runtime::Runtime::storeVal | ( | MemoryKey | key, |
MemoryValue | val ) |
store the value into memory.
key | |
val |
ICallBack* quisp::runtime::Runtime::callback |
The callback provides a way to access the RuleEngine.
bool quisp::runtime::Runtime::debugging = false |
if the flag is true, show debug information during RuleSet execution.
The showing debugging information is a heavy operation. We recommend you enable this with a debugger.
LabelMap const* quisp::runtime::Runtime::label_map = nullptr |
The label_map is a map of the instruction index and its label to allow to jump or branch.
The Runtime changes the value of the pc to the instruction index corresponding to the given label to jump or branch the execution.
Memory quisp::runtime::Runtime::memory |
bool quisp::runtime::Runtime::message_found = false |
The GET_MESSAGE instruction sets this flag. if it's true, the GET_MESSAGE instruction successfully found the corresponding message. if not, the instruction cannot find a message meant for this Program.
MessageResources quisp::runtime::Runtime::messages |
currently evaluating rule id
QubitNameMap quisp::runtime::Runtime::named_qubits |
This contains a map for a QubitId and a qubit.
The named_qubits must store the qubit in the qubits
member.
std::set<QNodeAddr> quisp::runtime::Runtime::partners |
The partners store the possible entangled partners' QNodeAddr. The RuleEngine looks at this variable to determine which entangled qubit to assign to which rule set.
unsigned int quisp::runtime::Runtime::pc = 0 |
program counter for Program execution.
The pc points to the current instruction, and after the instruction is executed, the pc will be incremented to point to the next instruction. This value is changed when we want to jump or branch.
bool quisp::runtime::Runtime::qubit_found = false |
The GET_QUBIT instruction sets this flag. if it's true, the GET_QUBIT instruction successfully found the qubit. if not, the instruction cannot find qubit.
SequenceNumberTracker quisp::runtime::Runtime::qubit_to_sequence_number |
currently evaluating rule id
QubitResources quisp::runtime::Runtime::qubits |
This stores the entangled qubits that are assigned to the ruleset.
The key is a pair of the entangled partner's QNodeAddr and the assigned RuleId. When Entanglement Swapping changes the entangled partner, we need to erase the record and insert a new key with a new entangled partner.
int quisp::runtime::Runtime::receive_tag = -1 |
currently evaluating rule id
Register quisp::runtime::Runtime::registers[5] |
SequenceNumberCounter quisp::runtime::Runtime::resource_counter |
This stores the latest sequence no. of resource assigned to the Stage/Rule.
ReturnCode quisp::runtime::Runtime::return_code = ReturnCode::NONE |
RuleId quisp::runtime::Runtime::rule_id = -1 |
currently evaluating rule id
std::unordered_map<RuleId, int> quisp::runtime::Runtime::rule_id_to_shared_tag |
currently evaluating rule id
RuleSet quisp::runtime::Runtime::ruleset |
int quisp::runtime::Runtime::send_tag = -1 |
currently evaluating send/receive tag of this rule id (if it is defined)
QubitResourcesWithSequenceNumbers quisp::runtime::Runtime::sequence_number_to_qubit |
currently evaluating rule id
std::unordered_map<int, RuleId> quisp::runtime::Runtime::shared_tag_to_rule_id |
[shared_rule_tag] => [rule_id]
bool quisp::runtime::Runtime::should_exit = false |
bool quisp::runtime::Runtime::terminated = false |
InstructionVisitor quisp::runtime::Runtime::visitor |
The visitor handles all instruction types for Program execution.