types¶
The types package contains quantum types such as Qubit, Qureg, and WeakQubitRef. With further development of the math library, also quantum integers, quantum fixed point numbers etc. will be added.
projectq.types.BasicQubit (engine, idx) |
BasicQubit objects represent qubits. |
projectq.types.Qubit (engine, idx) |
Qubit class. |
projectq.types.Qureg |
Quantum register class. |
projectq.types.WeakQubitRef (engine, idx) |
WeakQubitRef objects are used inside the Command object. |
Module contents¶
-
class
projectq.types.
BasicQubit
(engine, idx)[source]¶ BasicQubit objects represent qubits.
They have an id and a reference to the owning engine.
-
__eq__
(other)[source]¶ Compare with other qubit (Returns True if equal id and engine).
Parameters: other (BasicQubit) – BasicQubit to which to compare this one
-
__hash__
()[source]¶ Return the hash of this qubit.
Hash definition because of custom __eq__. Enables storing a qubit in, e.g., a set.
-
-
class
projectq.types.
Qubit
(engine, idx)[source]¶ Qubit class.
Represents a (logical-level) qubit with a unique index provided by the MainEngine. Once the qubit goes out of scope (and is garbage-collected), it deallocates itself automatically, allowing automatic resource management.
Thus the qubit is not copyable; only returns a reference to the same object.
-
__copy__
()[source]¶ Non-copyable (returns reference to self).
Note
To prevent problems with automatic deallocation, qubits are not copyable!
-
-
class
projectq.types.
Qureg
[source]¶ Quantum register class.
Simplifies accessing measured values for single-qubit registers (no []- access necessary) and enables pretty-printing of general quantum registers (call Qureg.__str__(qureg)).
-
__bool__
()[source]¶ Return measured value if Qureg consists of 1 qubit only.
Raises: - Exception if more than 1 qubit resides in this register (then you
- need to specify which value to get using qureg[???])
-
__int__
()[source]¶ Return measured value if Qureg consists of 1 qubit only.
Raises: - Exception if more than 1 qubit resides in this register (then you
- need to specify which value to get using qureg[???])
-
-
class
projectq.types.
WeakQubitRef
(engine, idx)[source]¶ WeakQubitRef objects are used inside the Command object.
Qubits feature automatic deallocation when destroyed. WeakQubitRefs, on the other hand, do not share this feature, allowing to copy them and pass them along the compiler pipeline, while the actual qubit objects may be garbage-collected (and, thus, cleaned up early). Otherwise there is no difference between a WeakQubitRef and a Qubit object.