SimulaQron.cqc.pythonLib package¶
Subpackages¶
SimulaQron.cqc.pythonLib.cqc module¶
-
class
SimulaQron.cqc.pythonLib.cqc.
CQCConnection
(name, cqcFile=None, appFile=None, appID=0)[source]¶ Bases:
object
-
closeClassicalChannel
(name)[source]¶ Closes a classical connection to another host in the application network.
Arguments
name: The name of the host in the application network.
-
createEPR
(name, remote_appID=0, notify=True, block=True, print_info=True)[source]¶ Creates epr with other host in cqc network.
Arguments
name: Name of the node as specified in the cqc network config file. remote_appID: The app ID of the application running on the receiving node. nofify: Do we wish to be notified when done. block: Do we want the qubit to be blocked print_info: If info should be printed
-
openClassicalChannel
(name, timout=1)[source]¶ Opens a classical connection to another host in the application network.
Arguments
name: The name of the host in the application network. timout: The time to try to connect to the server. When timout is reached an RuntimeError is raised.
-
print_CQC_msg
(message)[source]¶ Prints messsage returned by the readMessage method of CQCConnection.
-
readMessage
(maxsize=192)[source]¶ Receive the whole message from cqc server. Returns (CQCHeader,None,None), (CQCHeader,CQCNotifyHeader,None) or (CQCHeader,CQCNotifyHeader,EntInfoHeader) depending on the type of message. Maxsize is the max size of message.
-
recvEPR
(notify=True, block=True, print_info=True)[source]¶ Receives a qubit from an EPR-pair generated with another node.
Arguments
nofify: Do we wish to be notified when done. block: Do we want the qubit to be blocked print_info: If info should be printed
-
recvQubit
(notify=True, block=True, print_info=True)[source]¶ Receives a qubit.
Arguments
q: The qubit to send. Name: Name of the node as specified in the cqc network config file. remote_appID: The app ID of the application running on the receiving node. nofify: Do we wish to be notified when done. block: Do we want the qubit to be blocked print_info: If info should be printed
-
sendClassical
(name, msg, timout=1)[source]¶ Sends a classical message to another host in the application network.
Arguments
name: The name of the host in the application network. msg: The message to send. Should be either a int in range(0,256) or a list of such ints. timout: The time to try to connect to the server. When timout is reached an RuntimeError is raised.
-
sendCmdXtra
(qID, command, notify=1, block=1, action=0, xtra_qID=0, step=0, remote_appID=0, remote_node=0, remote_port=0, cmd_length=0)[source]¶ Sends a simple message, command message and xtra message to the cqc server.
Arguments
qID: qubit ID command: Command to be executed, eg CQC_CMD_H nofify: Do we wish to be notified when done. block: Do we want the qubit to be blocked action: Are there more commands to be executed xtra_qID: Extra qubit ID for for example CNOT step: Defines the angle of rotation. remote_appID: Application ID of remote host remote_node: ip of remote host in cqc network remote_port: port of remote host in cqc network cmd_length: length of extra commands
-
sendCommand
(qID, command, notify=1, block=1, action=0)[source]¶ Sends a simple message and command message to the cqc server.
Arguments
qID: qubit ID command: Command to be executed, eg CQC_CMD_H nofify: Do we wish to be notified when done. block: Do we want the qubit to be blocked action: Are there more commands to be executed
-
sendFactory
(qID, command, num_iter, notify=1, block=1, action=0, xtra_qID=0, remote_appID=0, remote_node=0, remote_port=0, cmd_length=0)[source]¶ Sends a factory message
Arguments
qID: qubit ID command: Command to be executed, eg CQC_CMD_H num_iter: Number of times to execute command nofify: Do we wish to be notified when done. block: Do we want the qubit to be blocked action: Are there more commands to be executed xtra_qID: Extra qubit ID for for example CNOT remote_appID: Application ID of remote host remote_node: ip of remote host in cqc network remote_port: port of remote host in cqc network cmd_length: length of extra commands
-
sendGetTime
(qID, notify=1, block=1, action=0)[source]¶ Sends get-time message
Arguments
qID: qubit ID command: Command to be executed, eg CQC_CMD_H nofify: Do we wish to be notified when done. block: Do we want the qubit to be blocked action: Are there more commands to be executed
-
sendQubit
(q, name, remote_appID=0, notify=True, block=True, print_info=True)[source]¶ Sends qubit to another node in the cqc network. If this node is not in the network an error is raised.
Arguments
q: The qubit to send. Name: Name of the node as specified in the cqc network config file. remote_appID: The app ID of the application running on the receiving node. nofify: Do we wish to be notified when done. block: Do we want the qubit to be blocked
-
sendSimple
(tp)[source]¶ Sends a simple message to the cqc server, for example a HELLO message if tp=CQC_TP_HELLO.
-
startClassicalServer
()[source]¶ Sets up a server for the application communication, if not already set up.
-
test_preparation
(preparation, exp_values, conf=2, iterations=100, progress=True)[source]¶ Test the preparation of a qubit. Returns True if the expected values are inside the confidence interval produced from the data received from the tomography function
Arguments
preparation: A function that takes a CQCConnection as input and prepares a qubit and returns this (and preferably sets print_info=False) exp_values: The expected values for measurements in the X, Y and Z basis. conf: Determines the confidence region (+/- conf/sqrt(iterations) ) iterations: Number of measurements in each basis. progress_bar: Displays a progress bar
-
tomography
(preparation, iterations, progress=True)[source]¶ Does a tomography on the output from the preparation specified. The frequencies from X, Y and Z measurements are returned as a tuple (f_X,f_Y,f_Z).
Arguments
preparation: A function that takes a CQCConnection as input and prepares a qubit and returns this (and preferably sets print_info=False) iterations: Number of measurements in each basis. progress_bar: Displays a progress bar
-
-
class
SimulaQron.cqc.pythonLib.cqc.
qubit
(cqc, notify=True, block=True, print_info=True, createNew=True, q_id=None, entInfo=None)[source]¶ Bases:
object
A qubit.
-
H
(notify=True, block=True, print_info=True)[source]¶ Performs a Hadamard on the qubit. If notify, the return message is received before the method finishes.
Arguments
nofify: Do we wish to be notified when done. block: Do we want the qubit to be blocked print_info: If info should be printed
-
I
(notify=True, block=True, print_info=True)[source]¶ Performs an identity gate on the qubit. If notify, the return message is received before the method finishes.
Arguments
nofify: Do we wish to be notified when done. block: Do we want the qubit to be blocked print_info: If info should be printed
-
K
(notify=True, block=True, print_info=True)[source]¶ Performs a K gate on the qubit. If notify, the return message is received before the method finishes.
Arguments
nofify: Do we wish to be notified when done. block: Do we want the qubit to be blocked print_info: If info should be printed
-
T
(notify=True, block=True, print_info=True)[source]¶ Performs a T gate on the qubit. If notify, the return message is received before the method finishes.
Arguments
nofify: Do we wish to be notified when done. block: Do we want the qubit to be blocked print_info: If info should be printed
-
X
(notify=True, block=True, print_info=True)[source]¶ Performs a X on the qubit. If notify, the return message is received before the method finishes.
Arguments
nofify: Do we wish to be notified when done. block: Do we want the qubit to be blocked print_info: If info should be printed
-
Y
(notify=True, block=True, print_info=True)[source]¶ Performs a Y on the qubit. If notify, the return message is received before the method finishes.
Arguments
nofify: Do we wish to be notified when done. block: Do we want the qubit to be blocked print_info: If info should be printed
-
Z
(notify=True, block=True, print_info=True)[source]¶ Performs a Z on the qubit. If notify, the return message is received before the method finishes.
Arguments
nofify: Do we wish to be notified when done. block: Do we want the qubit to be blocked print_info: If info should be printed
-
cnot
(target, notify=True, block=True, print_info=True)[source]¶ Applies a cnot onto target. Target should be a qubit-object with the same cqc connection. If notify, the return message is received before the method finishes.
Arguments
target: The target qubit nofify: Do we wish to be notified when done. block: Do we want the qubit to be blocked print_info: If info should be printed
-
cphase
(target, notify=True, block=True, print_info=True)[source]¶ Applies a cphase onto target. Target should be a qubit-object with the same cqc connection. If notify, the return message is received before the method finishes.
Arguments
target: The target qubit nofify: Do we wish to be notified when done. block: Do we want the qubit to be blocked print_info: If info should be printed
-
getTime
(block=True, print_info=True)[source]¶ Returns the time information of the qubit. If now INF_TIME message is received, None is returned.
Arguments
block: Do we want the qubit to be blocked print_info: If info should be printed
-
measure
(inplace=False, block=True, print_info=True)[source]¶ Measures the qubit in the standard basis and returns the measurement outcome. If now MEASOUT message is received, None is returned. If inplace=False, the measurement is destructive and the qubit is removed from memory. If inplace=True, the qubit is left in the post-measurement state.
Arguments
inplace: If false, measure destructively. block: Do we want the qubit to be blocked print_info: If info should be printed
-
reset
(notify=True, block=True, print_info=True)[source]¶ Resets the qubit. If notify, the return message is received before the method finishes.
Arguments
nofify: Do we wish to be notified when done. block: Do we want the qubit to be blocked print_info: If info should be printed
-
rot_X
(step, notify=True, block=True, print_info=True)[source]¶ Applies rotation around the x-axis with the angle of step*2*pi/256 radians. If notify, the return message is received before the method finishes.
Arguments
step: Determines the rotation angle in steps of 2*pi/256 nofify: Do we wish to be notified when done. block: Do we want the qubit to be blocked print_info: If info should be printed
-
rot_Y
(step, notify=True, block=True, print_info=True)[source]¶ Applies rotation around the y-axis with the angle of step*2*pi/256 radians. If notify, the return message is received before the method finishes.
Arguments
step: Determines the rotation angle in steps of 2*pi/256 nofify: Do we wish to be notified when done. block: Do we want the qubit to be blocked print_info: If info should be printed
-
rot_Z
(step, notify=True, block=True, print_info=True)[source]¶ Applies rotation around the z-axis with the angle of step*2*pi/256 radians. If notify, the return message is received before the method finishes.
Arguments
step: Determines the rotation angle in steps of 2*pi/256 nofify: Do we wish to be notified when done. block: Do we want the qubit to be blocked print_info: If info should be printed
-