-
Notifications
You must be signed in to change notification settings - Fork 376
Speed-up of AbelianGrouper.group_subops #923
Speed-up of AbelianGrouper.group_subops #923
Conversation
I don't think this build error is not caused by my change.
|
This is awesome!! Maybe we should check inside convert to see whether the summedop only contains PauliOps, and if that's the case, use the fast method, and otherwise use the Alternatively, is there an elegant way to add the numpy speed directly into the PauliOp's |
@dongreenberg Thank you for your comments. It is a good idea to call the fast version only if the summedop only contains PualiOps. I will write a code to realize it and add unit tests. |
So, I think a special pass for ListOp consisting of only PauliOp is the best approach. |
I added an option to control the pass (generic or fast) and update the test script The result of H2O JW:
Unit tests are not completed yet. |
Thank you for your comments. I changed the default options and moved the unit tests to |
Fwiw, please feel free to open an issue against retworkx to add the coloring support. The first priority for it when I started was the terra's usage for the DAGCircuit and the transpiler. So outside of that it doesn't have many features yet. But, now that it is in place expanding retworkx to support other needs from a graph library is totally fair and definitely worth it. I've got an in-progress PR for undirected graphs open now Qiskit/rustworkx#68. Once that's merged adding coloring algorithms (especially the |
Thanks! It's a good news. When undirected graphs are merged, I want to try it. |
Sorry - I think I may have been unclear about something. I liked that you pull the AbelianGrouper tests into a separate file. Can we just move test_abelian_grouper1 2 and 3 into the new test_abelian_grouper file and out of test_pauli_expectation? |
Sorry. I will move the tests to a separate file. |
I moved abelian grouper tests to a separate file test_abelian_grouper.py and added a unit test with random pauli operators. |
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.
Looks great, thanks Imamichi-san!!!!
Thank you for fixing lint. |
@woodsp-ibm should I hold off on merging this until after the patch to stable today? |
@dongreenberg Yes, if we can hold off on this until we do the release, thanks. |
…#923) * fast operator grouping with numpy * add a trick for networkx * remove unnecessary "[]" * fix comments * (wip) add test_abelian_grouper.py * implement a fast pass of grouping * fix lint * implement a numpy-based coloring * move abelian groupter tests * simplify * move abelian groupter tests to a separete file * replace assert with assertTrue * Fix lint Co-authored-by: Manoel Marques <manoel@us.ibm.com> Co-authored-by: Julien Gacon <jules.gacon@googlemail.com> Co-authored-by: Donny Greenberg <dongreenberg2@gmail.com> Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com>
…#923) * fast operator grouping with numpy * add a trick for networkx * remove unnecessary "[]" * fix comments * (wip) add test_abelian_grouper.py * implement a fast pass of grouping * fix lint * implement a numpy-based coloring * move abelian groupter tests * simplify * move abelian groupter tests to a separete file * replace assert with assertTrue * Fix lint Co-authored-by: Manoel Marques <manoel@us.ibm.com> Co-authored-by: Julien Gacon <jules.gacon@googlemail.com> Co-authored-by: Donny Greenberg <dongreenberg2@gmail.com> Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com>
…#923) * fast operator grouping with numpy * add a trick for networkx * remove unnecessary "[]" * fix comments * (wip) add test_abelian_grouper.py * implement a fast pass of grouping * fix lint * implement a numpy-based coloring * move abelian groupter tests * simplify * move abelian groupter tests to a separete file * replace assert with assertTrue * Fix lint Co-authored-by: Manoel Marques <manoel@us.ibm.com> Co-authored-by: Julien Gacon <jules.gacon@googlemail.com> Co-authored-by: Donny Greenberg <dongreenberg2@gmail.com> Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com>
Summary
Faster version of AbelianGrouper.group_subops with numpy.
As a PoC, I implemented
AbelianGrouper.group_subops_fast
.I know it is necessary to use
commutes
method, but it takes so long time to checkcommutes
between all pairs of operators.Details and comments
TPB based grouping can be implemented with numpy as tpb_grouped_weighted_pauli_operator.py does.
I implemented the same technique as
AbelianGrouper.group_subops_fast
.I also tested a trick to reduce the overhead of
Graph.add_edges_from
by directly inserting elements toGraph._adj
.I compared them using pauli_grouping.py.
I used NH3JW.txt of https://arxiv.org/src/1701.08213v1/anc/TaperingPaperHamiltonians.rar
'original' is the result of
AbelianGrouper.group_subops
, 'fast1' is that ofgroup_subops_fast
without the networkx trick, and 'fast2' is that ofgroup_subops_fast
with the networkx trick.The resulting groups are identical and 'fast2' is the fastest.