Skip to content

feat: add count() method to Circuit for instruction countingFeature circuit count#1296

Open
sirocco369 wants to merge 2 commits into
amazon-braket:mainfrom
sirocco369:feature-circuit-count
Open

feat: add count() method to Circuit for instruction countingFeature circuit count#1296
sirocco369 wants to merge 2 commits into
amazon-braket:mainfrom
sirocco369:feature-circuit-count

Conversation

@sirocco369

Copy link
Copy Markdown

Fixes #1235

This PR adds a count() method to the Circuit class that allows users to easily count instructions in a quantum circuit.

Features:

  • circuit.count('gate_name') — returns count of specific gate (case-insensitive)
  • circuit.count() — returns dictionary with counts of all gate types
  • Handles all instruction types (gates, measurements, etc.)
  • Returns 0 for empty circuits or non-existent gates

Changes:

  • Added count() method to Circuit class in src/braket/circuits/circuit.py
  • Added comprehensive tests in test/unit_tests/braket/circuits/test_circuit.py

Examples:

>>> circ = Circuit().h(0).cnot(0, 1).h(1)
>>> circ.count('h')
2
>>> circ.count()
{'h': 2, 'cnot': 1}

@sirocco369 sirocco369 requested a review from a team as a code owner June 10, 2026 00:53

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why has this change been made as part of this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Easily count instructions in a circuit

2 participants