simulaqron.virt_node package

Submodules

simulaqron.virtual_node.basics module

exception simulaqron.virtual_node.basics.NoQubitError(value)[source]

Bases: QuantumError

class simulaqron.virtual_node.basics.QuantumEngine(node: str, num: int, maxQubits: int = 10)[source]

Bases: Referenceable, ABC

Basic quantum engine. Abstract class meant to be subclassed to implement different simulation backends.

Initialize the simple engine.

Parameters:
  • node (str) – Node name this register is started from.

  • num (int) – Number of this register.

  • maxQubits (int) – maximum number of qubits this register supports. If not give, it will default to 10.

abstract absorb(other)[source]

Absorb the qubits from the other engine into this one. This is done by tensoring the state at the end.

Parameters:

other (int) – The other qubit to absorb.

Return type:

None

abstract absorb_parts(R, I, activeQ)[source]

Absorb the qubits, given in pieces

Parameters:
  • R (List[float]) – Real part of the qubit state as a list.

  • I (List[float]) – Imaginary part as a list.

  • activeQ – Active number of qubits

Return type:

None

abstract add_fresh_qubit() int[source]

Add a new qubit initialized in the \(|0>\) state.

Returns:

The qubit number

Return type:

int

abstract add_qubit(newQubit) int[source]

Add new qubit in the state described by the density matrix newQubit

Parameters:

newQubit (Any) – The new qubit state

Returns:

The qubit number

Return type:

int

abstract apply_CNOT(qubitNum1, qubitNum2)[source]

Applies the CNOT to the qubit with the numbers qubitNum1 and qubitNum2.

Parameters:
  • qubitNum1 (int) – Qubit number 1

  • qubitNum2 (int) – Qubit number 2

Return type:

None

abstract apply_CPHASE(qubitNum1, qubitNum2)[source]

Applies the CPHASE to the qubit with the numbers qubitNum1 and qubitNum2.

Parameters:
  • qubitNum1 (int) – Qubit number 1

  • qubitNum2 (int) – Qubit number 2

Return type:

None

abstract apply_H(qubitNum)[source]

Applies a Hadamard gate to the qubits with number qubitNum.

Parameters:

qubitNum (int) – Qubit number

Return type:

None

abstract apply_K(qubitNum)[source]

Applies a K gate to the qubits with number qubitNum. Maps computational basis to Y eigenbasis.

Parameters:

qubitNum (int) – Qubit number

Return type:

None

abstract apply_T(qubitNum)[source]

Applies a T gate to the qubits with number qubitNum.

Parameters:

qubitNum (int) – Qubit number

Return type:

None

abstract apply_X(qubitNum)[source]

Applies an X gate to the qubits with number qubitNum.

Parameters:

qubitNum (int) – Qubit number

Return type:

None

abstract apply_Y(qubitNum)[source]

Applies a Y gate to the qubits with number qubitNum.

Parameters:

qubitNum (int) – Qubit number

Return type:

None

abstract apply_Z(qubitNum)[source]

Applies a Z gate to the qubits with number qubitNum.

Parameters:

qubitNum (int) – Qubit number

Return type:

None

abstract apply_onequbit_gate(gateU, qubitNum)[source]

Applies a unitary gate to the specified qubit.

Parameters:
  • gateU (Qobj) – Unitary to apply as Qobj

  • qubitNum (int) – The number of the qubit this gate is applied to

Return type:

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[int, int, int]) – 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.

Parameters:
  • gateU (Qobj) – Unitary to apply as Qobj

  • qubit1 (int) – The first qubit

  • qubit2 (int) – The second qubit

Return type:

None

abstract get_density_matrix_RI()[source]

Retrieves the entire register in real and imaginary parts and returns the result of the outer product. In other words, if the qubit is in state \(|q>\), this function returns the density matrix \(|q><q|\) of the qubit.

Returns:

The density matrix real and imaginary parts of a qubit state

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.

Parameters:

qubitNum (int) – Qubit to be measured

Returns:

The measurement outcome

Return type:

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.

Parameters:

qubitNum (int) – Qubit to be measured

Returns:

The measurement outcome

Return type:

int

abstract remove_qubit(qubitNum: int) None[source]

