Skip to content

feature: Count Instructions in a Circuits via count() #1273

Open
sim-eng-ii wants to merge 12 commits into
amazon-braket:mainfrom
sim-eng-ii:feature/count_instructions
Open

feature: Count Instructions in a Circuits via count() #1273
sim-eng-ii wants to merge 12 commits into
amazon-braket:mainfrom
sim-eng-ii:feature/count_instructions

Conversation

@sim-eng-ii

@sim-eng-ii sim-eng-ii commented Jun 3, 2026

Copy link
Copy Markdown

Problem Addressed with This PR

This PR addresses issue #1235 by introducing two methods: counting instructions within a circuit and returning the number of times a gate appears in a circuit. Therefore, there is flexibility in which method to use.

Description of changes:

A new count() method was added in file \src\braket\circuits\circuit.py under the Circuit class:

  • count("cnot") returns an int
  • count() with no argument returns a Counter of all operator names and frequency.

Testing done:

Testing was achieved by adding two test functions that can be run via:

tox -e unit-tests -- test/unit_tests/braket/circuits/test_circuit.py -k count -v -s

ruff was used to format both Circuit.py and test_circuit.py

Merge Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your pull request.

General

Tests

  • [ x] I have added tests that prove my fix is effective or that my feature works (if appropriate)
  • [x ] I have checked that my tests are not configured for a specific region or account (if appropriate)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Cursor was used to navigate the folder structure and identify where the relevant files were.

@sim-eng-ii sim-eng-ii requested a review from a team as a code owner June 3, 2026 21:02
Comment thread src/braket/circuits/circuit.py Outdated
Comment thread src/braket/circuits/circuit.py Outdated
@sim-eng-ii sim-eng-ii changed the title feature: Count Instructions in a Circuits via count_gates() or count_instructions() feature: Count Instructions in a Circuits via count() Jun 4, 2026
@sim-eng-ii

Copy link
Copy Markdown
Author

I will fix the errors. thank you

@sim-eng-ii

Copy link
Copy Markdown
Author

it should be fixed now

@sim-eng-ii

Copy link
Copy Markdown
Author

There were some issues with tests regarding from_ir(), which should be resolved now! thank you @aniksd-braket

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.

2 participants