simulaqron.virtNode package¶
Submodules¶
simulaqron.virtNode.basics module¶
-
class
simulaqron.virtNode.basics.
quantumEngine
(node, num, maxQubits=10)[source]¶ Bases:
twisted.spread.flavors.Referenceable
Basic quantum engine. Abstract class meant to be subclassed to implement different simulation backends.
- Attributes:
Arguments node node this register is started from num number of this register maxQubits maximum number of qubits this register supports
-
abstract
absorb
(other)[source]¶ Absorb the qubits from the other engine into this one. This is done by tensoring the state at the end. :rtype: None
-
abstract
absorb_parts
(R, I, activeQ)[source]¶ Absorb the qubits, given in pieces
Arguments: R real part of the qubit state as a list I imaginary part as a list activeQ active number of qubits :rtype: None
-
abstract
add_fresh_qubit
()[source]¶ Add a new qubit initialized in the |0> state. :return: The qubit number :rtype: int
-
abstract
add_qubit
(newQubit)[source]¶ Add new qubit in the state described by the density matrix newQubit :return: The qubit number :rtype: int
-
abstract
apply_CNOT
(qubitNum1, qubitNum2)[source]¶ Applies the CNOT to the qubit with the numbers qubitNum1 and qubitNum2. :rtype: None
-
abstract
apply_CPHASE
(qubitNum1, qubitNum2)[source]¶ Applies the CPHASE to the qubit with the numbers qubitNum1 and qubitNum2. :rtype: None
-
abstract
apply_H
(qubitNum)[source]¶ Applies a Hadamard gate to the qubits with number qubitNum. :rtype: None
-
abstract
apply_K
(qubitNum)[source]¶ Applies a K gate to the qubits with number qubitNum. Maps computational basis to Y eigenbasis. :rtype: None
-
abstract
apply_T
(qubitNum)[source]¶ Applies a T gate to the qubits with number qubitNum. :rtype: None
-
abstract
apply_X
(qubitNum)[source]¶ Applies a X gate to the qubits with number qubitNum. :rtype: None
-
abstract
apply_Y
(qubitNum)[source]¶ Applies a Y gate to the qubits with number qubitNum. :rtype: None
-
abstract
apply_Z
(qubitNum)[source]¶ Applies a Z gate to the qubits with number qubitNum. :rtype: None
-
abstract
apply_onequbit_gate
(gateU, qubitNum)[source]¶ Applies a unitary gate to the specified qubit.
Arguments: gateU unitary to apply as Qobj qubitNum the number of the qubit this gate is applied to :rtype: None
-
abstract
apply_rotation
(qubitNum, n, a)[source]¶ Applies a rotation around the axis n with the angle a to qubit with number qubitNum. If n is zero a ValueError is raised.
- Parameters
qubitNum – int Qubit number
n – tuple A tuple of three numbers specifying the rotation axis, e.g n=(1,0,0)
a – float The rotation angle in radians.
- Return type
None
-
abstract
apply_twoqubit_gate
(gateU, qubit1, qubit2)[source]¶ Applies a unitary gate to the two specified qubits.
Arguments: gateU unitary to apply as Qobj qubit1 the first qubit qubit2 the second qubit :rtype: None
-
abstract
get_register_RI
()[source]¶ Retrieves the entire register in real and imaginary parts and returns the result as a list. Twisted only likes to send real valued lists, not complex ones. :return: The real and imaginary parts of a qubit state :rtype: tuple
-
abstract
measure_qubit
(qubitNum)[source]¶ Measures the desired qubit in the standard basis. This returns the classical outcome and deletes the qubit.
Arguments: qubitNum qubit to be measured :return: The meaurement outcome :rtype: int
-
abstract
measure_qubit_inplace
(qubitNum)[source]¶ Measures the desired qubit in the standard basis. This returns the classical outcome. The quantum register is in the post-measurment state corresponding to the obtained outcome.
Arguments: qubitNum qubit to be measured :return: The meaurement outcome :rtype: int
simulaqron.virtNode.projectQSimulator module¶
-
class
simulaqron.virtNode.projectQSimulator.
projectQEngine
(node, num, maxQubits=10)[source]¶ Bases:
simulaqron.virtNode.basics.quantumEngine
Basic quantum engine which uses ProjectQ.
- Attributes:
maxQubits: maximum number of qubits this engine will support.
-
absorb
(other)[source]¶ Absorb the qubits from the other engine into this one. This is done by tensoring the state at the end.
-
absorb_parts
(R, I, activeQ)[source]¶ Absorb the qubits, given in pieces
Arguments: R real part of the qubit state as a list I imaginary part as a list activeQ active number of qubits
-
apply_CNOT
(qubitNum1, qubitNum2)[source]¶ Applies the CNOT to the qubit with the numbers qubitNum1 and qubitNum2.
-
apply_CPHASE
(qubitNum1, qubitNum2)[source]¶ Applies the CPHASE to the qubit with the numbers qubitNum1 and qubitNum2.
-
apply_K
(qubitNum)[source]¶ Applies a K gate to the qubits with number qubitNum. Maps computational basis to Y eigenbasis.
-
apply_onequbit_gate
(gate, qubitNum)[source]¶ Applies a unitary gate to the specified qubit.
Arguments: gate The project Q gate to be applied qubitNum the number of the qubit this gate is applied to
-
apply_rotation
(qubitNum, n, a)[source]¶ Applies a rotation around the axis n with the angle a to qubit with number qubitNum. If n is zero a ValueError is raised.
- Parameters
qubitNum – int Qubit number
n – tuple of floats A tuple of three numbers specifying the rotation axis, e.g n=(1,0,0)
a – float The rotation angle in radians.
-
apply_twoqubit_gate
(gate, qubit1, qubit2)[source]¶ Applies a unitary gate to the two specified qubits.
Arguments: gate The project Q gate to be applied qubit1 the first qubit qubit2 the second qubit
-
get_register_RI
()[source]¶ Retrieves the entire register in real and imaginary parts and returns the result as a list. Twisted only likes to send real valued lists, not complex ones.
-
measure_qubit
(qubitNum)[source]¶ Measures the desired qubit in the standard basis. This returns the classical outcome and deletes the qubit.
Arguments: qubitNum qubit to be measured
simulaqron.virtNode.quantum module¶
-
class
simulaqron.virtNode.quantum.
simulatedQubit
(node, register, simNum, num=0)[source]¶ Bases:
twisted.spread.flavors.Referenceable
Simulated qubit object in the specified local simulation engine.
- Arguments
- node
network node that this qubit lives at
- register
register on that node that the qubit is in
Note
Qubit objects are local to each node that is simulating a particular quantum register. A qubit object provides the backing for a virtual qubit, which may be at another node.
-
remote_apply_K
()[source]¶ Apply K gate to itself by passing it onto the underlying register. Maps computational to Y eigenbasis.
-
remote_apply_rotation
(*args)[source]¶ Apply rotation around axis n with angle a. Arguments: n A tuple of three numbers specifying the rotation axis, e.g n=(1,0,0) a The rotation angle in radians.
-
remote_cnot_onto
(targetNum)[source]¶ Performs a CNOT operation with this qubit as control, and the other qubit as target.
Arguments targetNum the qubit to use as the target of the CNOT
-
remote_cphase_onto
(targetNum)[source]¶ Performs a CPHASE operation with this qubit as control, and the other qubit as target.
Arguments targetNum the qubit to use as the target of the CPHASE
-
remote_get_details
()[source]¶ Returns out simulation number as well as the details of this simulating node.
-
remote_get_qubit
()[source]¶ Returns the state of the qubits in the list qList by tracing out the rest.
-
remote_measure
()[source]¶ Measure the qubit in the standard basis. This does delete the qubit.
Returns the measurement outcome.
simulaqron.virtNode.qutipSimulator module¶
-
class
simulaqron.virtNode.qutipSimulator.
qutipEngine
(node, num, maxQubits=10)[source]¶ Bases:
simulaqron.virtNode.basics.quantumEngine
Basic quantum engine which uses QuTip. Works with density matrices and in principle allows full quantum dynamics via QuTip. Subsequently, this is quite slow.
- Attributes:
maxQubits: maximum number of qubits this engine will support.
-
absorb
(other)[source]¶ Absorb the qubits from the other engine into this one. This is done by tensoring the state at the end.
-
absorb_parts
(R, I, activeQ)[source]¶ Absorb the qubits, given in pieces
Arguments: R real part of the qubit state as a list I imaginary part as a list activeQ active number of qubits
-
apply_CNOT
(qubitNum1, qubitNum2)[source]¶ Applies the CNOT to the qubit with the numbers qubitNum1 and qubitNum2.
-
apply_CPHASE
(qubitNum1, qubitNum2)[source]¶ Applies the CPHASE to the qubit with the numbers qubitNum1 and qubitNum2.
-
apply_K
(qubitNum)[source]¶ Applies a K gate to the qubits with number qubitNum. Maps computational basis to Y eigenbasis.
-
apply_onequbit_gate
(gateU, qubitNum)[source]¶ Applies a unitary gate to the specified qubit.
Arguments: gateU unitary to apply as Qobj qubitNum the number of the qubit this gate is applied to
-
apply_rotation
(qubitNum, n, a)[source]¶ Applies a rotation around the axis n with the angle a to qubit with number qubitNum. If n is zero a ValueError is raised.
- Parameters
qubitNum – int Qubit number
n – tuple A tuple of three numbers specifying the rotation axis, e.g n=(1,0,0)
a – float The rotation angle in radians.
- Return type
None
-
apply_twoqubit_gate
(gateU, qubit1, qubit2)[source]¶ Applies a unitary gate to the two specified qubits.
Arguments: gateU unitary to apply as Qobj qubit1 the first qubit qubit2 the second qubit
-
get_qubits_RI
(qList)[source]¶ Retrieves the qubits in the list and returns the result as a list divided into a real and imaginary part. Twisted only likes to send real values lists, not complex ones.
Arguments qList list of qubits to retrieve, e.g. [1, 4]
-
get_register_RI
()[source]¶ Retrieves the entire register in real and imaginary parts and returns the result as a list. Twisted only likes to send real valued lists, not complex ones.
-
measure_qubit
(qubitNum)[source]¶ Measures the desired qubit in the standard basis. This returns the classical outcome and deletes the qubit.
Arguments: qubitNum qubit to be measured
simulaqron.virtNode.stabilizerSimulator module¶
-
class
simulaqron.virtNode.stabilizerSimulator.
stabilizerEngine
(node, num, maxQubits=10)[source]¶ Bases:
simulaqron.virtNode.basics.quantumEngine
Basic quantum engine which uses stabilizer formalism. Thus only Clifford operations can be performed
- Attributes:
maxQubits: maximum number of qubits this engine will support.
-
absorb
(other)[source]¶ Absorb the qubits from the other engine into this one. This is done by tensoring the state at the end.
-
absorb_parts
(R, I, activeQ)[source]¶ Absorb the qubits, given in pieces
Arguments: R The array describing the stabilizer state (from StabilizerState.to_array) I Unused activeQ active number of qubits
-
property
activeQubits
¶
-
add_qubit
(newQubit)[source]¶ Add new qubit in the state described by the array containing the generators of the stabilizer group. This should be in the form required by the StabilizerState class.
-
apply_CNOT
(qubitNum1, qubitNum2)[source]¶ Applies the CNOT to the qubit with the numbers qubitNum1 and qubitNum2.
-
apply_CPHASE
(qubitNum1, qubitNum2)[source]¶ Applies the CPHASE to the qubit with the numbers qubitNum1 and qubitNum2.
-
apply_K
(qubitNum)[source]¶ Applies a K gate to the qubits with number qubitNum. Maps computational basis to Y eigenbasis.
-
apply_onequbit_gate
(gate, qubitNum)[source]¶ Applies a unitary gate to the specified qubit.
Arguments: gate The project Q gate to be applied qubitNum the number of the qubit this gate is applied to
-
apply_rotation
(qubitNum, n, a)[source]¶ Applies a rotation around the axis n with the angle a to qubit with number qubitNum. If n is zero a ValueError is raised.
- Parameters
qubitNum – int Qubit number
n – tuple of floats A tuple of three numbers specifying the rotation axis, e.g n=(1,0,0)
a – float The rotation angle in radians.
-
apply_twoqubit_gate
(gate, qubit1, qubit2)[source]¶ Applies a unitary gate to the two specified qubits.
Arguments: gate The project Q gate to be applied qubit1 the first qubit qubit2 the second qubit
-
get_register_RI
()[source]¶ Retrieves the entire register in real and imaginary part. Twisted only likes to send real valued lists, not complex ones. Since this is in stabilizer formalism the real part will be the boolean matrix describing the generators and the imaginary part will be None
-
measure_qubit
(qubitNum)[source]¶ Measures the desired qubit in the standard basis. This returns the classical outcome and deletes the qubit.
Arguments: qubitNum qubit to be measured
simulaqron.virtNode.virtual module¶
-
class
simulaqron.virtNode.virtual.
QubitCQC
(fromName, toName, from_app_id, to_app_id, new_virt_num, rawEntInfo=None)[source]¶ Bases:
object
-
class
simulaqron.virtNode.virtual.
backEnd
(name, virtualFile, network_name='default')[source]¶ Bases:
object
-
class
simulaqron.virtNode.virtual.
virtualNode
(ID, config, maxQubits=20, maxRegisters=1000)[source]¶ Bases:
twisted.spread.flavors.Root
-
connectNet
()[source]¶ Initialize the connections to the other virtual nodes in the network according to the available configuration.
-
connect_to_node
(node)[source]¶ Connects to other node. If node not up yet, waits for CONF_WAIT_TIME seconds.
-
get_connection
(name)[source]¶ Returns the connection specified by ‘name’. If no such connection is up yet but name is in the configuration file, wait and try again.
-
get_sim_id
()[source]¶ Similarly, this is a crude and horrible cludge to generate unique IDs for simulated qubits.
-
get_virtual_id
()[source]¶ This is a crude and horrible cludge to generate unique IDs for virtual qubits.
-
handle_connection
(obj, node)[source]¶ Callback obtaining twisted root object when connection to the node given by the node details ‘node’.
-
handle_connection_error
(reason, node)[source]¶ Handles errors from trying to connect to other node. If a ConnectionRefusedError is raised another try will be made after CONF_WAIT_TIME seconds. CONF_WAIT_TIME is set in ‘settings.py’. Any other error is raised again.
-
local_merge_regs
(qubit1, qubit2)[source]¶ Merges the two local quantum registers. Note that these register may simulate virtual qubits across different network nodes. This will ignore maxQubits and simply create one large register allowing twice maxQubits qubits.
Arguments qubit1 qubit1 in reg1, called from remote having access to only qubits qubit2 qubit2 in reg2
-
remote_add_qubit
(name, simQubit)[source]¶ Add a qubit to the local virtual node.
Arguments name name of the node simulating this qubit simQubit simulated qubit reference in the backend we’re adding
-
remote_add_register
(maxQubits=10)[source]¶ Adds a new register to the node..
Arguments: maxQubits maximum number of qubits to use in the default engine
-
remote_check_connections
()[source]¶ Checks if all connections are up. (Just checks if the number of connections equal the number of nodes in config-file)
-
remote_cqc_add_epr_list
(fromName, from_app_id, to_app_id, new_virt_num, rawEntInfo)[source]¶ Add an item to the epr list for use in CQC.
-
remote_cqc_add_recv_list
(fromName, from_app_id, to_app_id, new_virt_num)[source]¶ Add an item to the received list for use in CQC.
-
remote_cqc_get_epr_recv
(to_app_id)[source]¶ Retrieve the next qubit (half of an EPR-pair) with the given app ID from the received list.
-
remote_cqc_get_recv
(to_app_id)[source]¶ Retrieve the next qubit with the given app ID form the received list.
-
remote_cqc_send_epr_half
(num, targetName, app_id, remote_app_id, rawEntInfo)[source]¶ Send interface for CQC to add the qubit to the remote nodes received list for an application.
Arguments: num number of virtual qubit to send targetName name of the node to send to app_id application asking to have this qubit delivered remote_app_id application ID to deliver the qubit to entInfo entanglement information
-
remote_cqc_send_qubit
(num, targetName, app_id, remote_app_id)[source]¶ Send interface for CQC to add the qubit to the remote nodes received list for an application.
Arguments: num number of virtual qubit to send targetName name of the node to send to app_id application asking to have this qubit delivered remote_app_id application ID to deliver the qubit to
-
remote_delete_register
(reg)[source]¶ Removes the register from the node. Happens if the last qubit in the register is measured out.
-
remote_get_multiple_qubits
(qList)[source]¶ Return the state of multiple qubits virtually located at this node. This will fail if the qubits are not in the same register or thus also simulating node.
Arguments qList list of virtual qubits of which to retrieve the state
-
remote_get_register
(qubit)[source]¶ Return the value of of a locally simulated register which contains this virtual qubit.
-
remote_get_register_RI
(qubit)[source]¶ Return the real and imaginary part of the (possibly remote) simulated register which contains this virtual qubit.
-
remote_get_register_del
(qubitNum)[source]¶ Return the value of of a locally simulated register, and remove the simulated qubits from this node.
Caution: virtual qubits not updated.
-
remote_get_state
(simNumList)[source]¶ Return the state of multiple qubits corresponding to the IDs in simNumList.
-
remote_get_virtual_ref
(num)[source]¶ Return a virual qubit object for the given number.
Arguments num number of the virtual qubit
-
remote_lock_reg_qubits
(qubitNum)[source]¶ Acquire the lock on all qubits in the same register as qubitNum.
-
remote_merge_from
(simNodeName, simQubitNum, localReg)[source]¶ Bring a remote register to this node.
Arguments simNodeName name of the node who simulates right now simQubitNum simulation number of qubit whose register we will merge localReg local register to merge with
-
remote_merge_regs
(num1, num2)[source]¶ Merges the two local quantum registers. Note that these register may simulate virtual qubits across different network nodes. This will ignore maxQubits and simply create one large register allowing twice maxQubits qubits.
Arguments num1 number of the first qubit num2 number of the second qubit
-
remote_new_qubit
(ignore_max_qubits=False)[source]¶ Create a new qubit in the default local register.
- Parameters
ignore_max_qubits – bool Used to ignore the check if max virtual qubits is reached. This is used when creating EPR pairs to be able to temporarily create a qubit.
-
remote_new_register
(maxQubits=10)[source]¶ Initialize a local register. Right now, this simple creates a register according to the simple engine backend using qubit.
Arguments: maxQubits maximum number of qubits to use in the default engine (default 10)
-
remote_remove_sim_qubit_num
(delNum)[source]¶ Removes the simulated qubit delQubit from the node and also from the underlying engine. Relies on this qubit having been locked.
Arguments delNum simID of the simulated qubit to delete
-
remote_send_qubit
(qubit, targetName)[source]¶ Sends the qubit to the specified target node. This creates a new virtual qubit object at the remote node with the right qubit and backend details.
Arguments qubit virtual qubit to be sent targetName target ndoe to place qubit at (host object)
-
remote_transfer_qubit
(simQubitNum, targetName)[source]¶ Transfer the qubit to the destination node if we are the simulating node. The reason why we cannot do this directly is that Twisted PB does not allow objects to be passed between connecting nodes. Only between the creator of the object and its immediate connections.
Arguments simQubitNum simulated qubit number to be sent targetName target node to place qubit at (host object)
-
remote_unlock_reg_qubits
(qubitNum)[source]¶ Release the lock on all qubits in the same register as qubitNum.
-
remote_update_virtual_merge
(newSimNodeName, oldSimNodeName, oldRegNum, newD)[source]¶ Update the virtual qubits to the new simulating node, if applicable. This is extremely inefficient due to not keeping register information in virtualQubit.
Arguments newSimNodeName new node simulating this qubit oldSimNodeName old node simulating the qubit oldReg old register newD dictionary mapping qubit numbers to qubit objects at the new simulating node
-
-
class
simulaqron.virtNode.virtual.
virtualQubit
(virtNode, simNode, simQubit, num)[source]¶ Bases:
twisted.spread.flavors.Referenceable
-
remote_apply_rotation
(n, a)[source]¶ Apply rotation around axis n with angle a. Arguments: n A tuple of three numbers specifying the rotation axis, e.g n=(1,0,0) a The rotation angle in radians.
-
remote_cnot_onto
(target)[source]¶ Performs a CNOT operation with this qubit as control, and the other qubit as target.
Arguments target the virtual qubit to use as the target of the CNOT
-
remote_cphase_onto
(target)[source]¶ Performs a CPHASE operation with this qubit as control, and the other qubit as target.
Arguments target the virtual qubit to use as the target of the CPHASE
-
remote_get_number
()[source]¶ Returns the number of this qubit in whatever local register it is in. Not useful for the client, but convenient for debugging.
-