forked from NVIDIA/cuda-quantum
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase_integrator.h
More file actions
76 lines (63 loc) · 2.58 KB
/
base_integrator.h
File metadata and controls
76 lines (63 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/****************************************************************-*- 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 "operators.h"
#include "schedule.h"
#include <map>
#include <memory>
#include <vector>
namespace cudaq {
// Struct captures the system dynamics needed by the integrator
struct SystemDynamics {
std::vector<int64_t> modeExtents;
sum_op<cudaq::matrix_handler> hamiltonian;
std::vector<sum_op<cudaq::matrix_handler>> collapseOps;
std::unordered_map<std::string, std::complex<double>> parameters;
SystemDynamics(
const std::vector<int64_t> extents,
const sum_op<cudaq::matrix_handler> &ham,
const std::vector<sum_op<cudaq::matrix_handler>> &cOps = {},
const std::unordered_map<std::string, std::complex<double>> ¶ms = {})
: modeExtents(extents), hamiltonian(ham), collapseOps(cOps),
parameters(params) {}
SystemDynamics()
: hamiltonian(sum_op<cudaq::matrix_handler>(
cudaq::matrix_op::empty())){};
};
class base_time_stepper;
class base_integrator {
public:
/// @brief Default constructor
base_integrator() = default;
virtual ~base_integrator() = default;
/// @brief Set the initial state and time
virtual void setState(const cudaq::state &initialState, double t0) = 0;
/// @brief Perform integration to the target time.
virtual void integrate(double targetTime) = 0;
/// @brief Get the current time and state.
virtual std::pair<double, cudaq::state> getState() = 0;
/// @brief Create a clone of this integrator.
// e.g., cloning an integrator to keep inside async. functors.
virtual std::shared_ptr<base_integrator> clone() = 0;
protected:
friend class integrator_helper;
SystemDynamics m_system;
cudaq::schedule m_schedule;
std::unique_ptr<base_time_stepper> m_stepper;
};
class integrator_helper {
public:
static void init_system_dynamics(base_integrator &integrator,
const SystemDynamics &system,
const cudaq::schedule &schedule) {
integrator.m_system = system;
integrator.m_schedule = schedule;
integrator.m_stepper.reset();
}
};
} // namespace cudaq