pythonLib¶
-
class
cqc.pythonLib.
CQCConnection
(name, socket_address=None, appID=None, pend_messages=False, retry_connection=True, conn_retry_time=0.1, log_level=None, backend=None, use_classical_communication=True, network_name=None)[source]¶ Handler to be used when sending commands over a socket.
-
__init__
(name, socket_address=None, appID=None, pend_messages=False, retry_connection=True, conn_retry_time=0.1, log_level=None, backend=None, use_classical_communication=True, network_name=None)[source]¶ Initialize a connection to the cqc server.
Since version 3.0.0: If socket_address is None or use_classical_communication is True, the CQC connection needs some way of finding the correct socket addresses. If backend is None or “simulaqron” the connection will try to make use of the network config file setup in simulaqron. If simulaqron is not installed
- Arguments
- param name
Name of the host.
- param socket_address
tuple (str, int) of ip and port number.
- param appID
Application ID. If set to None, defaults to a nonused ID.
- param pend_messages
True if you want to wait with sending messages to the back end. Use flush() to send all pending messages in one go as a sequence to the server
- param retry_connection
bool Whether to retry a failed connection or not
- param conn_retry_time
float How many seconds to wait between each connection retry
- param log_level
int or None The log-level, for example logging.DEBUG (default: logging.WARNING)
- param backend
None or str If socket_address is None or use_classical_communication is True, If None or “simulaqron” is used the cqc library tries to use the network config file setup in simulaqron if network_config_file is None. If network_config_file is None and simulaqron is not installed a ValueError is raised.
- param use_classical_communication
bool Whether to use the built-in classical communication or not.
- param network_name
None or str Used if simulaqron is used to load socket addresses for the backend
-
close
(release_qubits=True, notify=True)[source]¶ Handle closing actions.
Flushes remaining headers, releases all qubits, closes the connections, and removes the app ID from the used app IDs.
-
new_qubitID
(print_cqc=False)[source]¶ Provide new qubit ID.
For CQCConnection the qubit ID is given by the server. A message has to be read and the qubit ID extracted from it.
-
startClassicalServer
()[source]¶ Sets up a server for the application communication, if not already set up.
-
openClassicalChannel
(name)[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.
-
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.
-
sendClassical
(name, msg, close_after=True)[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.
-
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.
-
sendQubit
(q, name, remote_appID=0, notify=True, block=True, remote_socket=None)[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
- remote_socket
tuple (str, int) of ip and port number. Needed if no cqcFile was specified
-
createEPR
(name, remote_appID=0, notify=True, block=True, remote_socket=None)[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
- remote_socket
tuple (str, int) of ip and port number. Needed if no cqcFile was specified
-
-
class
cqc.pythonLib.
qubit
(cqc, notify=True, block=True, createNew=True, q_id=None, entInfo=None)[source]¶ A qubit.
-
__init__
(cqc, notify=True, block=True, createNew=True, q_id=None, entInfo=None)[source]¶ Initializes the qubit. The cqc connection must be given. If notify, the return message is received before the method finishes. createNew is set to False when we receive a qubit.
Arguments
- cqc
The CQCconnection used
- nofify
Do we wish to be notified when done.
- block
Do we want the qubit to be blocked
- createNew
If NEW-message should be sent, used internally
- q_id
Qubit id, used internally if createNew
- entInfo
Entanglement information, if qubit is part of EPR-pair
-
I
(notify=True, block=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
-
X
(notify=True, block=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
-
Y
(notify=True, block=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
-
Z
(notify=True, block=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
-
T
(notify=True, block=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
-
H
(notify=True, block=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
-
K
(notify=True, block=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
-
rot_X
(step, notify=True, block=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
-
rot_Y
(step, notify=True, block=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
-
rot_Z
(step, notify=True, block=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
-
cnot
(target, notify=True, block=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
-
cphase
(target, notify=True, block=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
-
measure
(inplace=False, block=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
-
reset
(notify=True, block=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
-
-
class
cqc.pythonLib.
CQCMix
(cqc_connection: cqc.pythonLib.cqc_mix.CQCMixConnection)[source]¶ This Python Context Manager Type can be used to create CQC programs that consist of more than a single type. Hence the name CQC Mix. Programs of this type can consist of any number and mix of the other CQC types.
-
__init__
(cqc_connection: cqc.pythonLib.cqc_mix.CQCMixConnection)[source]¶ Initializes the Mix context.
Arguments
- cqc_connection
The CQCConnection to which this CQC Program must be sent.
-
cqc_if
(logical_function: cqc.pythonLib.cqc_mix._LogicalFunction)[source]¶ Open a Python Context Manager Type to start an if-statement block.
Arguments
- logical_function
A _LogicalFunction instance. Never instantiate this explicitely; instead use the following: CQCVariable == 1 OR CQCVariable == CQCVariable. CQCVariable can be any instance that you want to test to a value, or to another CQCVariable. The operator can be == or !=. The value can be any integer (though only 1 and 0 make sense).
-