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.

Module contents

class projectq.types.BasicQubit(engine, idx)

BasicQubit objects represent qubits.

They have an id and a reference to the owning engine.

__bool__()

Access the result of a previous measurement and return False / True (0/1)

__eq__(other)

Compare with other qubit (Returns True if equal id and engine).

Parameters:other (BasicQubit) – BasicQubit to which to compare this one
__hash__()

Return the hash of this qubit.

Hash definition because of custom __eq__. Enables storing a qubit in, e.g., a set.

__init__(engine, idx)

Initialize a BasicQubit object.

Parameters:
  • engine – Owning engine / engine that created the qubit
  • idx – Unique index of the qubit referenced by this qubit
__int__()

Access the result of a previous measurement and return as integer (0 / 1).

__nonzero__()

Access the result of a previous measurement for Python 2.7.

__str__()

Return string representation of this qubit.

__weakref__

list of weak references to the object (if defined)

class projectq.types.Qubit(engine, idx)

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__()

Non-copyable (returns reference to self).

Note

To prevent problems with automatic deallocation, qubits are not copyable!

__deepcopy__(memo)

Non-deepcopyable (returns reference to self).

Note

To prevent problems with automatic deallocation, qubits are not deepcopyable!

__del__()

Destroy the qubit and deallocate it (automatically).

class projectq.types.Qureg

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__()

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__()

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[???])
__nonzero__()

Return measured value if Qureg consists of 1 qubit only for Python 2.7.

Raises:
  • Exception if more than 1 qubit resides in this register (then you
  • need to specify which value to get using qureg[???])
__str__()

Get string representation of a quantum register.

__weakref__

list of weak references to the object (if defined)

engine

Return owning engine.

class projectq.types.WeakQubitRef(engine, idx)

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.