netqasm.sdk.toolbox

netqasm.sdk.toolbox.gates

netqasm.sdk.toolbox.gates.t_inverse(q)

Performs an inverse of the T gate by applying the T gate 7 times.

Parameters

q (Qubit) –

Return type

None

netqasm.sdk.toolbox.gates.toffoli_gate(control1, control2, target)

Performs a Toffoli gate with control1 and control2 as control qubits and target as target, using CNOTS, Ts and Hadamard gates.

See https://en.wikipedia.org/wiki/Toffoli_gate

Parameters
Return type

None

netqasm.sdk.toolbox.measurements

netqasm.sdk.toolbox.measurements.parity_meas(qubits, bases)

Performs a parity measurement on the provided qubits in the Pauli bases specified by ‘bases’. bases should be a string with letters in ‘IXYZ’ and optionally start with ‘-‘. If bases starts with ‘-‘, then the measurement outcome is flipped. The basis should have the same length as the number of qubits provided or +1 if starts with ‘-‘. If more than one letter of ‘bases’ is not identity, then an ancilla qubit will be used, which is created using the connection of the first qubit.

Parameters
  • qubits (List[Qubit]) – The qubits to measure

  • bases (str) – What parity meas to perform.

Returns

The measurement outcome

Return type

class:~.sdk.futures.Future

netqasm.sdk.toolbox.multi_node

netqasm.sdk.toolbox.multi_node.create_ghz(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 mutliples 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 intialises 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”. NOTE Both down_epr_socket and up_epr_socket cannot be None.

Parameters
  • down_epr_socket (sdk.epr_socket.esck.EPRSocket) – The esck.EPRSocket to be used for receiving EPR pairs from downstream.

  • up_epr_socket (sdk.epr_socket.esck.EPRSocket) – The esck.EPRSocket to be used for create EPR pairs upstream.

  • down_socket (sdk.classical_communication.socket.Socket) – The classical socket to be used for sending corrections, if do_corrections = True.

  • up_socket (sdk.classical_communication.socket.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.

Returns

Of the form (q, m) where q is the qubit part of the state and m is the measurement outcome.

Return type

tuple

netqasm.sdk.toolbox.sim_states

netqasm.sdk.toolbox.sim_states.qubit_from(phi, theta)

Only used for simulation output purposes. Uses the phi and theta angles to construct a NetSquid qubit.

Parameters
  • phi (float) –

  • theta (float) –

Return type

NetSquidQubit

netqasm.sdk.toolbox.sim_states.to_dm(q)

Only used for simulation output purposes.

Parameters

q (NetSquidQubit) –

Return type

np.ndarray

netqasm.sdk.toolbox.sim_states.get_fidelity(q1, q2)

Only used for simulation output purposes. Gets the fidelity between the states q1 and q2

Parameters
  • q1 (NetSquidQubit) –

  • q2 (np.ndarray) –

Return type

float

netqasm.sdk.toolbox.state_prep

netqasm.sdk.toolbox.state_prep.set_qubit_state(qubit, phi=0.0, theta=0.0)

Assuming that the qubit is in the state \(|0\rangle\), this function rotates the state to \(\cos(\theta / 2)|0\rangle + e^{i\phi}\sin(\theta / 2)|1\rangle\).

Parameters
  • qubit (sdk.qubit.Qubit) – The qubit to prepare the state.

  • phi (float) – Angle around Z-axis from X-axis

  • theta (float) – Angle from Z-axis

Return type

None

netqasm.sdk.toolbox.state_prep.get_angle_spec_from_float(angle, tol=0.0001)

Tries to find the shortest sequence of (n, d) such that \(abs(\sum_i n_i \pi / 2 ^ {d_i} - angle) < tol\) This is to find a sequence of rotations for a given angle.

Parameters
  • angle (float) – The angle to approximate

  • tol (float) – Tolerance to use

Return type

List[Tuple[int, int]]