pyquil.resource_manager

Contains objects and functions to manage allocation and de-allocation of quantum and classical resources in pyQuil.

class pyquil.resource_manager.AbstractQubit[source]

Bases: pyquil.quil_atom.QuilAtom

Representation of a qubit.

index()[source]
class pyquil.resource_manager.DirectQubit(index)[source]

Bases: pyquil.resource_manager.AbstractQubit

A reference to a particularly indexed qubit.

index()[source]
class pyquil.resource_manager.Qubit(resource_manager)[source]

Bases: pyquil.resource_manager.AbstractQubit

A qubit whose index is determined by a ResourceManager.

index()[source]
Returns:The index of this qubit.
Return type:int
class pyquil.resource_manager.ResourceManager[source]

Bases: object

allocate_qubit()[source]

Create a new Qubit object.

Returns:A Qubit instance.
Return type:Qubit
free_qubit(q)[source]

Free the previously allocated qubit.

Parameters:q (Qubit) – A live Qubit that was previously allocated.
instantiate(qubit)[source]

Assign a number to a qubit.

Parameters:qubit (Qubit) – A Qubit object.
reset()[source]

Frees all qubits, resetting this ResourceManager.

uninstantiate_index(i)[source]

Free up an index that was previously instantiated.

Parameters:i (int) – The index.
pyquil.resource_manager.check_live_qubit(qubit)[source]

Ensure that an object is a live qubit. Raises errors if not.

Parameters:qubit – A qubit, either a DirectQubit or Qubit object.
pyquil.resource_manager.instantiated(qubit)[source]

Is the qubit instantiated?

Parameters:qubit (AbstractQubit) – A AbstractQubit instance.
Returns:A boolean.
Return type:bool
pyquil.resource_manager.merge_resource_managers(rm1, rm2)[source]

Merge two resource managers into a new resource manager. All qubits in the old managers will point to the new one. The in_use labels of the second resource manager have priority.

Parameters:
Returns:

A merged ResourceManager.

Return type:

ResourceManager