Qubit
– Qubits and quantum systems¶
-
class
squanch.qubit.
QSystem
(num_qubits, index=None, state=None)[source]¶ Bases:
object
Represents a multi-body, maximally-entangleable quantum system. Contains references to constituent qubits and (if applicable) its parent
QStream
. Quantum state is represented as a density matrix in the computational basis.-
__init__
(num_qubits, index=None, state=None)[source]¶ Instatiate the quantum state for an n-qubit system
Parameters: - num_qubits (int) – number of qubits in the system, treated as maximally entangled
- index (int) – index of the QSystem within the parent QStream
- state (np.array) – density matrix representing the quantum state. By default, |000...0><0...000| is used
-
__weakref__
¶ list of weak references to the object (if defined)
-
apply
(operator)[source]¶ Apply an N-qubit unitary operator to this system’s N-qubit quantum state
Parameters: operator (np.array) – the unitary N-qubit operator to apply Returns: nothing, the qsystem state is mutated
-
classmethod
from_stream
(qstream, index)[source]¶ Instantiate a QSystem from a given index in a parent QStream
Parameters: - qstream (QStream) – the parent stream
- index (int) – the index in the parent stream corresponding to this system
Returns: the QSystem object
-
-
class
squanch.qubit.
Qubit
(qsystem, index)[source]¶ Bases:
object
A wrapper class representing a single qubit in an existing quantum system.
-
__init__
(qsystem, index)[source]¶ Instantiate the qubit from an existing QSystem and index
Parameters: - qsystem (QSystem) – n-qubit quantum system that this qubit points to
- index (int) – particle index in the quantum system, ranging from 0 to n-1
-
__weakref__
¶ list of weak references to the object (if defined)
-
apply
(operator, id=None)[source]¶ Apply a single-qubit operator to this qubit, tensoring with I and passing to the qsystem.apply() method
Parameters: - operator (np.array) – a single qubit (2x2) complex-valued matrix
- cacheID (str) – a character or string to cache the expanded operator by (e.g. Hadamard qubit 2 -> “IHII…”)
-
classmethod
from_stream
(qstream, system_index, qubit_index)[source]¶ Instantiate a qubit from a parent stream (via a QSystem call)
Parameters: - qstream (QStream) – the parent stream
- system_index (int) – the index corresponding to the parent QSystem
- qubit_index (int) – the index of the qubit to be recalled
Returns: the qubit
-