Removes the qubit with the desired number qubitNum

Parameters:

qubitNum (int) – Qubit number

Return type:

None

abstract replace_qubit(qubitNum, state)[source]

Replaces the qubit at position qubitNum with the one given by state.

Parameters:
  • qubitNum (int) – Qubit to be replaced

  • state (Any) – New state to write in the place of the old qubit.

Return type:

None

exception simulaqron.virtual_node.basics.QuantumError(value)[source]

Bases: Error

exception simulaqron.virtual_node.basics.VirtNetError(value)[source]

Bases: Exception

simulaqron.virtual_node.project_q_simulator module

class simulaqron.virtual_node.project_q_simulator.ProjectQEngine(node: str, num: int, maxQubits: int = 10)[source]

Bases: QuantumEngine

Basic quantum engine which uses ProjectQ.

Initialize the ProjectQ engine.

Parameters:
  • node (str) – Node name this register is started from.

  • num (int) – Number of this register.

  • maxQubits (int) – 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.

Parameters:

other (int) – The other qubit to absorb.

absorb_parts(R, I, activeQ)[source]

Absorb the qubits, given in pieces

Parameters:
  • R (List[float]) – Real part of the qubit state as a list.

  • I (List[float]) – Imaginary part as a list.

  • activeQ – Active number of qubits

add_fresh_qubit() int[source]

Add a new qubit initialized in the \(|0>\) state.

Returns:

The ID of the new qubit allocated.

Return type:

int

add_qubit(newQubit)[source]

Add new qubit in the state described by the vector newQubit ([a, b])

Parameters:

newQubit – The density matrix of the new qubit.

Returns:

The ID of the new qubit allocated.

Return type:

int

apply_CNOT(qubitNum1, qubitNum2)[source]

Applies the CNOT to the qubit with the numbers qubitNum1 and qubitNum2.

Parameters:
  • qubitNum1 (int) – Qubit number 1.

  • qubitNum1 – Qubit number 2.

apply_CPHASE(qubitNum1, qubitNum2)[source]

Applies the CPHASE to the qubit with the numbers qubitNum1 and qubitNum2.

Parameters:
  • qubitNum1 (int) – Qubit number 1.

  • qubitNum1 – Qubit number 2.

apply_H(qubitNum)[source]

Applies a Hadamard gate to the qubits with number qubitNum.

Parameters:

qubitNum (int) – Qubit number

apply_K(qubitNum)[source]

Applies a K gate to the qubits with number qubitNum. Maps computational basis to Y eigenbasis.

Parameters:

qubitNum (int) – Qubit number

apply_T(qubitNum)[source]

Applies a T gate to the qubits with number qubitNum.

Parameters:

qubitNum (int) – Qubit number

apply_X(qubitNum)[source]

Applies a X gate to the qubits with number qubitNum.

Parameters:

qubitNum (int) – Qubit number

apply_Y(qubitNum)[source]

Applies a Y gate to the qubits with number qubitNum.

Parameters:

qubitNum (int) – Qubit number

apply_Z(qubitNum)[source]

Applies a Z gate to the qubits with number qubitNum.

Parameters:

qubitNum (int) – Qubit number

apply_onequbit_gate(gate, qubitNum: int)[source]

Applies a unitary gate to the specified qubit.

Parameters:
  • gate – The project Q gate to be applied.

  • qubitNum (int) – The number of the qubit this gate is applied to.

apply_rotation(qubitNum: int, n: Tuple[float, float, float], a: float)[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[float, float, float]) – 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: int, qubit2: int)[source]

Applies a unitary gate to the two specified qubits.

Arguments: :param gate: The project Q gate to be applied :param qubit1: The first qubit :type qubit1: int :param qubit2: The second qubit :type qubit2: int

get_density_matrix_RI() Tuple[List[float], List[float]][source]

Retrieves the density matrix of the qubit as a real and imaginary part. Twisted only likes to send real valued lists, not complex ones.

Returns:

The qubit density matrix real and imaginary parts.

Return type:

Tuple[List[float], List[float]]

