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. This would preferably be 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
Some stretch ideas
- Could also collect the density of operations
- Could collect instructions per qubit
uH 2026
Please note that we're still waiting for Unitary Foundation to review and approve our issues, so these are subject to change.
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. This would preferably be a Circuit class method, or an accumulating static property.
A nice parallel is with list.count()
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.
Additional context
Some stretch ideas
uH 2026
Please note that we're still waiting for Unitary Foundation to review and approve our issues, so these are subject to change.