Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
139 commits
Select commit Hold shift + click to select a range
4830bb4
[partial commit] committing the trivial changes - depends on changes …
bettinaheim Mar 5, 2025
b834f98
[partial commit] more changes that should be ok to commit - depends o…
bettinaheim Mar 5, 2025
36097ff
[partial commit] partial progress - depends on changes I haven't comm…
bettinaheim Mar 5, 2025
94da283
row majore for matrix class
bettinaheim Mar 6, 2025
3854090
cmake tests pass - needs clean up
bettinaheim Mar 6, 2025
61a9228
this should cover all C++ llvm lit tests
bettinaheim Mar 6, 2025
48a7ec8
some cleanup
bettinaheim Mar 6, 2025
f6e3630
addressing some fixmes
bettinaheim Mar 6, 2025
322b8dd
cleaning up some comments
bettinaheim Mar 6, 2025
fd7d1a2
going with get_term_id for term expectation retrieval - just seems fa…
bettinaheim Mar 7, 2025
a0c84af
... and a couple more comments
bettinaheim Mar 7, 2025
604ffa7
throw if we don't find an expectation value
bettinaheim Mar 7, 2025
21265e4
making product iterable
bettinaheim Mar 7, 2025
db7e756
cleaning up ordering conventions
bettinaheim Mar 7, 2025
3f87949
minor clean up
bettinaheim Mar 7, 2025
735f595
iterator over sum
bettinaheim Mar 7, 2025
00036ba
sorting out operator names
bettinaheim Mar 7, 2025
b23343a
forgot to save a file
bettinaheim Mar 7, 2025
f2aa283
removing file that should not be committed
bettinaheim Mar 7, 2025
dda0eb8
cleaning up the mess in the operators.h, operator_sum.cpp and product…
bettinaheim Mar 7, 2025
e55849f
some renaming
bettinaheim Mar 7, 2025
6afc0e1
more class renaming
bettinaheim Mar 7, 2025
b2692aa
reenabling most of the old spin ops tests
bettinaheim Mar 7, 2025
f672373
reenabling most of the old spin ops tests
bettinaheim Mar 7, 2025
ba301f2
Early cmake changes necessary (?) for libraries
bmhowe23 Mar 8, 2025
9b15ccd
Merge pull request #26 from bmhowe23/spin_ops
bettinaheim Mar 8, 2025
aafa774
Cleaning up docs preview for PR #26.
cuda-quantum-bot Mar 8, 2025
81da29b
some tools for better backward compatibility
bettinaheim Mar 8, 2025
1614d8c
some progress on the python bindings
bettinaheim Mar 8, 2025
2a10655
isolated commit to have the context own its spinop
bettinaheim Mar 8, 2025
9ff0f6f
some minor things
bettinaheim Mar 8, 2025
e8860a0
Try fixing ObserveAnsatz
annagrin Mar 8, 2025
124e624
Merge pull request #27 from annagrin/spin-ops-observe-ansatz-fix
bettinaheim Mar 9, 2025
3b79e84
Cleaning up docs preview for PR #27.
cuda-quantum-bot Mar 9, 2025
6252869
fixes a couple of the remaining tests
bettinaheim Mar 9, 2025
1805556
commit before trying to replace data format
bettinaheim Mar 9, 2025
a9cd155
changing data representation
bettinaheim Mar 9, 2025
c64f3a6
additional constructor for compatibility with existing files
bettinaheim Mar 9, 2025
a6f2983
all tests except for the python dynamics seem to pass now
bettinaheim Mar 9, 2025
295770b
wip commit to be able to switch branches
bettinaheim Mar 9, 2025
db54169
[blind - i.e. did not run all tests] ergonomic improvements
bettinaheim Mar 9, 2025
8415b17
changes from spin_ops
bettinaheim Mar 9, 2025
83cd7dd
all python tests now pass
bettinaheim Mar 9, 2025
e141fd1
deleting spare file
bettinaheim Mar 9, 2025
0bd41e2
Merge branch 'main' into spin_ops
bettinaheim Mar 9, 2025
0eea3dc
minimal API changes
bettinaheim Mar 10, 2025
14f287a
template instantiation
bettinaheim Mar 10, 2025
d085084
pulling in changes from renaming
bettinaheim Mar 10, 2025
b694a9b
adding an is_default property to sum (not yet tested)
bettinaheim Mar 10, 2025
631e8bb
instantiate handler specific templates also for clang
bettinaheim Mar 10, 2025
66a1715
some tests - it occurs to me that scalars are not properly handled fo…
bettinaheim Mar 10, 2025
8fda12f
this should take care of most build errors, except the elusive clang …
bettinaheim Mar 10, 2025
e830898
fixing one wrong test, and updating the docs and a test to reflect th…
bettinaheim Mar 10, 2025
33dc4a3
forgot to commit the docs comment change
bettinaheim Mar 10, 2025
5d3eb33
default value
bettinaheim Mar 10, 2025
b5096d4
skip test if openfermion is not found
bettinaheim Mar 10, 2025
dbb16b4
Merge branch 'renaming' into spin_ops
bettinaheim Mar 10, 2025
975602b
formatting
bettinaheim Mar 10, 2025
ca899a3
more formatting
bettinaheim Mar 10, 2025
4a2a5b7
Merge branch 'main' into spin_ops
bettinaheim Mar 14, 2025
18ca6b0
removing duplication from merge
bettinaheim Mar 14, 2025
1819d4b
Removing a comment regarding the serialization format needing an upda…
bettinaheim Mar 14, 2025
518ae29
fixing some things that probably went wrong with the merge
bettinaheim Mar 14, 2025
a7c2f6e
making clang happy
bettinaheim Mar 14, 2025
6d00558
updates
bettinaheim Mar 14, 2025
b1e21c6
updating notebooks
bettinaheim Mar 14, 2025
438c0b5
more notebook updates in notebooks that are not in CI
bettinaheim Mar 14, 2025
8397d8a
fixing python changes
bettinaheim Mar 14, 2025
b7e056d
making the sum iterator deterministic
bettinaheim Mar 18, 2025
67fdd36
Merge branch 'main' into spin_ops
bettinaheim Mar 18, 2025
974347d
formatting
bettinaheim Mar 18, 2025
08e682d
taking care of the remaining updates
bettinaheim Mar 18, 2025
0114a74
fixing sum iterator
bettinaheim Mar 18, 2025
81cbd9c
wrong API call
bettinaheim Mar 18, 2025
5d1d3c2
a couple of fixes I missed
bettinaheim Mar 18, 2025
9c25c3b
a couple of fixes I missed
bettinaheim Mar 18, 2025
828eab8
adding a evaluate_coefficient method
bettinaheim Mar 18, 2025
4ad9903
some ergonomic changes to minimize breaking changes
bettinaheim Mar 18, 2025
fd1d58d
making it possible to keep the ham = 0; ham += spin_op... assignment
bettinaheim Mar 18, 2025
237610d
undoing accidentally committed change of target
bettinaheim Mar 18, 2025
1d0ea43
forgot two
bettinaheim Mar 18, 2025
d088e0a
formatting
bettinaheim Mar 18, 2025
0668526
Merge branch 'main' into spin_ops
bettinaheim Mar 18, 2025
a762ef3
missed a signature update
bettinaheim Mar 19, 2025
17a996c
small fixes
bettinaheim Mar 19, 2025
38467f6
implementing sparse matrix as is - may be better to use Eigen instead
bettinaheim Mar 19, 2025
8da1cf7
using eigen for sparse matrix
bettinaheim Mar 19, 2025
f29b0f2
formatting and spellcheck
bettinaheim Mar 19, 2025
97256b8
adding C++ deprecation warnings
bettinaheim Mar 19, 2025
c9aa9ba
making gcc happy
bettinaheim Mar 19, 2025
ef586bb
Merge branch 'main' into spin_ops
bettinaheim Mar 19, 2025
beb3d4d
forgot some preprocessor ifs
bettinaheim Mar 19, 2025
875cff0
moving to size_t across the board for operators
bettinaheim Mar 20, 2025
6ae3e85
switching dimensions to int64_t to match cudensitymat
bettinaheim Mar 20, 2025
093ecf6
formatting
bettinaheim Mar 20, 2025
a264782
adjusting data type in test
bettinaheim Mar 20, 2025
04d3515
Merge branch 'main' into spin_ops
bettinaheim Mar 20, 2025
4a2ace4
hopefully makes doxygen happy
bettinaheim Mar 20, 2025
6d6baad
Merge branch 'spin_ops' of https://github.com/bettinaheim/cuda-quantu…
bettinaheim Mar 20, 2025
ce43284
formatting
bettinaheim Mar 20, 2025
23aed9b
review comments
bettinaheim Mar 21, 2025
76459e8
eliminate user_facing_order
bettinaheim Mar 21, 2025
e897a2c
adding min_degree and max_degree
bettinaheim Mar 21, 2025
a45953f
convenience namespaces
bettinaheim Mar 21, 2025
cc25522
Merge branch 'main' into spin_ops
bettinaheim Mar 21, 2025
7dfe497
some ergonomic changes
bettinaheim Mar 21, 2025
0f7c461
two more deprecation warnings
bettinaheim Mar 21, 2025
a412093
adding trim helper
bettinaheim Mar 21, 2025
ba6a125
better test for trim
bettinaheim Mar 24, 2025
f599372
renaming some headers/files
bettinaheim Mar 24, 2025
02fe66d
making evaluation.h a proper header
bettinaheim Mar 24, 2025
cac0163
just moving some files
bettinaheim Mar 24, 2025
d91ee6b
moving integrator headers
bettinaheim Mar 24, 2025
42d402f
formatting
bettinaheim Mar 24, 2025
0f7d82a
Merge branch 'main' into spin_ops
bettinaheim Mar 24, 2025
c9a234c
lineendings
bettinaheim Mar 24, 2025
f48e4fa
make to_string the same format as term id
bettinaheim Mar 24, 2025
a1043de
canonicalize to trim ids
bettinaheim Mar 24, 2025
37fe1c7
tests for canonicalize
bettinaheim Mar 24, 2025
34b5907
canonicalize to expand the terms
bettinaheim Mar 24, 2025
e5efc63
headers
bettinaheim Mar 24, 2025
4a0814b
headers and clean up
bettinaheim Mar 25, 2025
d733901
some clean up for counts
bettinaheim Mar 25, 2025
d0e0f5a
making observe ignore all identities
bettinaheim Mar 25, 2025
53ab777
removing files/changes that were just committed for convenience
bettinaheim Mar 25, 2025
c5c8ac7
removing unecessary include
bettinaheim Mar 25, 2025
55fc99d
proper error on deserialization error
bettinaheim Mar 25, 2025
e0cfd88
line endings
bettinaheim Mar 25, 2025
3c3e9f8
formatting
bettinaheim Mar 25, 2025
c1a97d7
Line endings
bmhowe23 Mar 25, 2025
9fb800a
fixing build errors
bettinaheim Mar 25, 2025
e7bc5d5
Update test_trotter.cpp (new from merge)
bmhowe23 Mar 26, 2025
c3f338b
Fixup e7bc5d5ba
bmhowe23 Mar 26, 2025
c8a763d
Merge branch 'main' into spin_ops
bettinaheim Mar 26, 2025
4bc60bd
updating mgpu commit to match the changes in this PR
bettinaheim Mar 26, 2025
4913c3d
addressing review comments
bettinaheim Mar 26, 2025
eae81cf
fixing the last commit....
bettinaheim Mar 26, 2025
c822959
formatting
bettinaheim Mar 26, 2025
8763301
fixing python syntax error
bettinaheim Mar 26, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/config/gitlab_commits.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
nvidia-mgpu-repo: cuda-quantum/cuquantum-mgpu.git
nvidia-mgpu-commit: ddfaacf2ffd7dc1a9a4333e06474b213887d437c
nvidia-mgpu-repo: cuda-quantum/cuquantum-mgpu.git
nvidia-mgpu-commit: 966ff7b2f775128fa3339e19672892d8ff1a4e74
1 change: 0 additions & 1 deletion cmake/Modules/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ set(CONFIG_FILES
CUDAQCommonConfig.cmake
CUDAQEmDefaultConfig.cmake
CUDAQNloptConfig.cmake
CUDAQSpinConfig.cmake
CUDAQOperatorConfig.cmake
CUDAQConfig.cmake
CUDAQEnsmallenConfig.cmake
Expand Down
3 changes: 0 additions & 3 deletions cmake/Modules/CUDAQConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ get_filename_component(CUDAQ_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
include(CMakeFindDependencyMacro)
list(APPEND CMAKE_MODULE_PATH "${CUDAQ_CMAKE_DIR}")

set (CUDAQSpin_DIR "${CUDAQ_CMAKE_DIR}")
find_dependency(CUDAQSpin REQUIRED)

set (CUDAQOperator_DIR "${CUDAQ_CMAKE_DIR}")
find_dependency(CUDAQOperator REQUIRED)

Expand Down
3 changes: 0 additions & 3 deletions cmake/Modules/CUDAQEmDefaultConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@

get_filename_component(CUDAQ_EM_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)

set (CUDAQSpin_DIR "${CUDAQ_EM_CMAKE_DIR}")
find_dependency(CUDAQSpin REQUIRED)

set (CUDAQOperator_DIR "${CUDAQ_EM_CMAKE_DIR}")
find_dependency(CUDAQOperator REQUIRED)

Expand Down
3 changes: 0 additions & 3 deletions cmake/Modules/CUDAQPlatformDefaultConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ find_dependency(CUDAQEmDefault REQUIRED)
set (CUDAQOperator_DIR "${CUDAQ_CMAKE_DIR}")
find_dependency(CUDAQOperator REQUIRED)

set (CUDAQSpin_DIR "${CUDAQ_CMAKE_DIR}")
find_dependency(CUDAQSpin REQUIRED)

set (CUDAQCommon_DIR "${CUDAQ_CMAKE_DIR}")
find_dependency(CUDAQCommon REQUIRED)

Expand Down
13 changes: 0 additions & 13 deletions cmake/Modules/CUDAQSpinConfig.cmake

This file was deleted.

1 change: 0 additions & 1 deletion cmake/Modules/NVQIRConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ include(CMakeFindDependencyMacro)

get_filename_component(PARENT_DIRECTORY ${NVQIR_CMAKE_DIR} DIRECTORY)

find_dependency(CUDAQSpin REQUIRED HINTS "${PARENT_DIRECTORY}/cudaq")
find_dependency(CUDAQOperator REQUIRED HINTS "${PARENT_DIRECTORY}/cudaq")
find_dependency(CUDAQCommon REQUIRED HINTS "${PARENT_DIRECTORY}/cudaq")
find_package(fmt QUIET)
Expand Down
12 changes: 3 additions & 9 deletions docs/sphinx/api/languages/cpp_api.rst
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
CUDA-Q C++ API
******************************

Operators
=============

.. doxygenclass:: cudaq::spin_op
:members:

Quantum
=========

Expand Down Expand Up @@ -38,9 +32,9 @@ Common
.. doxygenstruct:: cudaq::observe_options
:members:

.. doxygenfunction:: cudaq::observe(const observe_options &options, QuantumKernel &&kernel, spin_op H, Args &&...args)
.. doxygenfunction:: cudaq::observe(std::size_t shots, QuantumKernel &&kernel, spin_op H, Args &&...args)
.. doxygenfunction:: cudaq::observe(QuantumKernel &&kernel, spin_op H, Args &&...args)
.. doxygenfunction:: cudaq::observe(const observe_options &options, QuantumKernel &&kernel, const spin_op &H, Args &&...args)
.. doxygenfunction:: cudaq::observe(std::size_t shots, QuantumKernel &&kernel, const spin_op &H, Args &&...args)
.. doxygenfunction:: cudaq::observe(QuantumKernel &&kernel, const spin_op &H, Args &&...args)
.. doxygenfunction:: cudaq::observe(QuantumKernel &&kernel, const SpinOpContainer &termList, Args &&...args)

.. doxygenclass:: cudaq::ExecutionContext
Expand Down
9 changes: 4 additions & 5 deletions docs/sphinx/applications/cpp/qaoa_maxcut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <cudaq/algorithm.h>
#include <cudaq/gradients.h>
#include <cudaq/optimizers.h>
#include <cudaq/spin_op.h>

// Here we build up a CUDA-Q kernel for QAOA with p layers, with each
// layer containing the alternating set of unitaries corresponding to the
Expand Down Expand Up @@ -51,13 +50,13 @@ struct ansatz {

int main() {

using namespace cudaq::spin;

cudaq::set_random_seed(13); // set for repeatability

// Problem Hamiltonian
const cudaq::spin_op Hp = 0.5 * z(0) * z(1) + 0.5 * z(1) * z(2) +
0.5 * z(0) * z(3) + 0.5 * z(2) * z(3);
const cudaq::spin_op Hp = 0.5 * cudaq::spin_op::z(0) * cudaq::spin_op::z(1) +
0.5 * cudaq::spin_op::z(1) * cudaq::spin_op::z(2) +
0.5 * cudaq::spin_op::z(0) * cudaq::spin_op::z(3) +
0.5 * cudaq::spin_op::z(2) * cudaq::spin_op::z(3);

// Problem parameters
const int n_qubits = 4;
Expand Down
27 changes: 15 additions & 12 deletions docs/sphinx/applications/cpp/trotter_kernel_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,22 @@ struct initState {
}
};

std::vector<double> term_coefficients(cudaq::spin_op op) {
std::vector<double> term_coefficients(const cudaq::spin_op &op) {
std::vector<double> result{};
op.for_each_term([&](cudaq::spin_op &term) {
const auto coeff = term.get_coefficient().real();
for (const auto &term : op) {
const auto coeff = term.evaluate_coefficient().real();
result.push_back(coeff);
});
}
return result;
}

std::vector<cudaq::pauli_word> term_words(cudaq::spin_op op) {
std::vector<cudaq::pauli_word> result{};
op.for_each_term(
[&](cudaq::spin_op &term) { result.push_back(term.to_string(false)); });
std::vector<cudaq::pauli_word> term_words(const cudaq::spin_op &op) {
// Our kernel uses these words to apply exp_pauli to the entire state.
// we hence ensure that each pauli word covers the entire space.
auto n_spins = op.num_qubits();
std::vector<cudaq::pauli_word> result;
for (const auto &term : op)
result.push_back(term.get_pauli_word(n_spins));
return result;
}

Expand All @@ -93,22 +96,22 @@ int run_steps(int steps, int spins) {
const double Jz = g;
const double dt = 0.05;
const int n_steps = steps;
const int n_spins = spins;
const std::size_t n_spins = spins;
const double omega = 2 * M_PI;
const auto heisenbergModelHam = [&](double t) -> cudaq::spin_op {
cudaq::spin_op tdOp(n_spins);
for (int i = 0; i < n_spins - 1; ++i) {
for (std::size_t i = 0; i < n_spins - 1; ++i) {
tdOp += (Jx * cudaq::spin::x(i) * cudaq::spin::x(i + 1));
tdOp += (Jy * cudaq::spin::y(i) * cudaq::spin::y(i + 1));
tdOp += (Jz * cudaq::spin::z(i) * cudaq::spin::z(i + 1));
}
for (int i = 0; i < n_spins; ++i)
for (std::size_t i = 0; i < n_spins; ++i)
tdOp += (std::cos(omega * t) * cudaq::spin::x(i));
return tdOp;
};
// Observe the average magnetization of all spins (<Z>)
cudaq::spin_op average_magnetization(n_spins);
for (int i = 0; i < n_spins; ++i)
for (std::size_t i = 0; i < n_spins; ++i)
average_magnetization += ((1.0 / n_spins) * cudaq::spin::z(i));
average_magnetization -= 1.0;

Expand Down
22 changes: 13 additions & 9 deletions docs/sphinx/applications/python/adapt_qaoa.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -118,23 +118,28 @@
" # Add a term to the Hamiltonian for the edge (u,v)\n",
" ham += 0.5 * (weight[count] * cudaq.spin.z(qubitu) * cudaq.spin.z(qubitv) -\n",
" weight[count] * cudaq.spin.i(qubitu) * cudaq.spin.i(qubitv))\n",
" count+=1\n",
" count += 1\n",
"\n",
" return ham\n",
"\n",
"# Collect coefficients from a spin operator so we can pass them to a kernel\n",
"def term_coefficients(ham: cudaq.SpinOperator) -> list[complex]:\n",
" result = []\n",
" ham.for_each_term(lambda term: result.append(term.get_coefficient()))\n",
" for term in ham:\n",
" result.append(term.get_coefficient())\n",
" return result\n",
"\n",
"# Collect Pauli words from a spin operator so we can pass them to a kernel\n",
"def term_words(ham: cudaq.SpinOperator) -> list[str]:\n",
" # Our kernel uses these words to apply exp_pauli to the entire state.\n",
" # we hence ensure that each pauli word covers the entire space.\n",
" n_spins = ham.get_qubit_count()\n",
" result = []\n",
" ham.for_each_term(lambda term: result.append(term.to_string(False)))\n",
" for term in ham:\n",
" result.append(term.get_pauli_word(n_spins))\n",
" return result\n",
"\n",
"# Generate the Spin Hmiltonian:\n",
"# Generate the Spin Hamiltonian:\n",
"\n",
"ham = spin_ham(edges, weight)\n",
"ham_coef = term_coefficients(ham)\n",
Expand Down Expand Up @@ -185,7 +190,7 @@
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand All @@ -200,7 +205,6 @@
"# Generate the mixer pool\n",
"\n",
"pools = mixer_pool(qubits_num)\n",
"#print([op.to_string(False) for op in pools])\n",
"print('Number of pool operator: ', len(pools))"
]
},
Expand Down Expand Up @@ -289,7 +293,7 @@
},
{
"cell_type": "code",
"execution_count": 28,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -402,7 +406,7 @@
" layer.append(1) \n",
" random_mixer = random.choice(temp_pool)\n",
" \n",
" mixer_pool = mixer_pool + [random_mixer.to_string(False)]\n",
" mixer_pool = mixer_pool + [random_mixer.get_pauli_word(qubits_num)]\n",
" \n",
" print('Mixer pool at step', istep)\n",
" print(mixer_pool)\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,14 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Generate the Hamiltonian\n",
"def ham_clique(penalty, nodes, weights, non_edges) -> cudaq.SpinOperator:\n",
"\n",
" spin_ham = 0.0\n",
" spin_ham = 0\n",
" for wt, node in zip(weights, nodes):\n",
" #print(wt,node)\n",
" spin_ham += 0.5 * wt * spin.z(node)\n",
Expand All @@ -153,7 +153,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand All @@ -180,15 +180,20 @@
"# Collect coefficients from a spin operator so we can pass them to a kernel\n",
"def term_coefficients(ham: cudaq.SpinOperator) -> list[complex]:\n",
" result = []\n",
" ham.for_each_term(lambda term: result.append(term.get_coefficient()))\n",
" for term in ham:\n",
" result.append(term.get_coefficient())\n",
" return result\n",
"\n",
" # Collect Pauli words from a spin operator so we can pass them to a kernel\n",
"\n",
"\n",
"def term_words(ham: cudaq.SpinOperator) -> list[str]:\n",
" # Our kernel uses these words to apply exp_pauli to the entire state.\n",
" # we hence ensure that each pauli word covers the entire space.\n",
" n_spins = ham.get_qubit_count()\n",
" result = []\n",
" ham.for_each_term(lambda term: result.append(term.to_string(False)))\n",
" for term in ham:\n",
" result.append(term.get_pauli_word(n_spins))\n",
" return result\n",
"\n",
"\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand Down
19 changes: 12 additions & 7 deletions docs/sphinx/applications/python/hamiltonian_simulation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,14 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": null,
"id": "heisenberg-code",
"metadata": {},
"outputs": [],
"source": [
"def create_hamiltonian_heisenberg(n_spins: int, Jx: float, Jy: float, Jz: float, h_x: list[float], h_y: list[float], h_z: list[float]):\n",
" \"\"\"Create the Hamiltonian operator\"\"\"\n",
" ham = cudaq.SpinOperator(num_qubits=n_spins)\n",
" ham = 0\n",
"\n",
" # Add two-qubit interaction terms for Heisenberg Hamiltonian\n",
" for i in range(0, n_spins - 1):\n",
Expand All @@ -221,14 +221,14 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": null,
"id": "tfim-code",
"metadata": {},
"outputs": [],
"source": [
"def create_hamiltonian_tfim(n_spins: int, h_field: float):\n",
" \"\"\"Create the Hamiltonian operator\"\"\"\n",
" ham = cudaq.SpinOperator(num_qubits=n_spins)\n",
" ham = 0\n",
" \n",
" # Add single-qubit terms\n",
" for i in range(0, n_spins):\n",
Expand All @@ -253,19 +253,24 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": null,
"id": "extract-code",
"metadata": {},
"outputs": [],
"source": [
"def extractCoefficients(hamiltonian: cudaq.SpinOperator):\n",
" result = []\n",
" hamiltonian.for_each_term(lambda term: result.append(term.get_coefficient()))\n",
" for term in hamiltonian:\n",
" result.append(term.get_coefficient())\n",
" return result\n",
"\n",
"def extractWords(hamiltonian: cudaq.SpinOperator):\n",
" # Our kernel uses these words to apply exp_pauli to the entire state.\n",
" # we hence ensure that each pauli word covers the entire space.\n",
" n_spins = hamiltonian.get_qubit_count()\n",
" result = []\n",
" hamiltonian.for_each_term(lambda term: result.append(term.to_string(False)))\n",
" for term in hamiltonian:\n",
" result.append(term.get_pauli_word(n_spins))\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General question about the Python notebooks and docs changes - right now most people that look at them are using the latest official release - are the changes in this PR will also work with 0.10? If not then I suggest to stage these changes until we have the next official release.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me double check, but I think these changes should work with 0.10.0; I largely had this PR ready prior to the 0.10.0 release, so everything that is not mitigation for deprecation should already be in 0.10.0. It was just too risky and too tight to pull it in in a way that is as nice as possible with regards to existing code.

" return result"
]
},
Expand Down
Loading
Loading