-
Notifications
You must be signed in to change notification settings - Fork 294
Replacing existing spin_ops with the general operators #2710
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
Conversation
…I haven't committed yet Signed-off-by: Bettina Heim <heimb@outlook.com>
…n changes I haven't committed yet Signed-off-by: Bettina Heim <heimb@outlook.com>
…itted yet Signed-off-by: Bettina Heim <heimb@outlook.com>
Signed-off-by: Bettina Heim <heimb@outlook.com>
Signed-off-by: Bettina Heim <heimb@outlook.com>
Signed-off-by: Bettina Heim <heimb@outlook.com>
Signed-off-by: Bettina Heim <heimb@outlook.com>
Signed-off-by: Bettina Heim <heimb@outlook.com>
Signed-off-by: Bettina Heim <heimb@outlook.com>
…r cleaner and more predictable Signed-off-by: Bettina Heim <heimb@outlook.com>
Signed-off-by: Bettina Heim <heimb@outlook.com>
Signed-off-by: Bettina Heim <heimb@outlook.com>
Signed-off-by: Bettina Heim <heimb@outlook.com>
Signed-off-by: Bettina Heim <heimb@outlook.com>
Signed-off-by: Bettina Heim <heimb@outlook.com>
Signed-off-by: Bettina Heim <heimb@outlook.com>
Signed-off-by: Bettina Heim <heimb@outlook.com>
Signed-off-by: Bettina Heim <heimb@outlook.com>
Signed-off-by: Bettina Heim <heimb@outlook.com>
…_operator.cpp Signed-off-by: Bettina Heim <heimb@outlook.com>
Signed-off-by: Bettina Heim <heimb@outlook.com>
Signed-off-by: Bettina Heim <heimb@outlook.com>
Signed-off-by: Bettina Heim <heimb@outlook.com>
Signed-off-by: Bettina Heim <heimb@outlook.com>
Signed-off-by: Ben Howe <bhowe@nvidia.com>
Early cmake changes necessary (?) for libraries
Signed-off-by: Bettina Heim <heimb@outlook.com>
Signed-off-by: Bettina Heim <heimb@outlook.com>
Command Bot: Processing... |
|
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
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.
I'm only part way through, but posting what I've got so far.
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.
This is another partial review ... I'm hoping that submitting this one and then starting another one will make my browser load the remaining diffs correctly.
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.
OK, this is the last of my comments. Unfortunately breaking up my review didn't help my browser any ... it refuses to automatically load diffs for more than X files (where X is unknown to me), so I had to manually load them I think that many of the test file changes ended up being unnecessary (simply changing to use cudaq::spin_op::x instead of just x).
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, Bettina. I know there are some unresolved threads right now, but I'm approving now anyway and will let you judge which ones need to be addressed now vs later (or never).
Also, just to capture our offline discussion, we know this is likely to break compatibility with our currently deployed NVQC servers, but there is a separate plan in place for NVQC going forward.
Signed-off-by: Bettina Heim <heimb@outlook.com>
Signed-off-by: Bettina Heim <heimb@outlook.com>
Signed-off-by: Bettina Heim <heimb@outlook.com>
Command Bot: Processing... |
Signed-off-by: Bettina Heim <heimb@outlook.com>
Command Bot: Processing... |
|
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
|
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
This PR includes the required CUDA-QX changes that must be applied once NVIDIA/cuda-quantum#2710 (from CUDA-Q) lands. For that PR, most of the breaking changes are in C++, but a few Python tests needed to be updated as well. Python changes will likely be coming in the near future. Note that this change actually removes more code than it adds. This is primarily due to updates in the test code. Here is a summary of the changes in this PR. 1. Update CMakeLists.txt files to link against `cudaq-operator` instead of `cudaq-spin` because `cuda-spin` was removed. 2. Make use of `cudaq::spin_op_term` (a product term) where appropriate. I currently left all the public QEC API's to use `spin_op` (a sum term), but we may choose to update them to simply `spin_op_term` in the near future. That would be a CUDA-QX breaking change if we do. 3. Since the new operators no longer store degrees that had implicit `I`'s in them, we must now clarify whether we want `I` in the terms. For QEC, this means that we will sometimes use something like `cudaq::spin_op_term identity(0, get_num_data_qubits())`, but for Solvers, we have eliminated all implicit `I`'s. 4. Use `get_pauli_word()` instead of `to_string(false)`. 5. Use `evaluate_coefficient()` instead of `get_coefficient()`. 6. Use `.trim()` to remove 0-cofficient terms and `.canonicalize()` to remove `I` operations from terms. (These new helper functions help reduce boiler-plate code.) 7. For default-constructed `cudaq::spin_op` objects, clarify whether you want them to be initialized to the neutral sum term (i.e. 0 = `spin_op::empty()`) or the neutral product term (i.e. 1 = `spin_op::identity()`). 8. Change `for_each_term()` to use iterators like `for (const auto &term : hamiltonian)`. 9. As needed, update code to reflect that `get_qubit_count()` now only returns the number of _actual_ degrees used in the operator rather than the "highest degree + 1" that used to be returned. If needed, make use of the new `min_degree()` and `max_degree()` methods instead. 10. For canned test data, update to use the new serialization format (as retrieved by `get_data_representation()`). 11. For test data comparisons, be sure to call `canonicalize` on the test data and/or truth data as necessary in order to ensure correct comparisons. 12. Don't use `get_raw_data()` anymore. --------- Signed-off-by: Ben Howe <bhowe@nvidia.com>
* State synthesis for quantum devices (#2291) * DCO Remediation Commit for Ben Howe <bhowe@nvidia.com> I, Ben Howe <bhowe@nvidia.com>, hereby add my Signed-off-by to this commit: 86681ef Signed-off-by: Ben Howe <bhowe@nvidia.com> Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * State pointer synthesis for quantum hardware Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Merge with main Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Merge with main Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Fix test failure on anyon platform Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Make StateInitialization a funcOp pass Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Fix issues and tests for the rest of quantum architectures Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Fix failing quantinuum state prep tests Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Address CR comments Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Format Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Fix failing test Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Format Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Format Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Replaced getState intrinsic by cc.get_state op Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Remove print Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Remove getCudaqState references Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Minor updates Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Fix failing quake test Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Add a few state-related cc ops Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Fix test_argument_conversion Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Add printing in failing tests Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Add printing in failing tests Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Fix failing tests Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Add description for new algorithm for state syntesis Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Fix tests Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Make intermediate IR legal by separating allocs * DCO Remediation Commit for Anna Gringauze <agringauze@nvidia.com> I, Anna Gringauze <agringauze@nvidia.com>, hereby add my Signed-off-by to this commit: 9563371 Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Address some PR comments Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Address more CR comments Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Cleanup Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Address CR comments Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Address more CR comments Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Address more CR comments Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Store new functions in subst module and update synthesis Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Make argument synthesis transitive Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Update callers of synthesis Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Use PointerOf in quake defs Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Addressed more CR comments Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Recursive with caching Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * StateAggregatorWithArgumentConverter Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Make ArgumentConverter handle the state call tree Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Make argument converter handle kernels created from states Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Fix null alloc size and add tests Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Keep storing ops when generating numSubits func Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Cleanup Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Cleanup Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Cleanup Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Fix failing test Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Fix failing doc build Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Address CR comments Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Address more CR comments and add a test Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Address more CR comments Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Fix links Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Fix links Signed-off-by: Anna Gringauze <agringauze@nvidia.com> --------- Signed-off-by: Ben Howe <bhowe@nvidia.com> Signed-off-by: Anna Gringauze <agringauze@nvidia.com> Co-authored-by: Ben Howe <bhowe@nvidia.com> * Some fixes for complex numbers and vectors (#2739) * Some fixes for complex numbers and vectors Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Cleanup Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Cleanup Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Update lib/Optimizer/Dialect/CC/CCOps.cpp Co-authored-by: Eric Schweitz <eschweitz@nvidia.com> Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Fix links Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Fix links Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Fix links Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Fix links Signed-off-by: Anna Gringauze <agringauze@nvidia.com> --------- Signed-off-by: Anna Gringauze <agringauze@nvidia.com> Co-authored-by: Eric Schweitz <eschweitz@nvidia.com> * Add docs for `apply_noise` (#2745) * Enabling afqmc notebook by freezing numba to 0.60.0 (#2759) * Enabling afqmc by freezing numba to 0.60.0 Signed-off-by: Sachin Pisal <spisal@nvidia.com> * removing afqmc form skipped_notebooks Signed-off-by: Sachin Pisal <spisal@nvidia.com> --------- Signed-off-by: Sachin Pisal <spisal@nvidia.com> * Replacing existing spin_ops with the general operators (#2710) This PR contains the full replacement of the existing spin_ops with the new general operators. See the PR description on GitHub for a full list of all changes. --------- Signed-off-by: Bettina Heim <heimb@outlook.com> Signed-off-by: Ben Howe <bhowe@nvidia.com> Signed-off-by: Anna Gringauze <agringauze@nvidia.com> Co-authored-by: Ben Howe <bhowe@nvidia.com> Co-authored-by: cuda-quantum-bot <cuda-quantum-bot@users.noreply.github.com> Co-authored-by: Anna Gringauze <agringauze@nvidia.com> * Allow Return Value Optimization instead of forcing moves (#2765) Signed-off-by: Ben Howe <bhowe@nvidia.com> * Dev Container psi-header extension: retain original copyright year (#2766) For those of us using VSCode dev containers, this makes the psi-header extension work with other projects that don't all have 2022 as a starting point. More specifically - with this change, the extension will attempt to retain the existing starting copyright year and update only the ending copyright year if it exists (rather than updating both the start copyright year and current copyright year). Additionally, if the file is a new file, it will use "now" as the starting copyright year, which is more correct anyway. Signed-off-by: Ben Howe <bhowe@nvidia.com> --------- Signed-off-by: Ben Howe <bhowe@nvidia.com> Signed-off-by: Anna Gringauze <agringauze@nvidia.com> Signed-off-by: Sachin Pisal <spisal@nvidia.com> Signed-off-by: Bettina Heim <heimb@outlook.com> Co-authored-by: Anna Gringauze <agringauze@nvidia.com> Co-authored-by: Ben Howe <bhowe@nvidia.com> Co-authored-by: Eric Schweitz <eschweitz@nvidia.com> Co-authored-by: Ben Howe <141149032+bmhowe23@users.noreply.github.com> Co-authored-by: Sachin Pisal <spisal@nvidia.com> Co-authored-by: Bettina Heim <heimb@outlook.com> Co-authored-by: cuda-quantum-bot <cuda-quantum-bot@users.noreply.github.com>
* State synthesis for quantum devices (NVIDIA#2291) * DCO Remediation Commit for Ben Howe <bhowe@nvidia.com> I, Ben Howe <bhowe@nvidia.com>, hereby add my Signed-off-by to this commit: 86681ef Signed-off-by: Ben Howe <bhowe@nvidia.com> Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * State pointer synthesis for quantum hardware Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Merge with main Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Merge with main Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Fix test failure on anyon platform Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Make StateInitialization a funcOp pass Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Fix issues and tests for the rest of quantum architectures Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Fix failing quantinuum state prep tests Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Address CR comments Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Format Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Fix failing test Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Format Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Format Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Replaced getState intrinsic by cc.get_state op Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Remove print Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Remove getCudaqState references Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Minor updates Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Fix failing quake test Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Add a few state-related cc ops Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Fix test_argument_conversion Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Add printing in failing tests Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Add printing in failing tests Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Fix failing tests Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Add description for new algorithm for state syntesis Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Fix tests Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Make intermediate IR legal by separating allocs * DCO Remediation Commit for Anna Gringauze <agringauze@nvidia.com> I, Anna Gringauze <agringauze@nvidia.com>, hereby add my Signed-off-by to this commit: 9563371 Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Address some PR comments Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Address more CR comments Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Cleanup Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Address CR comments Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Address more CR comments Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Address more CR comments Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Store new functions in subst module and update synthesis Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Make argument synthesis transitive Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Update callers of synthesis Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Use PointerOf in quake defs Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Addressed more CR comments Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Recursive with caching Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * StateAggregatorWithArgumentConverter Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Make ArgumentConverter handle the state call tree Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Make argument converter handle kernels created from states Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Fix null alloc size and add tests Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Keep storing ops when generating numSubits func Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Cleanup Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Cleanup Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Cleanup Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Fix failing test Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Fix failing doc build Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Address CR comments Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Address more CR comments and add a test Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Address more CR comments Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Fix links Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Fix links Signed-off-by: Anna Gringauze <agringauze@nvidia.com> --------- Signed-off-by: Ben Howe <bhowe@nvidia.com> Signed-off-by: Anna Gringauze <agringauze@nvidia.com> Co-authored-by: Ben Howe <bhowe@nvidia.com> * Some fixes for complex numbers and vectors (NVIDIA#2739) * Some fixes for complex numbers and vectors Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Cleanup Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Cleanup Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Update lib/Optimizer/Dialect/CC/CCOps.cpp Co-authored-by: Eric Schweitz <eschweitz@nvidia.com> Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Fix links Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Fix links Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Fix links Signed-off-by: Anna Gringauze <agringauze@nvidia.com> * Fix links Signed-off-by: Anna Gringauze <agringauze@nvidia.com> --------- Signed-off-by: Anna Gringauze <agringauze@nvidia.com> Co-authored-by: Eric Schweitz <eschweitz@nvidia.com> * Add docs for `apply_noise` (NVIDIA#2745) * Enabling afqmc notebook by freezing numba to 0.60.0 (NVIDIA#2759) * Enabling afqmc by freezing numba to 0.60.0 Signed-off-by: Sachin Pisal <spisal@nvidia.com> * removing afqmc form skipped_notebooks Signed-off-by: Sachin Pisal <spisal@nvidia.com> --------- Signed-off-by: Sachin Pisal <spisal@nvidia.com> * Replacing existing spin_ops with the general operators (NVIDIA#2710) This PR contains the full replacement of the existing spin_ops with the new general operators. See the PR description on GitHub for a full list of all changes. --------- Signed-off-by: Bettina Heim <heimb@outlook.com> Signed-off-by: Ben Howe <bhowe@nvidia.com> Signed-off-by: Anna Gringauze <agringauze@nvidia.com> Co-authored-by: Ben Howe <bhowe@nvidia.com> Co-authored-by: cuda-quantum-bot <cuda-quantum-bot@users.noreply.github.com> Co-authored-by: Anna Gringauze <agringauze@nvidia.com> * Allow Return Value Optimization instead of forcing moves (NVIDIA#2765) Signed-off-by: Ben Howe <bhowe@nvidia.com> * Dev Container psi-header extension: retain original copyright year (NVIDIA#2766) For those of us using VSCode dev containers, this makes the psi-header extension work with other projects that don't all have 2022 as a starting point. More specifically - with this change, the extension will attempt to retain the existing starting copyright year and update only the ending copyright year if it exists (rather than updating both the start copyright year and current copyright year). Additionally, if the file is a new file, it will use "now" as the starting copyright year, which is more correct anyway. Signed-off-by: Ben Howe <bhowe@nvidia.com> --------- Signed-off-by: Ben Howe <bhowe@nvidia.com> Signed-off-by: Anna Gringauze <agringauze@nvidia.com> Signed-off-by: Sachin Pisal <spisal@nvidia.com> Signed-off-by: Bettina Heim <heimb@outlook.com> Co-authored-by: Anna Gringauze <agringauze@nvidia.com> Co-authored-by: Ben Howe <bhowe@nvidia.com> Co-authored-by: Eric Schweitz <eschweitz@nvidia.com> Co-authored-by: Ben Howe <141149032+bmhowe23@users.noreply.github.com> Co-authored-by: Sachin Pisal <spisal@nvidia.com> Co-authored-by: Bettina Heim <heimb@outlook.com> Co-authored-by: cuda-quantum-bot <cuda-quantum-bot@users.noreply.github.com> Signed-off-by: Anna Gringauze <agringauze@nvidia.com>
This PR contains the full replacement of the existing spin_ops with the new general operators. See the PR description on GitHub for a full list of all changes. --------- Signed-off-by: Bettina Heim <heimb@outlook.com> Signed-off-by: Ben Howe <bhowe@nvidia.com> Signed-off-by: Anna Gringauze <agringauze@nvidia.com> Co-authored-by: Ben Howe <bhowe@nvidia.com> Co-authored-by: cuda-quantum-bot <cuda-quantum-bot@users.noreply.github.com> Co-authored-by: Anna Gringauze <agringauze@nvidia.com> Signed-off-by: Anna Gringauze <agringauze@nvidia.com>
This PR contains the full replacement of the existing spin_ops with the new general operators.
It essentially keeps the python bindings as is with the trampolining between the C++ spin_ops and the python operators. That really needs to be replaced, but is a somewhat extensive change that I suggest to make in a separate PR. I did test that just replacing spin/spin ops in Python directly with the bound data structures works throughout all tests except for dynamics (which require that all other operators also are bound).
Some perf numbers can be found here: #2631
These largely remain the same - there is a tiny bit of overhead added due to the switch from int to size_t and the introduced default value, but that is < 10% (last benchmark is unchanged).
Full list of breaking vs non-breaking changes:
Breaking changes:
x,y,z, andiincudaq::spincreate aspin_op_term(a product operator)spin_op::emptychanged - it now returns an empty sumspin_op()constructor - it creates an uninitialized sum rather than the product identityspin_op(std::size_t)- it creates an empty sum reserving space for the given number of termsspin_op_term:std::vector<bool>but instead it's own class type (product_op<spin_handler>)spin_op_termincludes all information about the product, including its coefficientspin_op_termspin_op::key_typeandspin_op::mapped_typeno longer existspin_opiterator is aspin_op_termspin_opiterator nor thespin_op_termiterator allow to modify the operator itselfnum_qubitsreflects only the degrees the operator explicitly acts upon; e.g.spin_op::i(2)act on a single degreeto_matrixreflects only the degrees the operator explicitly acts upon; e.g.spin_op::x(1)returns a 2x2 matrix (previously a 4x4 matrix)get_coefficientreturns a scalar callback function that in general may require a parameter_map for evaluation;evaluate_coefficientreplaces the previous get_coefficient implementation and takes an optional parameter_map argumentto_string()produces a different string than before - see also deprecation ofto_string(bool)get_term_id()and values for the entire sum are stored under the key obtained by callingto_string()spin_op_termcan be obtained by callingget_pauli_word(size_t = 0);by default that representation does not include identities on qubits the operator does not explicitly act on,
but if the optional integral argument is provided, the string includes identities for the degrees in
[0, arg)that the operator does not act onexp_pauliexpects the number of qubits to match the length of the Pauli wordexpectationandcountwill fail instead of return0.0if the requested value has not been computed/foundspin_opmay be different than with the previous implementation;this should largely be irrelevant but may lead to slightly different results in some cases due to slightly different finite precision effects
cudaq-spinis replaced bycudaq-operatorCUDAQSpinConfig.cmakeandCUDAQSpinTargets.cmakeno longer exist - the replacements are the correspondingCUDAQOperator*.cmakefilesDeprecated:
spin_op(const std::vector<bool> &term, const std::complex<double> &coeff)(FIXME...)spin_op(std::pair<const std::vector<bool>, std::complex<double>> &termData)(FIXME...)spin_op(pauli, const std::size_t id, std::complex<double> coeff = 1.0)(FIXME...)spin_op(const std::unordered_map<std::vector<bool>, std::complex<double>> &_terms)(FIXME...)spin_op(const std::vector<std::vector<bool>> &bsf, const std::vector<std::complex<double>> &coeffs)(suggest no substitution)sum_op(const std::vector<double> &input_vec, std::size_t nQubits)(replaced with the matching constructor for new serialization format)get_raw_data(no substitution)is_identity(to be removed onspin_opclass, but will continue to be supported onspin_op_term)to_string(bool)(replaced by eitherto_string(),get_term_id, orget_pauli_word)getDataRepresentation(replaced byget_data_representationto generate the new serialization format)getDataTuple(no longer used, no substitution, matching constructor listed above)for_each_term(replaced by iterator)for_each_pauli(replaced by iterator)expectationandcountwill require aspin_op_termgoing forward; passing a spin_op (with a single term, as previously) is still supported but deprecatedOther changes:
csr_spmatrixis defined in thecudaqnamespace rather than a type definition onspin_opspin_opbut rather stores the valuespin_opchanged; deprecated functions producing and loading the old format are still available, but the entire internal infrastructure switched to the new format obtained byget_data_representationbinary_spin_op_reader::read(const std::string &)is set up to read the new data format -an overload
binary_spin_op_reader::read(const std::string &, bool)is provided that will read the old serialization format if the optional bool argument is set to truecudaq::dimension_maptostd::unordered_map<std::size_t, int64_t>; this should have no impact on application code in most cases, the only exception being a type change of the dimensions vector in the definition of a custom operatordegreesno longer takes a boolean parameter - any optional argument that was passed can be dropped without a change in behaviorto_matrixtakes an additional optional boolean parameterinvert_orderthat allows to retrieve the matrix with an inverted ordering convention compared to the default order