get_register_RI() Tuple[Dict[int, int], Tuple[Tuple[float, ...], Tuple[float, ...]]][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.

Returns:

The qubit states real and imaginary parts.

Return type:

Tuple[Tuple[float, …], Tuple[float, …]]

measure_qubit(qubitNum: int)[source]

Measures the desired qubit in the standard basis. This returns the classical outcome and deletes the qubit.

Parameters:

qubitNum (int) – The number of the qubit to measure.

measure_qubit_inplace(qubitNum: int)[source]

Measures the desired qubit in the standard basis. This returns the classical outcome. The quantum register is in the post-measurement state corresponding to the obtained outcome.

Parameters:

qubitNum (int) – The number of the qubit to measure.

remove_qubit(qubitNum)[source]

Removes the qubit with the desired number qubitNum

Parameters:

qubitNum (int) – Qubit number

replace_qubit(qubitNum: int, state)[source]

Replaces the qubit at position qubitNum with the one given by state.

Parameters:
  • qubitNum (int) – Qubit to be replaced

  • state (Any) – New state to write in the place of the old qubit.

simulaqron.virtual_node.quantum module

class simulaqron.virtual_node.quantum.SimulatedQubit(node: Host, register: QuantumEngine, simNum: int, num: int = 0)[source]

Bases: Referenceable

Simulated qubit object in the specified local simulation engine.

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.

Creates a new simulated qubit object in the local simulation engine.

Parameters:
  • node (Host) – Network node that this qubit lives at.

  • register (QuantumEngine) – Register on that node that the qubit is in.

  • simNum (int) – The number of the simulated qubit. This value is unique at each virtual node.

  • num (int) – Number in the register.

isLocked()[source]
lock()[source]
make_fresh()[source]

Make this a fresh qubit.

remote_apply_H()[source]

Apply H gate.

remote_apply_K()[source]

Apply K gate to itself by passing it onto the underlying register. Maps computational to Y eigenbasis.

remote_apply_T()[source]

Apply T gate.

remote_apply_X()[source]

Apply X gate to itself by passing it onto the underlying register.

remote_apply_Y()[source]

Apply Y gate.

remote_apply_Z()[source]

Apply Z gate.

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.

Parameters:

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.

Parameters:

targetNum – the qubit to use as the target of the CPHASE

remote_get_density_matrix_RI()[source]

Returns the matrix density as per the internal state of the qubit.

remote_get_details()[source]

Returns out simulation number as well as the details of this simulating node.

remote_get_number()[source]

Returns the local number of this qubit.

remote_get_numbers()[source]

Returns the number of the simulating register.

remote_get_qubit()[source]

Returns the state of the qubits in the list qList by tracing out the rest.

remote_get_register()[source]

Returns the register where this qubit is simulated.

remote_get_register_RI()[source]

Returns the register where this qubit is simulated.

remote_get_sim_number()[source]

Returns the simulation number of this qubit.

remote_isActive()[source]
remote_isLocked()[source]
remote_lock()[source]
remote_measure()[source]

Measure the qubit in the standard basis. This does delete the qubit.

Returns:

The measurement outcome.

remote_measure_inplace()[source]

Measure the qubit in the standard basis. This does NOT delete the qubit, but replace the relevant qubit with the measurement outcome.

Returns:

The measurement outcome.

remote_unlock()[source]
unlock()[source]

simulaqron.virtual_node.qutip_simulator module

class simulaqron.virtual_node.qutip_simulator.QutipEngine(node: str, num: int, maxQubits: int = 10)[source]

Bases: 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.

Initializes the Qutip engine.

Parameters:
  • node (str) – Node name this register is started from.

  • num (int) – Number of this register.

  • maxQubits (int) – 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.

Parameters:

other (int) – The other qubit to absorb.

absorb_parts(R, I, activeQ)[source]

Absorb the qubits, given in pieces

Parameters:
  • R (List[float]) – Real part of the qubit state as a list.

  • I (List[float]) – Imaginary part as a list.

  • activeQ – Active number of qubits

add_fresh_qubit() int[source]

Add a new qubit initialized in the \(|0>\) state.

Returns:

The ID of the new qubit allocated.

Return type:

int

add_qubit(newQubit)[source]

Add new qubit in the state described by the density matrix newQubit.

Parameters:

newQubit – The density matrix of the new qubit.

Returns:

The ID of the new qubit allocated.

Return type:

int

apply_CNOT(qubitNum1: int, qubitNum2: int)[source]

Applies the CNOT to the qubit with the numbers qubitNum1 and qubitNum2.

Parameters:
  • qubitNum1 (int) – Qubit number 1.

  • qubitNum1 – Qubit number 2.

apply_CPHASE(qubitNum1, qubitNum2)[source]

Applies the CPHASE to the qubit with the numbers qubitNum1 and qubitNum2.

Parameters:
  • qubitNum1 (int) – Qubit number 1.

  • qubitNum1 – Qubit number 2.

apply_H(qubitNum)[source]

Applies a Hadamard gate to the qubits with number qubitNum.

Parameters:

qubitNum (int) – Qubit number

apply_K(qubitNum)[source]

Applies a K gate to the qubits with number qubitNum. Maps computational basis to Y eigenbasis.

Parameters:

qubitNum (int) – Qubit number

apply_T(qubitNum)[source]

Applies a T gate to the qubits with number qubitNum.

Parameters:

qubitNum (int) – Qubit number

apply_X(qubitNum)[source]

Applies a X gate to the qubits with number qubitNum.

Parameters:

qubitNum (int) – Qubit number

apply_Y(qubitNum)[source]

Applies a Y gate to the qubits with number qubitNum.

Parameters:

qubitNum (int) – Qubit number

apply_Z(qubitNum)[source]

Applies a Z gate to the qubits with number qubitNum.

Parameters:

qubitNum (int) – Qubit number

apply_onequbit_gate(gateU: Qobj, qubitNum: int)[source]

Applies a unitary gate to the specified qubit.

Parameters:
  • gateU (Qobj) – Unitary to apply as Qobj.

  • qubitNum (int) – 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[float, float, float]) – 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(gateU: Qobj, qubit1: int, qubit2: int)[source]

