QuISP
Loading...
Searching...
No Matches
quisp::runtime::Runtime Class Reference

Runtime class is responsible for executing the given RuleSet and the states' management. More...

#include <Runtime.h>

Collaboration diagram for quisp::runtime::Runtime:

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 &)
 
Runtimeoperator= (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 RegistergetReg (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.
 
IQubitRecordgetQubitBySequenceNumber (QNodeAddr, RuleId, SequenceNumber)
 Get the qubit record by sequence number.
 
IQubitRecordgetQubitByPartnerAddr (QNodeAddr, int index)
 Get the qubit record by partner's QNodeAddr.
 
IQubitRecordgetQubitByQubitId (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.
 
ICallBackcallback
 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, RuleIdshared_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< QNodeAddrpartners
 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.
 

Detailed Description

Runtime class is responsible for executing the given RuleSet and the states' management.

Constructor & Destructor Documentation

◆ Runtime() [1/3]

quisp::runtime::Runtime::Runtime ( )

◆ Runtime() [2/3]

quisp::runtime::Runtime::Runtime ( const RuleSet & ruleset,
ICallBack * callback )

◆ Runtime() [3/3]

quisp::runtime::Runtime::Runtime ( const Runtime & rt)

◆ ~Runtime()

quisp::runtime::Runtime::~Runtime ( )

Member Function Documentation

◆ assignMessageToRuleSet()

void quisp::runtime::Runtime::assignMessageToRuleSet ( int shared_rule_tag,
MessageRecord & msg_content )

assign the message to the rule

Parameters
partner_addrthe entangled partner QNode address for the qubit.
rule_idthe rule id to assign the qubit
msgthe content of the message (e.g., purification [measurement_result, sequence_number, pur_type], swapping [frame_correction, sequence_number])

◆ assignQubitToRule()

void quisp::runtime::Runtime::assignQubitToRule ( QNodeAddr partner_addr,
RuleId rule_id,
IQubitRecord * qubit_record )

assign the entangled qubit to the rule

Parameters
partner_addrthe entangled partner QNode address for the qubit.
rule_idthe rule id to assign the qubit
qubit_recordthe entangled qubit's record

◆ assignQubitToRuleSet()

void quisp::runtime::Runtime::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.

Parameters
partner_addrthe entangled partner QNode address for the qubit.
qubit_recordthe entangled qubit's record.

◆ assignRuleSet()

void quisp::runtime::Runtime::assignRuleSet ( const RuleSet & ruleset)

◆ cleanup()

void quisp::runtime::Runtime::cleanup ( )

this method resets the state before each Program execution.

◆ debugInstruction()

std::string quisp::runtime::Runtime::debugInstruction ( const InstructionTypes & instr) const

◆ debugRuntimeState()

void quisp::runtime::Runtime::debugRuntimeState ( )

◆ debugSource()

void quisp::runtime::Runtime::debugSource ( const Program & program) const

◆ exec()

void quisp::runtime::Runtime::exec ( )

public method to execute the assigned RuleSet.

◆ execInstruction()

void quisp::runtime::Runtime::execInstruction ( const InstructionTypes & op)

execute the one Instruction

◆ execProgram()

void quisp::runtime::Runtime::execProgram ( const Program & program)

execute the given Program in a Rule

◆ findQubit()

QubitResources::iterator quisp::runtime::Runtime::findQubit ( IQubitRecord * qubit_record)

find the qubit iterator that match with this rule_id and sequence_number

◆ freeQubit()

void quisp::runtime::Runtime::freeQubit ( QubitId qubit_id)

free qubit and release it from the Rule and the RuleSet

◆ gateCNOT()

void quisp::runtime::Runtime::gateCNOT ( QubitId control_qubit_id,
QubitId target_qubit_id )

apply CNOT gate

◆ gateX()

void quisp::runtime::Runtime::gateX ( QubitId qubit_id)

apply X gate

◆ gateY()

void quisp::runtime::Runtime::gateY ( QubitId qubit_id)

apply Y gate

◆ gateZ()

void quisp::runtime::Runtime::gateZ ( QubitId qubit_id)

apply Z gate

◆ getQubitByPartnerAddr()

IQubitRecord * quisp::runtime::Runtime::getQubitByPartnerAddr ( QNodeAddr partner_addr,
int index )

Get the qubit record by partner's QNodeAddr.

This method finds an index-th qubit record entangled with the partner from the qubits member. If the Runtime cannot find the qubit, this returns nullptr. The qubit must be assigned to the current rule_id.

Parameters
index
Returns
IQubitRecord*

◆ getQubitByQubitId()

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.

Parameters
qubit_id
Returns
IQubitRecord*

◆ getQubitBySequenceNumber()

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.

Parameters
partner_address
rule_id
sequence_number
Returns
IQubitRecord*

◆ getReg()

const Register & quisp::runtime::Runtime::getReg ( RegId reg_id) const

Get the Register in registers by RegId.

Parameters
reg_id
Returns
const Register&

◆ getRegVal()

int32_t quisp::runtime::Runtime::getRegVal ( RegId reg_id) const

Get the Register's value.

Parameters
reg_id
Returns
int32_t

◆ isQubitLocked()

bool quisp::runtime::Runtime::isQubitLocked ( IQubitRecord * const qubit)

check the qubit is locked or not. Purification uses the lock state in a qubit.

Returns
true the qubit is locked by a Rule
false the qubit is not locked

◆ jumpTo()

void quisp::runtime::Runtime::jumpTo ( const Label & label)

jump to the instruction that has the given label

Parameters
labellabel to jump.

◆ loadVal() [1/2]

MemoryValue quisp::runtime::Runtime::loadVal ( MemoryKey key)

load the value from memory.

Parameters
key
Returns
MemoryValue

◆ loadVal() [2/2]

void quisp::runtime::Runtime::loadVal ( MemoryKey key,
RegId reg_id )

load the value from memory, and put it into the given register.

Parameters
key
reg_id

◆ measureQubit() [1/3]

void quisp::runtime::Runtime::measureQubit ( QubitId qubit_id,
MemoryKey result_key,
Basis basis )

measure qubit with the given basis and store the result to the memory.

Parameters
qubit_idthe measurement target qubit's id
result_keythe key to store the measurement result
basisthe measurement result

◆ measureQubit() [2/3]

void quisp::runtime::Runtime::measureQubit ( QubitId qubit_id,
RegId result_reg,
Basis basis )

measure qubit with given basis and put result into register

Parameters
qubit_idqubit to measure
result_regregister to put result into
basismeasurement basis

◆ measureQubit() [3/3]

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

Parameters
qubit_idqubit to measure
result_regregister to put result into
basismeasurement basis

◆ operator=()

Runtime & quisp::runtime::Runtime::operator= ( Runtime && runtime)

◆ promoteQubit()

void quisp::runtime::Runtime::promoteQubit ( IQubitRecord * qubit_record)

promote the qubit to the next rule.

the next rule id is automatically derived by the Programs in the RuleSet.

Parameters
qubit_recordthe entangled qubit's record already assigned to the RuleSet

◆ promoteQubitWithNewPartner()

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

Parameters
qubit_recordthe entangled qubit's record already assigned to the RuleSet
new_partner_addrnew entangled partner's QNode address.

◆ purifyX()

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

◆ purifyY()

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

◆ purifyZ()

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

◆ setQubit()

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.

Parameters
qubit_record
qubit_id

◆ setRegVal()

void quisp::runtime::Runtime::setRegVal ( RegId reg_id,
int32_t val )

Set the given value to the Register.

Parameters
reg_idthe id for the register
valthe value to set the register

◆ storeVal()

void quisp::runtime::Runtime::storeVal ( MemoryKey key,
MemoryValue val )

store the value into memory.

Parameters
key
val

Member Data Documentation

◆ callback

ICallBack* quisp::runtime::Runtime::callback

The callback provides a way to access the RuleEngine.

◆ debugging

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.

◆ label_map

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

Memory quisp::runtime::Runtime::memory

The memory contains a variety of values during the RuleSet execution.

Unlike the registers, a Runtime does not initialize the memory in each Program execution. So we can use memory to pass a value between Condition and Action, Rules.

◆ message_found

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.

◆ messages

MessageResources quisp::runtime::Runtime::messages

currently evaluating rule id

◆ named_qubits

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.

◆ partners

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.

◆ pc

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.

◆ qubit_found

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.

◆ qubit_to_sequence_number

SequenceNumberTracker quisp::runtime::Runtime::qubit_to_sequence_number

currently evaluating rule id

◆ qubits

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.

◆ receive_tag

int quisp::runtime::Runtime::receive_tag = -1

currently evaluating rule id

◆ registers

Register quisp::runtime::Runtime::registers[5]

Registers are temporary memory for Program execution.

Before each Program execution, Runtime initializes these registers with 0.

◆ resource_counter

SequenceNumberCounter quisp::runtime::Runtime::resource_counter

This stores the latest sequence no. of resource assigned to the Stage/Rule.

◆ return_code

ReturnCode quisp::runtime::Runtime::return_code = ReturnCode::NONE

The return_code describes the program's exit status.

The Runtime uses the return_code to determine how the Runtime should execute the RuleSet next. Whether to execute the action, go to the following rule without executing it, or stop the ruleset.

◆ rule_id

RuleId quisp::runtime::Runtime::rule_id = -1

currently evaluating rule id

◆ rule_id_to_shared_tag

std::unordered_map<RuleId, int> quisp::runtime::Runtime::rule_id_to_shared_tag

currently evaluating rule id

◆ ruleset

RuleSet quisp::runtime::Runtime::ruleset

The assigned RuleSet for this Runtime instance.

One Runtime has only one RuleSet to process and is never re-used for another RuleSet.

◆ send_tag

int quisp::runtime::Runtime::send_tag = -1

currently evaluating send/receive tag of this rule id (if it is defined)

◆ sequence_number_to_qubit

QubitResourcesWithSequenceNumbers quisp::runtime::Runtime::sequence_number_to_qubit

currently evaluating rule id

◆ shared_tag_to_rule_id

std::unordered_map<int, RuleId> quisp::runtime::Runtime::shared_tag_to_rule_id

[shared_rule_tag] => [rule_id]

◆ should_exit

bool quisp::runtime::Runtime::should_exit = false

if this flag is true, the Runtime stops the Program execution.

◆ terminated

bool quisp::runtime::Runtime::terminated = false

This flag is enabled when the RuleSet finishes its tasks.

If this flag is true, the Runtime stops the Program execution, and then the RuleEngine deletes the RuleSet and the Runtime.

◆ visitor

InstructionVisitor quisp::runtime::Runtime::visitor

The visitor handles all instruction types for Program execution.


The documentation for this class was generated from the following files: