Home Reference Source
import ResourceCounter from 'projectq/src/backends/resource.js'
public class | source

ResourceCounter

Extends:

BasicEngine → ResourceCounter

ResourceCounter is a compiler engine which counts the number of gates and max. number of active qubits.

Attributes: gate_counts (dict): Dictionary of gate counts. The keys are tuples of the form (cmd.gate, ctrl_cnt), where ctrl_cnt is the number of control qubits. gate_class_counts (dict): Dictionary of gate class counts. The keys are tuples of the form (cmd.gate.class, ctrl_cnt), where ctrl_cnt is the number of control qubits. max_width (int): Maximal width (=max. number of active qubits at any given point). Properties: depth_of_dag (int): It is the longest path in the directed acyclic graph (DAG) of the program.

Constructor Summary

Public Constructor
public

Member Summary

Public Members
public get
public
public
public
Private Members
private
private
private

Method Summary

Public Methods
public

addCMD(cmd: Command)

public

Specialized implementation of isAvailable: Returns true if the ResourceCounter is the last engine (since it can count any command).

public

receive(commandList: Command[])

public

Return the string representation of this ResourceCounter.

Inherited Summary

From class BasicEngine
public
public

Return a new qubit as a list containing 1 qubit object (quantum register of size 1).

public

Allocate n qubits and return them as a quantum register, which is a list of qubit objects.

public

Deallocate a qubit (and sends the deallocation command down the pipeline).

public

Default implementation of isAvailable: Ask the next engine whether a command is available, i.e., whether it can be executed by the next engine(s).

public

Check if there is a compiler engine handling the meta tag

public
public

send(commandList: Command[])

Forward the list of commands to the next engine in the pipeline.

Public Constructors

public constructor() source

Override:

BasicEngine#constructor

Public Members

public get depthOfDag: number: * source

Return:

number

public gate_class_counts: {} source

public gate_counts: {} source

public max_width: number source

Private Members

private _active_qubits: number source

private _depth_of_qubit: {} source

private _previous_max_depth: number source

Public Methods

public addCMD(cmd: Command) source

Params:

NameTypeAttributeDescription
cmd Command

public isAvailable(cmd: Command): boolean source

Specialized implementation of isAvailable: Returns true if the ResourceCounter is the last engine (since it can count any command).

Override:

BasicEngine#isAvailable

Params:

NameTypeAttributeDescription
cmd Command

Command for which to check availability (all Commands can be counted).

Return:

boolean

true, unless the next engine cannot handle the Command (if there is a next engine).

public receive(commandList: Command[]) source

Override:

BasicEngine#receive

Params:

NameTypeAttributeDescription
commandList Command[]

public toString(): string source

Return the string representation of this ResourceCounter.

Return:

string

A summary (string) of resources used, including gates, number of calls, and max. number of qubits that were active at the same time.