Skip to content

Easily count instructions in a circuit #1235

@sesmart

Description

@sesmart

Describe the feature you'd like

A simple method or tool for counting instructions.

How would this feature be used? Please describe.

Easily used for benchmarking, sanity-checks, or just gathering statistics on a Circuit. Could be an external method Circuit, or preferably a Circuit class method, or an accumulating static property.

A nice parallel is with list.count()

target_circuits.count('cnot')

Describe alternatives you've considered

Like many things, you just manually iterate over instructions and pattern match. Requires knowledge of instruction attributes, and so on. This request is really just a convenience function.

def count_gates(circ)
    gates = {}
    for ins in circ.instructions:
        name = ins.operator.name.lower()
        gates[name] = gates.get(name,0) + 1
    return gates

Additional context
Could also collect the density of operations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions