Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 6 additions & 6 deletions docs/sphinx/examples/cpp/dynamics/cavity_qed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ int main() {
// For the cavity subsystem 1
// We create the annihilation (a) and creation (a+) operators.
// These operators lower and raise the photon number, respectively.
auto a = cudaq::boson_operator::annihilate(1);
auto a_dag = cudaq::boson_operator::create(1);
auto a = cudaq::boson_op::annihilate(1);
auto a_dag = cudaq::boson_op::create(1);

// For the atom subsystem 0
// We create the annihilation (`sm`) and creation (`sm_dag`) operators.
// These operators lower and raise the excitation number, respectively.
auto sm = cudaq::boson_operator::annihilate(0);
auto sm_dag = cudaq::boson_operator::create(0);
auto sm = cudaq::boson_op::annihilate(0);
auto sm_dag = cudaq::boson_op::create(0);

// Number operators
// These operators count the number of excitations.
// For the atom (`subsytem` 0) and the cavity (`subsystem` 1) they give the
// population in each subsystem.
auto atom_occ_op = cudaq::matrix_operator::number(0);
auto cavity_occ_op = cudaq::matrix_operator::number(1);
auto atom_occ_op = cudaq::matrix_op::number(0);
auto cavity_occ_op = cudaq::matrix_op::number(1);

// Hamiltonian
// The `hamiltonian` models the dynamics of the atom-cavity (cavity QED)
Expand Down
20 changes: 10 additions & 10 deletions docs/sphinx/examples/cpp/dynamics/cross_resonance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ int main() {
// operators allow transitions between the spin states (|0> and |1>).
auto spin_plus = [](int degree) {
return 0.5 *
(cudaq::spin_operator::x(degree) +
std::complex<double>(0.0, 1.0) * cudaq::spin_operator::y(degree));
(cudaq::spin_handler::x(degree) +
std::complex<double>(0.0, 1.0) * cudaq::spin_handler::y(degree));
};

auto spin_minus = [](int degree) {
return 0.5 *
(cudaq::spin_operator::x(degree) -
std::complex<double>(0.0, 1.0) * cudaq::spin_operator::y(degree));
(cudaq::spin_handler::x(degree) -
Copy link
Collaborator

Choose a reason for hiding this comment

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

spin_handler? shouldn't this be spin_op::x?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The operators i, x, y, z are private in spin_op. These are made available through static methods in spin_handler.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The user should never write code that says "spin_handler". The user facing type is spin_op.

Copy link
Collaborator Author

@sacpis sacpis Mar 12, 2025

Choose a reason for hiding this comment

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

Thanks @amccaskey for the feedback. @bettinaheim Can we make this change now for this release?

std::complex<double>(0.0, 1.0) * cudaq::spin_handler::y(degree));
};

// The Hamiltonian describes the energy and dynamics of our 2-qubit system.
Expand All @@ -61,10 +61,10 @@ int main() {
// 4. `Crosstalk` drive on qubit 1: m_12 * Omega * X. A reduces drive on qubit
// 1 due to electromagnetic `crosstalk`.
auto hamiltonian =
(delta / 2.0) * cudaq::spin_operator::z(0) +
(delta / 2.0) * cudaq::spin_handler::z(0) +
J * (spin_minus(1) * spin_plus(0) + spin_plus(1) * spin_minus(0)) +
Omega * cudaq::spin_operator::x(0) +
m_12 * Omega * cudaq::spin_operator::x(1);
Omega * cudaq::spin_handler::x(0) +
m_12 * Omega * cudaq::spin_handler::x(1);

// Each qubit is a 2-level system (dimension 2).
// The composite system (two qubits) has a total Hilbert space dimension of 2
Expand Down Expand Up @@ -98,9 +98,9 @@ int main() {

// The observables are the spin components along the x, y, and z directions
// for both qubits. These observables will be measured during the evolution.
auto observables = {cudaq::spin_operator::x(0), cudaq::spin_operator::y(0),
cudaq::spin_operator::z(0), cudaq::spin_operator::x(1),
cudaq::spin_operator::y(1), cudaq::spin_operator::z(1)};
auto observables = {cudaq::spin_handler::x(0), cudaq::spin_handler::y(0),
cudaq::spin_handler::z(0), cudaq::spin_handler::x(1),
cudaq::spin_handler::y(1), cudaq::spin_handler::z(1)};

// Evolution with 2 initial states
// We evolve the system under the defined Hamiltonian for both initial states
Expand Down
18 changes: 9 additions & 9 deletions docs/sphinx/examples/cpp/dynamics/heisenberg_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ int main() {
// The staggered magnetization operator is used to measure antiferromagnetic
// order. It is defined as a sum over all spins of the Z operator, alternating
// in sign. For even sites, we add `sz`; for odd sites, we subtract `sz`.
auto staggered_magnetization_t = cudaq::matrix_operator::empty();
auto staggered_magnetization_t = cudaq::sum_op<cudaq::spin_handler>::empty();
for (int i = 0; i < num_spins; i++) {
auto sz = cudaq::spin_operator::z(i);
auto sz = cudaq::spin_handler::z(i);
if (i % 2 == 0) {
staggered_magnetization_t += sz;
} else {
Expand Down Expand Up @@ -83,14 +83,14 @@ int main() {
// H = H + `Jy` * `Sy`_i * `Sy`_{i+1}
// H = H + `Jz` * `Sz`_i * `Sz`_{i+1}
// This is a form of the `anisotropic` Heisenberg (or `XYZ`) model.
auto hamiltonian = cudaq::spin_operator::empty();
auto hamiltonian = cudaq::sum_op<cudaq::spin_handler>::empty();
for (int i = 0; i < num_spins - 1; i++) {
hamiltonian = hamiltonian + Jx * cudaq::spin_operator::x(i) *
cudaq::spin_operator::x(i + 1);
hamiltonian = hamiltonian + Jy * cudaq::spin_operator::y(i) *
cudaq::spin_operator::y(i + 1);
hamiltonian = hamiltonian + Jz * cudaq::spin_operator::z(i) *
cudaq::spin_operator::z(i + 1);
hamiltonian = hamiltonian + Jx * cudaq::spin_handler::x(i) *
cudaq::spin_handler::x(i + 1);
hamiltonian = hamiltonian + Jy * cudaq::spin_handler::y(i) *
cudaq::spin_handler::y(i + 1);
hamiltonian = hamiltonian + Jz * cudaq::spin_handler::z(i) *
cudaq::spin_handler::z(i + 1);
}

// Initial state vector
Expand Down
10 changes: 5 additions & 5 deletions docs/sphinx/examples/cpp/dynamics/qubit_control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ int main() {
// 2. A time-dependent driving term: omega_x * cos(omega_drive * t) * `Sx`_0,
// which induces rotations about the X-axis. The scalar_operator(mod_`func`)
// allows the drive term to vary in time according to mod_`func`.
auto hamiltonian = 0.5 * omega_z * cudaq::spin_operator::z(0) +
mod_func * cudaq::spin_operator::x(0) * omega_x;
auto hamiltonian = 0.5 * omega_z * cudaq::spin_handler::z(0) +
mod_func * cudaq::spin_handler::x(0) * omega_x;

// A single qubit with dimension 2.
cudaq::dimension_map dimensions = {{0, 2}};
Expand Down Expand Up @@ -76,8 +76,8 @@ int main() {

// Measure the expectation values of the `qubit's` spin components along the
// X, Y, and Z directions.
auto observables = {cudaq::spin_operator::x(0), cudaq::spin_operator::y(0),
cudaq::spin_operator::z(0)};
auto observables = {cudaq::spin_handler::x(0), cudaq::spin_handler::y(0),
cudaq::spin_handler::z(0)};

// Simulation without decoherence
// Evolve the system under the Hamiltonian, using the specified schedule and
Expand All @@ -93,7 +93,7 @@ int main() {
double gamma_sz = 1.0;
auto evolve_result_decay = cudaq::evolve(
hamiltonian, dimensions, schedule, psi0, integrator,
{std::sqrt(gamma_sz) * cudaq::spin_operator::z(0)}, observables, true);
{std::sqrt(gamma_sz) * cudaq::spin_handler::z(0)}, observables, true);

// Lambda to extract expectation values for a given observable index
auto get_expectation = [](int idx, auto &result) -> std::vector<double> {
Expand Down
8 changes: 4 additions & 4 deletions docs/sphinx/examples/cpp/dynamics/qubit_dynamics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ int main() {
// Qubit `hamiltonian`: 2 * pi * 0.1 * sigma_x
// Physically, this represents a qubit (a two-level system) driven by a weak
// transverse field along the x-axis.
auto hamiltonian = 2.0 * M_PI * 0.1 * cudaq::spin_operator::x(0);
auto hamiltonian = 2.0 * M_PI * 0.1 * cudaq::spin_handler::x(0);

// Dimensions: one subsystem of dimension 2 (a two-level system).
const cudaq::dimension_map dimensions = {{0, 2}};
Expand All @@ -40,15 +40,15 @@ int main() {
// Run the simulation without collapse operators (ideal evolution)
auto evolve_result = cudaq::evolve(
hamiltonian, dimensions, schedule, psi0, integrator, {},
{cudaq::spin_operator::y(0), cudaq::spin_operator::z(0)}, true);
{cudaq::spin_handler::y(0), cudaq::spin_handler::z(0)}, true);

constexpr double decay_rate = 0.05;
auto collapse_operator = std::sqrt(decay_rate) * cudaq::spin_operator::x(0);
auto collapse_operator = std::sqrt(decay_rate) * cudaq::spin_handler::x(0);

// Evolve with collapse operators
cudaq::evolve_result evolve_result_decay = cudaq::evolve(
hamiltonian, dimensions, schedule, psi0, integrator, {collapse_operator},
{cudaq::spin_operator::y(0), cudaq::spin_operator::z(0)}, true);
{cudaq::spin_handler::y(0), cudaq::spin_handler::z(0)}, true);

// Lambda to extract expectation values for a given observable index
auto get_expectation = [](int idx, auto &result) -> std::vector<double> {
Expand Down
Loading