Qubit

The Qubit object is mainly a wrapper for the underlying qubit that is defined in the Backend. We add our own properties such that we can better manage the qubits in the system, for example, Qubits have a unique ID and they know which Host they belong to.

exception qunetsim.objects.qubit.InputError(message)

Bases: Exception

Exception raised for errors in the input.

expression -- input expression in which the error occurred
message -- explanation of the error
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

class qunetsim.objects.qubit.Qubit(host, qubit=None, q_id=None, blocked=False)

Bases: object

A Qubit object. It is a wrapper class of qubits of different backends, which adds additional information needed for QuNetSim.

H()

Perform a Hadamard gate on the qubit.

I()

Perform Identity operation on the qubit.

K()

Perform a K gate on the qubit.

T()

Perform a T gate on the qubit.

X()

Perform pauli x gate on qubit.

Y()

Perform pauli y gate on qubit.

Z()

Perform pauli z gate on qubit.

property blocked

Give the block state of the qubit.

Returns

If the qubit is blocked or not.

cnot(target)

Applies a controlled x gate to the target qubit.

Parameters

target (Qubit) – Qubit on which the cnot gate should be applied.

cphase(target)

Applies a controlled z gate to the target qubit.

Parameters

target (Qubit) – Qubit on which the cphase gate should be applied.

custom_controlled_gate(target, gate)

Applies a custom 2x2 unitary on the qubit.

Parameters
  • target (Qubit) – Qubit on which the controlled gate should be applied.

  • gate (Numpy ndarray) – A unitary 2x2 matrix

custom_gate(gate)

Applies a custom 2x2 unitary on the qubit.

Parameters

gate (Numpy ndarray) – A unitary 2x2 matrix

custom_two_qubit_control_gate(q1, q2, gate)

Applies the gate gate to qubits q1 and q2 as a controlled gate.

Parameters
  • q1 (Qubit) – First qubit

  • q2 (Qubit) – Second qubit

  • gate (Numpy ndarray) – The gate to apply

custom_two_qubit_gate(other_qubit, gate)

Applies a custom 2 qubit gate.

Parameters
  • other_qubit (Qubit) – The second qubit.

  • gate (Numpy ndarray) – The gate

density_operator()

Returns the density operator of this qubit. If the qubit is entangled, the density operator will be in a mixed state.

Returns

The density operator of the qubit.

Return type

np.ndarray

fidelity(other_qubit)

Determines the quantum fidelity between this and the given qubit.

Parameters

other_qubit (Qubit) – The other (apart from this) qubit used to calculate the quantum fidelity

Returns

(float) The quantum fidelity between this and the given qubit.

property host

Give the host of who the qubit belongs to.

Returns

Host of the qubit.

property id

Give the ID of the qubit.

Returns

Id of the qubit.

measure(non_destructive=False)

Measures the state of a qubit.

Parameters

non_destructive (bool) – Determines if the qubit should stay in the system or be eliminated.

Returns

0 or 1, dependent on measurement outcome.

Return type

measured_value (int)

property qubit

Return the physical qubit.

Returns

Return the physical qubit.

Return type

(backend.qubit) qubit

release()

Releases a qubit from the system.

rx(phi)

Perform a rotation pauli x gate with an angle of phi.

Parameters

phi (float) – Rotation in rad

ry(phi)

Perform a rotation pauli y gate with an angle of phi.

Parameters

phi (float) – Rotation in rad

rz(phi)

Perform a rotation pauli z gate with an angle of phi.

Parameters

phi (float) – Rotation in rad

send_to(receiver_id)

Sends the Qubit to another host.

Parameters

receiver_id (str) – ID of Host the qubit should be send to.