Routines
- squidasm.util.routines.create_ghz(connection, down_epr_socket=None, up_epr_socket=None, down_socket=None, up_socket=None, do_corrections=False)
Local protocol to create a GHZ state between multiples nodes.
EPR pairs are generated in a line and turned into a GHZ state by performing half of a Bell measurement. That is, CNOT and H are applied but only the control qubit is measured. If do_corrections=False (default) this measurement outcome is returned along with the qubit to be able to know what corrections might need to be applied. If the node is at the start or end of the line, the measurement outcome 0 is always returned since there is no measurement performed. The measurement outcome indicates if the next node in the line should flip its qubit to get the standard GHZ state: \(|0\rangle^{\otimes n} + |1\rangle^{\otimes n}\).
On the other hand if do_corrections=True, then the classical sockets down_socket and/or up_socket will be used to communicate the outcomes and automatically perform the corrections.
Depending on if down_epr_socket and/or up_epr_socket is specified the node, either takes the role of the:
“start”, which initialises the process and creates an EPR with the next node using the up_epr_socket.
“middle”, which receives an EPR pair on the down_epr_socket and then creates one on the up_epr_socket.
“end”, which receives an EPR pair on the down_epr_socket.
Note
There has to be exactly one “start” and exactly one “end” but zero or more “middle”. Both down_epr_socket and up_epr_socket cannot be None.
- Parameters:
connection (
BaseNetQASMConnection) – The connection to the quantum node controller used for sending instructions.down_epr_socket (
Optional[EPRSocket]) – The EPRSocket to be used for receiving EPR pairs from downstream.up_epr_socket (
Optional[EPRSocket]) – The EPRSocket to be used for create EPR pairs upstream.down_socket (
Optional[Socket]) – The classical socket to be used for sending corrections, if do_corrections = True.up_socket (
Optional[Socket]) – The classical socket to be used for sending corrections, if do_corrections = True.do_corrections (
bool) – If corrections should be applied to make the GHZ in the standard form \(|0\rangle^{\otimes n} + |1\rangle^{\otimes n}\) or not.- Return type:
Generator[None,None,Tuple[Qubit,int]]- Returns:
Of the form (q, m) where q is the qubit part of the state and m is the measurement outcome.
- squidasm.util.routines.distributed_CNOT_control(context, peer_name, ctrl_qubit)
Performs the two qubit CNOT gate, but with the control qubit located on this node, the target on a remote node. The formal return is a generator and requires use of yield from in usage in order to function as intended.
- Parameters:
context (
ProgramContext) – context of the current programpeer_name (
str) – name of the peer engaging in this teleportation protocolctrl_qubit (
Qubit) – The control qubit. Will not be affected in an ideal scenario.- Return type:
Generator[None,None,None]
- squidasm.util.routines.distributed_CNOT_target(context, peer_name, target_qubit)
Performs the two qubit CNOT gate, but with the target qubit located on this node, the control on a remote node. The formal return is a generator and requires use of yield from in usage in order to function as intended.
- Parameters:
context (
ProgramContext) – context of the current programpeer_name (
str) – name of the peer engaging in this teleportation protocoltarget_qubit (
Qubit) – The target qubit. Will be operated on depending on the control qubit state.
- squidasm.util.routines.distributed_CPhase_control(context, peer_name, ctrl_qubit)
Performs the two qubit Cphase gate, but with the control qubit located on this node, the target on a remote node. The formal return is a generator and requires use of yield from in usage in order to function as intended.
- Parameters:
context (
ProgramContext) – context of the current programpeer_name (
str) – name of the peer engaging in this teleportation protocolctrl_qubit (
Qubit) – The control qubit. Will not be affected in an ideal scenario.- Return type:
Generator[None,None,None]
- squidasm.util.routines.distributed_CPhase_target(context, peer_name, target_qubit)
Performs the two qubit CNOT gate, but with the target qubit located on this node, the control on a remote node. The formal return is a generator and requires use of yield from in usage in order to function as intended.
- Parameters:
context (
ProgramContext) – context of the current programpeer_name (
str) – name of the peer engaging in this teleportation protocoltarget_qubit (
Qubit) – The target qubit. Will be operated on depending on the control qubit state.
- squidasm.util.routines.measXY(q, angle)
Measure qubit q in the basis spanned by |0> ± e^{i*angle} |1>. This is equivalent to doing a Z-rotation of angle, then a Hadamard, and measuring in the Z-basis. Note: we use the convention that we rotate by +`angle` (not -angle).
- squidasm.util.routines.recv_float(socket)
Receive a float
- Return type:
Generator[None,None,float]
- squidasm.util.routines.recv_int(socket)
Receive a float
- Return type:
Generator[None,None,int]
- squidasm.util.routines.recv_remote_state_preparation(epr_socket)
Let the client prepare a state on the server. The client will do a suitable measurement on her side.
- squidasm.util.routines.remote_state_preparation(epr_socket, theta)
Prepare a state \(R_z(theta)|+>\) to the server. The resulting state on the server’s side is actually \(R_z(theta + m*\pi) |+>\), for the client’s measurement outcome m.
- squidasm.util.routines.send_float(socket, phi)
Send a float
- squidasm.util.routines.send_int(socket, outcome)
Send a integer
- squidasm.util.routines.teleport_recv(context, peer_name)
Receiving routine of a teleportation protocol. Will return the teleported qubit. The formal return is a generator and requires use of yield from in usage in order to function as intended.
- Parameters:
context (
ProgramContext) – context of the current programpeer_name (
str) – name of the peer engaging in this teleportation protocol- Return type:
Generator[None,None,Qubit]- Returns:
Teleported qubit
- squidasm.util.routines.teleport_send(q, context, peer_name)
Sending routine of a teleportation protocol. The formal return is a generator and requires use of yield from in usage in order to function as intended.
- Parameters:
q (
Qubit) – Qubit to teleport. This qubit will be measured and ‘destroyed’.context (
ProgramContext) – context: context of the current programpeer_name (
str) – name of the peer engaging in this teleportation protocol- Return type:
Generator[None,None,None]
- class squidasm.util.qkd_routine.QKDRoutine
- classmethod run(context, peer_name, is_init, num_epr, num_test_bits=None)
Run the QKD routine. The routine will return a variable length raw key and the error rate estimation. The length of the variable key has an expectation value of num_epr/2 - num_tests_bits. The formal return is a generator and requires use of yield from in usage in order to function as intended.
- Parameters:
context (
ProgramContext) – context: context of the current programpeer_name (
str) – name of the peer engaging in this teleportation protocolis_init (
bool) – Flag to designate if this node started the protocol. The peer must use the opposite flag for this protocol to work.context – Local program context
num_epr (
int) – The number of EPR pairs to be generated.num_test_bits (
Optional[int]) – The amount of EPR pairs in the same basis to use from the raw key to use for the error estimation. The EPR pairs used for the error estimation are not used for the raw key.- Return type:
Generator[EventExpression,None,Tuple[bitarray,float]]- Returns:
A tuple with a bitarray containing the raw key and a float that is the error rate estimation.