Applies a unitary gate to the two specified qubits.

Parameters:
  • gateU (Qobj) – Unitary to apply as Qobj.

  • qubit1 (int) – The first qubit

  • qubit2 (int) – The second qubit

get_density_matrix_RI() Tuple[Tuple[float], Tuple[float]][source]

Retrieves the density matrix of the qubit as a real and imaginary part. Twisted only likes to send real valued lists, not complex ones.

Returns:

The qubit density matrix real and imaginary parts.

Return type:

Tuple[List[float], List[float]]

get_qubits(list: List[int])[source]

Returns the qubits with numbers in list.

Parameters:

list (List[int]) – List of qubits to retrieve.

get_qubits_RI(qList: List[int]) Tuple[List[float], List[float]][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.

Parameters:

qList (List[int]) – List of qubits to retrieve, e.g. [1, 4]

Returns:

The qubits states real and imaginary parts.

Return type:

Tuple[List[float], List[float]]

get_register_RI() Tuple[List[float], List[float]][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.

Returns:

The qubit states real and imaginary parts.

Return type:

Tuple[List[float], List[float]]

measure_qubit(qubitNum: int)[source]

Measures the desired qubit in the standard basis. This returns the classical outcome and deletes the qubit.

Parameters:

qubitNum (int) – The number of the qubit to measure.

measure_qubit_inplace(qubitNum: int)[source]

Measures the desired qubit in the standard basis. This returns the classical outcome. The quantum register is in the post-measurement state corresponding to the obtained outcome.

Parameters:

qubitNum (int) – The number of the qubit to measure.

remove_qubit(qubitNum: int)[source]

Removes the qubit with the desired number qubitNum.

Parameters:

qubitNum (int) – Qubit number

replace_qubit(qubitNum: int, state)[source]

Replaces the qubit at position qubitNum with the one given by state.

Parameters:
  • qubitNum (int) – Qubit to be replaced

  • state (Any) – New state to write in the place of the old qubit.

simulaqron.virtual_node.stabilizer_simulator module

class simulaqron.virtual_node.stabilizer_simulator.StabilizerEngine(node: str, num: int, maxQubits: int = 10)[source]

Bases: QuantumEngine

Basic quantum engine which uses stabilizer formalism. Thus, only Clifford operations can be performed

Initialize the stabilizer engine.

Parameters:
  • node (str) – Node name this register is started from.

  • num (int) – Number of this register.

  • maxQubits (int) – 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.

Parameters:

other (int) – The other qubit to absorb.

absorb_parts(R, I, activeQ)[source]

Absorb the qubits, given in pieces

Parameters:
  • R (List[float]) – Real part of the qubit state as a list.

  • I (List[float]) – Unused.

  • activeQ – Active number of qubits

property activeQubits
add_fresh_qubit() int[source]

Add a new qubit initialized in the \(|0>\) state.

Returns:

The ID of the new qubit allocated.

Return type:

int

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.

Parameters:

newQubit – The density matrix of the new qubit.

Returns:

The ID of the new qubit allocated.

Return type:

int

apply_CNOT(qubitNum1, qubitNum2)[source]

Applies the CNOT to the qubit with the numbers qubitNum1 and qubitNum2.

Parameters:
  • qubitNum1 (int) – Qubit number 1.

  • qubitNum1 – Qubit number 2.

apply_CPHASE(qubitNum1, qubitNum2)[source]

Applies the CPHASE to the qubit with the numbers qubitNum1 and qubitNum2.

Parameters:
  • qubitNum1 (int) – Qubit number 1.

  • qubitNum1 – Qubit number 2.

apply_H(qubitNum)[source]

Applies a Hadamard gate to the qubits with number qubitNum.

Parameters:

qubitNum (int) – Qubit number

apply_K(qubitNum)[source]

Applies a K gate to the qubits with number qubitNum. Maps computational basis to Y eigenbasis.

Parameters:

qubitNum (int) – Qubit number

apply_T(qubitNum)[source]

Applies a T gate to the qubits with number qubitNum.

Parameters:

qubitNum (int) – Qubit number

apply_X(qubitNum)[source]

Applies a X gate to the qubits with number qubitNum.

Parameters:

qubitNum (int) – Qubit number

apply_Y(qubitNum)[source]

Applies a Y gate to the qubits with number qubitNum.

Parameters:

qubitNum (int) – Qubit number

apply_Z(qubitNum)[source]

Applies a Z gate to the qubits with number qubitNum.

Parameters:

qubitNum (int) – Qubit number

apply_onequbit_gate(gate, qubitNum)[source]

Applies a unitary gate to the specified qubit.

..warning:: This method is unsupported in the Stabilizer engine.

Invoking it will raise SimUnsupportedError.

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[float, float, float]) – 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.

..warning:: This method is unsupported in the Stabilizer engine.

Invoking it will raise SimUnsupportedError.

get_density_matrix_RI() Tuple[Tuple[float], Tuple[float]][source]

Retrieves the density matrix of the qubit as a real and imaginary part. Twisted only likes to send real valued lists, not complex ones.

Returns:

The qubit density matrix real and imaginary parts.

Return type:

Tuple[List[float], List[float]]

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

Returns:

The qubit states real and imaginary parts.

Return type:

Tuple[List[float], List[float]]

measure_qubit(qubitNum: int)[source]

Measures the desired qubit in the standard basis. This returns the classical outcome and deletes the qubit.

Parameters:

qubitNum (int) – The number of the qubit to measure.

measure_qubit_inplace(qubitNum: int)[source]

Measures the desired qubit in the standard basis. This returns the classical outcome. The quantum register is in the post-measurement state corresponding to the obtained outcome.

Parameters:

qubitNum (int) – The number of the qubit to measure.

remove_qubit(qubitNum)[source]

Removes the qubit with the desired number qubitNum

Parameters:

qubitNum (int) – Qubit number

replace_qubit(qubitNum: int, state)[source]

Replaces the qubit at position qubitNum with the one given by state.

..warning:: This method is unsupported in the Stabilizer engine.

Invoking it will raise SimUnsupportedError.

simulaqron.virtual_node.virtual module

class simulaqron.virtual_node.virtual.Backend(name: str, nodes_running: List[str], network_name: str)[source]

Bases: object

Create the Virtual Node backend. This will read the networks configuration and populate the name,hostname,port information with the information found in the configuration file for the given name.

Parameters:
  • name (str) – Node name to start.

  • nodes_running (List[str]) – List of nodes currently running.

  • network_name (str) – Name of the network to start.

start(max_qubits: int = 20, max_registers: int = 1000)[source]

Start listening to requests from other nodes.

Parameters:
  • max_qubits (int) – Maximum qubits in the default register.

  • max_registers (int) – Maximum number of registers in the default register.

class simulaqron.virtual_node.virtual.QubitNetQASM(fromName, toName, from_epr_socket_id, to_epr_socket_id, new_virt_num=None, rawEntInfo=None)[source]

Bases: object

class simulaqron.virtual_node.virtual.VirtualNode(ID: Host, config: SocketsConfig, maxQubits: int = 20, maxRegisters: int = 1000)[source]

Bases: Root

Initialize storing also our own name, hostname and port.

Parameters:
  • ID – Host identifier of this node

  • maxQubits (int) – Maximum number of qubits to use in the default engine (default 10)

  • maxRegisters (int) – Maximum number of registers

connectNet()[source]

Initialize the connections to the other virtual nodes in the network according to the available configuration.

connect_to_node(node: Host)[source]

Connects to other node. If node not up yet, waits for conn_retry_time seconds as configured in the simulaqron_settings.json file.

Parameters:

node (Host) – The node to connect to.

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.

Parameters:

name (str) – The name of the node connection to retrieve.

get_new_reg_num()[source]

Returns an unused register number.

handle_connection(obj, node: Host)[source]

Callback obtaining twisted root object when connection to the node given by the node details ‘node’.

Parameters:
  • obj – Twisted root object.

  • node (Host) – The node that was connected to.

handle_connection_error(reason, node: Host)[source]

Handles errors from trying to connect to other node. If a ConnectionRefusedError is raised another try will be made after conn_retry_time` seconds as configured in the simulaqron_settings.json file. Any other error is raised again.

local_merge_regs(qubit1: SimulatedQubit, 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.

Parameters:
remote_add_qubit(name: str, simQubit: SimulatedQubit)[source]

Add a qubit to the local virtual node.

Parameters:
  • name (str) – Name of the node simulating this qubit

  • simQubit (SimulatedQubit) – Simulated qubit reference in the backend we’re adding

remote_add_register(maxQubits: int = 10)[source]

Adds a new register to the node.

Parameters:

maxQubits (int) – Maximum number of qubits to use in the default engine

remote_check_connections()[source]

Checks if all connections are up.

remote_clear_recv_queues()[source]

Clear pending receive queues when an app disconnects

remote_delete_register(reg)[source]

Removes the register from the node. Happens if the last qubit in the register is measured out.

remote_get_global_lock()[source]
remote_get_multiple_qubits(qList: List[SimulatedQubit])[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.

Parameters:

qList (List[SimulatedQubit]) – List of virtual qubits of which to retrieve the state

remote_get_register(qubit)[source]

Return the value of a locally simulated register which contains this virtual qubit.

Parameters:

qubit – Qubit object to get the register from.

remote_get_register_RI(qubit)[source]

Return the real and imaginary part of the (possibly remote) simulated register which contains this virtual qubit.

Parameters:

qubit – Qubit object to get the register from.

remote_get_register_del(qubitNum: int)[source]

Return the value of a locally simulated register, and remove the simulated qubits from this node.

Caution

virtual qubits not updated.

Parameters:

qubitNum (int) – Qubit number to get the register from and remove.

remote_get_state(simNumList: List[int])[source]

Return the state of multiple qubits corresponding to the IDs in simNumList.

Parameters:

simNumList (List[int]) – List of simulated qubit numbers.

remote_get_virtual_ref(num: int)[source]

Return a virtual qubit object for the given number.

Parameters:

num (int) – Number of the virtual qubit

remote_isLocked()[source]
remote_lock_reg_qubits(qubitNum: int)[source]

Acquire the lock on all qubits in the same register as qubitNum.

Parameters:

qubitNum – The qubit number to lock.

remote_merge_from(simNodeName: str, simQubitNum: int, localReg)[source]

Bring a remote register to this node.

Parameters:
  • simNodeName (str) – Name of the node who simulates right now

  • simQubitNum (int) – Simulation number of qubit whose register we will merge

  • localReg – Local register to merge with

remote_merge_regs(num1: int, num2: int)[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.

Parameters:
  • num1 – Number of the first qubit

  • num2 – Number of the second qubit

remote_netqasm_add_epr_list(fromName, from_epr_socket_id, to_epr_socket_id, new_virt_num, rawEntInfo)[source]

Add an item to the epr list for use in NetQASM.

Parameters:
  • fromName (str) – Name of the node to receive the qubit.

  • from_epr_socket_id (int) – EPR socket ID

  • to_epr_socket_id (int) – EPR socket ID

  • new_virt_num (int) – New virtual qubit number

  • rawEntInfo – Entanglement information

remote_netqasm_add_recv_list(fromName, from_epr_socket_id: int, to_epr_socket_id: int, new_virt_num=None)[source]

Add an item to the received list for use in NetQASM.

Parameters:
  • fromName (str) – Name of the node to receive the qubit.

  • from_epr_socket_id (int) – EPR socket ID

  • to_epr_socket_id (int) – EPR socket ID

  • new_virt_num (int) – New virtual qubit number

remote_netqasm_get_epr_recv(to_epr_socket_id: int)[source]

Retrieve the next qubit (half of an EPR-pair) with the given app ID from the received list.

Parameters:

to_epr_socket_id (int) – EPR socket ID

remote_netqasm_get_recv(to_epr_socket_id)[source]

Retrieve the next qubit with the given app ID form the received list.

Parameters:

to_epr_socket_id (int) – EPR socket ID

remote_netqasm_send_epr_half(num: int, targetName: str, app_id: int, remote_app_id: int, rawEntInfo)[source]

Send interface for NetQASM to add the qubit to the remote nodes received list for an application.

Parameters:
  • num (int) – Number of virtual qubit to send

  • targetName (str) – Name of the node to send to

  • app_id (int) – Application asking to have this qubit delivered

  • remote_app_id (int) – Application ID to deliver the qubit to

  • rawEntInfo – Entanglement information

remote_netqasm_send_qubit(num: int, targetName: str, app_id: int, remote_app_id: int)[source]

Send interface for NetQASM to add the qubit to the remote nodes received list for an application.

Parameters:
  • num (int) – Number of virtual qubit to send

  • targetName (str) – Name of the node to send to

  • app_id (int) – Application asking to have this qubit delivered

  • remote_app_id (int) – Application ID to deliver the qubit to

remote_new_qubit(ignore_max_qubits: bool = 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_qubit_inreg(reg)[source]

Create a new qubit in the specified register reg.

remote_new_register(maxQubits: int = 10)[source]

Initialize a local register. Right now, this simple creates a register according to the simple engine backend using qubit.

Parameters:

maxQubits (int) – Maximum number of qubits to use in the default engine (default 10)

remote_release_global_lock()[source]
remote_remove_sim_qubit_num(delNum: int)[source]

Removes the simulated qubit delQubit from the node and also from the underlying engine. Relies on this qubit having been locked.

Parameters:

delNum (int) – simID of the simulated qubit to delete

remote_send_qubit(qubit: int, targetName: Host)[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.

Parameters:
  • qubit (int) – Virtual qubit to be sent

  • targetName (Host) – Target node to place qubit at.

remote_sim_qubit_num_in_same_reg(sim_qubit_num1: int, sim_qubit_num2: int)[source]

Checks if two qubits are in the same register

Parameters:
  • sim_qubit_num1 (int) – Qubit number 1.

  • sim_qubit_num2 (int) – Qubit number 2.

remote_stop_vnode()[source]
remote_transfer_qubit(simQubitNum: int, targetName: Host)[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.

Parameters:
  • simQubitNum (int) – Simulated qubit number to be sent

  • targetName (Host) – Target node to place qubit at (host object)

remote_unlock_reg_qubits(qubitNum: int)[source]

Release the lock on all qubits in the same register as qubitNum.

Parameters:

qubitNum – The qubit number on which to lock all qubits.

remote_update_virtual_merge(newSimNodeName: str, oldSimNodeName: str, oldRegNum: int, 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.

Parameters:
  • newSimNodeName (str) – New node simulating this qubit

  • oldSimNodeName (str) – Old node simulating the qubit

  • oldRegNum (int) – Old register number

  • newD – Dictionary mapping qubit numbers to qubit objects at the new simulating node.

class simulaqron.virtual_node.virtual.VirtualQubit(virtNode: Host, simNode: Host, simQubit: SimulatedQubit, num: int)[source]

Bases: Referenceable

Creates a virtual qubit object simulated in the specified simulation register backend

Parameters:
  • virtNode (Host) – Node where this qubit is virtually located

  • simNode (Host) – Node where this qubit is simulated

  • simQubit (SimulatedQubit) – Reference to the underlying qubit object (it can be remote)

  • num (int) – Number ID among the virtual qubits

remote_apply_H()[source]

Apply H gate.

remote_apply_K()[source]

Apply K gate - taking computational basis to Y eigenbasis.

remote_apply_T()[source]

Apply T gate.

remote_apply_X()[source]

Apply X gate to itself by passing it onto the underlying register.

remote_apply_Y()[source]

Apply Y gate.

remote_apply_Z()[source]

Apply Z gate.

remote_apply_rotation(n: Tuple[int, int, int], a: float)[source]

Apply rotation around axis n with angle a.

Parameters:
  • n (Tuple[int, int, int]) – A tuple of three numbers specifying the rotation axis, e.g n=(1,0,0)

  • a (float) – The rotation angle in radians.

remote_cnot_onto(target: Self)[source]

Performs a CNOT operation with this qubit as control, and the other qubit as target.

Parameters:

target (VirtualQubit) – The virtual qubit to use as the target of the CNOT

remote_cphase_onto(target: Self)[source]

Performs a CPHASE operation with this qubit as control, and the other qubit as target.

Parameters:

target (VirtualQubit) – The virtual qubit to use as the target of the CPHASE

remote_get_density_matrix_RI() Generator[Deferred, Tuple[List[float], List[float]], Tuple[List[float], List[float]]][source]

Returns the density matrix of this qubit in real and imaginary parts separated.

Returns:

The density matrix decomposed in real and imaginary part.

Return type:

Tuple[List[float], List[float]], Tuple[List[float], List[float]]]

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.

Returns:

The number of qubits in the register where this qubit resides.

Return type:

int

remote_get_qubit()[source]

Returns the state of this qubit in real and imaginary parts separated. This is required single Twisted cannot natively transfer complex valued objects.

Returns:

The real and imaginary part of the state of this qubit.

Return type:

Tule[float, float]

remote_get_register_RI()[source]

Gets the register of this qubit as imaginary and real pars separated.

Returns:

The register of this qubit as imaginary and real pars separated.

Return type:

Tuple[List[float], List[float]]

remote_get_simNode()[source]

Returns the simNode of this virtual qubit

Returns:

the name of the simNode of this qubit.

Return type:

str

remote_get_virtNode()[source]

Returns the virtNode of this virtual qubit

Returns:

The name of the virtual node of this qubit.

Return type:

str

remote_get_virt_num()[source]

Returns the number of the virtual qubit.

Returns:

The number of the virtual qubit.

Return type:

int

remote_measure(inplace: bool = False)[source]

Measure the qubit in the standard basis. If inplace=False, this does delete the qubit from the simulation.

Parameters:

inplace (bool) – Whether to perform the measurement in place or not.

Returns:

The measurement outcome.

simulaqron.virtual_node.virtual.call_method(obj, method_name, *args, **kwargs)[source]

Convenience method to call a method on an object, or a remote reference to an object

Parameters:
  • obj (Any) – Object to call the method on.

  • method_name (str) – Name of the method to call.

  • args (Any) – Positional arguments to pass to the method.

  • kwargs (Any) – Keyword arguments to pass to the method.

simulaqron.virtual_node.virtual.reraise_remote_error(remote_err: RemoteError)[source]

This is a function re-raises the error thrown remotely

Parameters:

remote_errtwisted.spread.pb.RemoteError

Raises:

A python class that was encoded in the Error

Module contents