-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve performance of RB circuit generation #1317
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @eendebakpt . This is a simple but good improvement I'd like to have. The use of QuantumCircuit._append
now sounds good to me since I've heard it's a semi-public API, which should be stable. I just suggest a minor improvement for the correct use of the API.
@@ -291,7 +291,7 @@ def _sequences_to_circuits( | |||
circ = QuantumCircuit(self.num_qubits) | |||
for elem in seq: | |||
circ.append(self._to_instruction(elem, basis_gates), circ.qubits) | |||
circ.append(Barrier(self.num_qubits), circ.qubits) | |||
circ._append(Barrier(self.num_qubits), circ.qubits, circ.cregs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
circ._append(Barrier(self.num_qubits), circ.qubits, circ.cregs) | |
circ._append(CircuitInstruction(Barrier(circ.num_qubits), tuple(circ.qubits), ())) |
with the import of CircuitInstruction
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@itoko No problem to change this, but why is this the correct usage of the API? The type annotation for _append
allows for both a CircuitInstruction
or Instruction
to be passed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excuse me for my short explanation. The old code does not take cargs
so it should be empty for drop-in replacement as you've already fixed so. Even if we want to change the spec and add barrier to clbits
it should be circ.clbits: Sequence[Clbit]
but not circ.cregs: list[ClassicalRegister]
. That's why I say the above change is not correct.
As you say the use of Instruction is allowed but the new-style (using CircuitInstruction) would be preferable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, LGTM.
### Summary In this PR we improve performance of the RB circuit generation. ### Details and comments The main performance bottleneck is the repeat application of `append` of sequence elements to a circuit. We can improve performance by using the `_append` for the `Barrier` gate. For the appending of the Clifford gates we could also use `_append` (in particular if the sequence elements are integral, in which case the internal generation using `_to_instruction` guarantees the elements to not need checking), but since the `StandardRB` is subclassed we have no full information about the elements in the sequence and have chosen not to do this. Profiling on main: ![image](https://github.com/Qiskit-Extensions/qiskit-experiments/assets/883786/23ddd6b3-e3cb-4ade-914f-45e197b0d0c7) PR: ![image](https://github.com/Qiskit-Extensions/qiskit-experiments/assets/883786/81714750-6f33-4410-aa4f-c14287bc8dd8) ### PR checklist (delete when all criteria are met) - [x] I have read the contributing guide `CONTRIBUTING.md`. - [x] I have added the tests to cover my changes. - [x] I have updated the documentation accordingly. - [x] I have added a release note file using `reno` if this change needs to be documented in the release notes. Internal change, no release notes needed
### Summary In this PR we improve performance of the RB circuit generation. ### Details and comments The main performance bottleneck is the repeat application of `append` of sequence elements to a circuit. We can improve performance by using the `_append` for the `Barrier` gate. For the appending of the Clifford gates we could also use `_append` (in particular if the sequence elements are integral, in which case the internal generation using `_to_instruction` guarantees the elements to not need checking), but since the `StandardRB` is subclassed we have no full information about the elements in the sequence and have chosen not to do this. Profiling on main: ![image](https://github.com/Qiskit-Extensions/qiskit-experiments/assets/883786/23ddd6b3-e3cb-4ade-914f-45e197b0d0c7) PR: ![image](https://github.com/Qiskit-Extensions/qiskit-experiments/assets/883786/81714750-6f33-4410-aa4f-c14287bc8dd8) ### PR checklist (delete when all criteria are met) - [x] I have read the contributing guide `CONTRIBUTING.md`. - [x] I have added the tests to cover my changes. - [x] I have updated the documentation accordingly. - [x] I have added a release note file using `reno` if this change needs to be documented in the release notes. Internal change, no release notes needed
Summary
In this PR we improve performance of the RB circuit generation.
Details and comments
The main performance bottleneck is the repeat application of
append
of sequence elements to a circuit. We can improve performance by using the_append
for theBarrier
gate.For the appending of the Clifford gates we could also use
_append
(in particular if the sequence elements are integral, in which case the internal generation using_to_instruction
guarantees the elements to not need checking), but since theStandardRB
is subclassed we have no full information about the elements in the sequence and have chosen not to do this.Profiling on main:
PR:
PR checklist (delete when all criteria are met)
CONTRIBUTING.md
.reno
if this change needs to be documented in the release notes. Internal change, no release notes needed