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.
Definition of BasicQubit, Qubit, WeakQubit and Qureg classes. |
|
|
BasicQubit objects represent qubits. |
|
Qubit class. |
|
Quantum register class. |
|
WeakQubitRef objects are used inside the Command object. |
Submodules
_qubit
Definition of BasicQubit, Qubit, WeakQubit and Qureg classes.
A Qureg represents a list of Qubit or WeakQubit objects. A Qubit represents a (logical-level) qubit with a unique index provided by the MainEngine. Qubit objects are automatically deallocated if they go out of scope and intented to be used within Qureg objects in user code.
Example
from projectq import MainEngine
eng = MainEngine()
qubit = eng.allocate_qubit()
qubit is a Qureg of size 1 with one Qubit object which is deallocated once qubit goes out of scope.
WeakQubit are used inside the Command object and are not automatically deallocated.
- class projectq.types._qubit.BasicQubit(engine, idx)[source]
BasicQubit objects represent qubits.
They have an id and a reference to the owning engine.
- class projectq.types._qubit.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.
- class projectq.types._qubit.Qureg(iterable=(), /)[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)).
- class projectq.types._qubit.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.
Module contents
ProjectQ module containing all basic types
- class projectq.types.BasicQubit(engine, idx)[source]
BasicQubit objects represent qubits.
They have an id and a reference to the owning engine.
- 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.
- class projectq.types.Qureg(iterable=(), /)[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)).
- 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.