feature: count circuit operation on circuit or given qubits#1278
feature: count circuit operation on circuit or given qubits#1278skushagra wants to merge 1 commit into
Conversation
|
I did not understand much around what can we do for calculating density of operations. I would need more clarification on how should we exactly define this density, and since there can be multiple ways with respect to which density can be calculated like, operations per layer, per qubit etc. Hence I extracted this into a seprate helper file to prevent bloating the Circuit class. Perhaps more clarification on this would help me to add such a features. |
| return [_normalize_operator_name(op) for op in operators] | ||
|
|
||
|
|
||
| def count_instructions( |
There was a problem hiding this comment.
why not make this a private function instead, or I do not mind moving it all to circuit.py
There was a problem hiding this comment.
we can move it all to circuit.py but this keeping(or renaming circuit_analysis.py) seems to be a very nice option that will keep the circuit class clean. But if it goes against the normal practives that we follow, I'll move it back.
There was a problem hiding this comment.
Yes, I would prefer this to be in the circuit.py
| include_types_set = set(include_types) | ||
| operator_names_set = set(_to_operator_names(operators)) | ||
| _qs = QubitSet(qubits) if qubits is not None else None | ||
| filter_qubits = _qs if _qs else None # empty QubitSet treated as no filter |
There was a problem hiding this comment.
check for case when qubit specified is not part of the circuit
| >>> circ.count_instructions(qubits=0) | ||
| Counter({'H': 1, 'CNot': 1, 'Rx': 1}) | ||
| """ | ||
| from braket.circuits.circuit_analysis import count_instructions as _count_instructions |
There was a problem hiding this comment.
move all imports to the top
| """ | ||
| return self._parameters | ||
|
|
||
| def count_instructions(self, operators=None, **kwargs) -> Counter[str]: |
There was a problem hiding this comment.
The function name should ideally be count()
|
@skushagra could you also make sure to resolve all comments for the next updated CR |
*Issue #1235
Description of changes:
I have added a
count_instructionfunctions that gives you count of an instrcution on a circuit. I have added test cases for the required flow.Features
GATE,GATE_NOISE,MEASUREetc.).QubitMatch.ANY— instruction on any specified qubit.QubitMatch.ALL— instruction on all specified qubits.Merge Checklist
Put an
xin 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
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.