From b2e5e1da5cac1503ffd99e6a3914c346f5ee9858 Mon Sep 17 00:00:00 2001 From: Sachin Pisal Date: Tue, 14 Jan 2025 17:56:42 -0800 Subject: [PATCH] Adding evolution API Signed-off-by: Sachin Pisal --- runtime/cudaq/evolution.h | 46 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 runtime/cudaq/evolution.h diff --git a/runtime/cudaq/evolution.h b/runtime/cudaq/evolution.h new file mode 100644 index 00000000000..3b86c448ceb --- /dev/null +++ b/runtime/cudaq/evolution.h @@ -0,0 +1,46 @@ +/****************************************************************-*- C++ -*-**** + * Copyright (c) 2022 - 2025 NVIDIA Corporation & Affiliates. * + * All rights reserved. * + * * + * This source code and the accompanying materials are made available under * + * the terms of the Apache License 2.0 which accompanies this distribution. * + ******************************************************************************/ + +#pragma once + +#include "cudaq/operators.h" +#include "cudaq/schedule.h" +#include "cudaq/base_integrator.h" +#include "common/EvolveResult.h" + +#include +#include +#include +#include +#include + +namespace cudaq { +class Evolution { +public: + /// Computes the Taylor series expansion of the matrix exponential. + static Eigen::MatrixXcd taylor_series_expm(const Eigen::MatrixXcd &op_matrix, int order = 20); + + /// Computes the evolution step matrix + static Eigen::MatrixXcd compute_step_matrix(const operator_sum &hamiltonian, const std::map &dimensions, const std::map> ¶meters, double dt, bool use_gpu = false); + + /// Adds noise channels based on collapse operators. + static void add_noise_channel_for_step(const std::string &step_kernel_name, cudaq::noise_model &noise_model, const std::vector &collapse_operators, const std::map &dimensions, const std::map> ¶meters, double dt); + + /// Launches an analog Hamiltonian kernel for quantum simulations. + static evolve_result launch_analog_hamiltonian_kernel(const std::string &target_name, const operator_sum &hamiltonian, const std::shared_ptr &schedule, int shots_count, bool is_async = false); + + /// Generates evolution kernels for the simulation. + static std::vector evolution_kernel(int num_qubits, const std::function> &, double)> &compute_step_matrix, const std::vector tlist, const std::vector>> &schedule_parameters); + + /// Evolves a single quantum state under a given hamiltonian. + static evolve_result evolve_single(const operator_sum &hamiltonian, const std::map &dimensions, const std::shared_ptr &schedule, state initial_state, const std::vector &collapse_operators = {}, const std::vector &observables = {}, bool store_intermediate_results = false, std::shared_ptr> integrator = nullptr, std::optional shots_count = std::nullopt); + + /// Evolves a single or multiple quantum states under a given hamiltonian. + static std::vector evolve(const operator_sum &hamiltonian, const std::map &dimensions, const std::shared_ptr &schedule, const std::vector &initial_states, const std::vector &collapse_operators = {}, const std::vector &observables = {}, bool store_intermediate_results = false, std::shared_ptr> integrator = nullptr, std::optional shots_count = std::nullopt); +}; +} \ No newline at end of file