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._qubit

Definition of BasicQubit, Qubit, WeakQubit and Qureg classes.

projectq.types.BasicQubit(engine, idx)

BasicQubit objects represent qubits.

projectq.types.Qubit(engine, idx)

Qubit class.

projectq.types.Qureg([iterable])

Quantum register class.

projectq.types.WeakQubitRef(engine, idx)

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)).

property engine[source]

Return owning engine.

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.

__init__(engine, idx)[source]

Initialize a BasicQubit object.

Parameters
  • engine – Owning engine / engine that created the qubit

  • idx – Unique index of the qubit referenced by this qubit

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)).

property engine[source]

Return owning engine.

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.