-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Remove deepcopy usage from circuit_to_dag() #1530
Remove deepcopy usage from circuit_to_dag() #1530
Conversation
The circuit_to_dag() function was previously using a deepcopy to make copies of all input circuits. This could get quite expensive as it has to update all the references. However, this deepcopy was only being used to create a fresh copy of the instructions objects that were part of the circuit. This instructions are passed directly to the dag in the output so we can't pass by reference otherwise changes to the dag will break the circuit. To avoid the performance hit with a deepcopy this commit changes the function to instatiate new instruction objects right before we add them to the dag. Fixes Qiskit#1528
do we have speed improvement numbers |
I've just done a small synthetic test running this function on a freshly loaded large circuit object (loaded from a 3500 line qasm file) and converting that to a dag. It was ~1.6x as fast for that quick conversion going from ~0.21 secs to ~0.13 secs. The raw data is:
If you've have any specific benchmarks you'd like me to run I can quickly throw it together. |
I ran transpile and compile on the same circuit from qasm and ran benchmark runs on those. For Heh, not quite as drastic as the >1000x speedup from the last time we did a patch like this in #1431 |
* Remove deepcopy usage from circuit_to_dag() The circuit_to_dag() function was previously using a deepcopy to make copies of all input circuits. This could get quite expensive as it has to update all the references. However, this deepcopy was only being used to create a fresh copy of the instructions objects that were part of the circuit. This instructions are passed directly to the dag in the output so we can't pass by reference otherwise changes to the dag will break the circuit. To avoid the performance hit with a deepcopy this commit changes the function to instatiate new instruction objects right before we add them to the dag. Fixes Qiskit#1528 * Fix Lint
Summary
The circuit_to_dag() function was previously using a deepcopy to make
copies of all input circuits. This could get quite expensive as it has
to update all the references. However, this deepcopy was only being used
to create a fresh copy of the instructions objects that were part of the
circuit. This instructions are passed directly to the dag in the output
so we can't pass by reference otherwise changes to the dag will break
the circuit. To avoid the performance hit with a deepcopy this commit
changes the function to instantiate new instruction objects right before
we add them to the dag.
Details and comments
Fixes #1528