forked from NVIDIA/cuda-quantum
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkedLibraryHolder.h
More file actions
107 lines (82 loc) · 3.44 KB
/
LinkedLibraryHolder.h
File metadata and controls
107 lines (82 loc) · 3.44 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/****************************************************************-*- C++ -*-****
* Copyright (c) 2022 - 2026 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 "common/Resources.h"
#include "common/RuntimeTarget.h"
#include "cudaq/Support/TargetConfig.h"
#include "cudaq/host_config.h"
#include <filesystem>
#include <functional>
#include <map>
#include <string>
#include <unordered_map>
#include <vector>
namespace nvqir {
class CircuitSimulator;
void switchToResourceCounterSimulator();
void stopUsingResourceCounterSimulator();
void setChoiceFunction(std::function<bool()> choice);
cudaq::Resources *getResourceCounts();
} // namespace nvqir
namespace cudaq {
class quantum_platform;
/// @brief The LinkedLibraryHolder provides a mechanism for
/// dynamically loading and storing the required plugin libraries
/// for the CUDA-Q runtime within the Python runtime.
class LinkedLibraryHolder {
protected:
// Store the library suffix
std::string libSuffix = "";
/// @brief The path to the CUDA-Q libraries
std::filesystem::path cudaqLibPath;
/// @brief Map of path strings to loaded library handles.
std::unordered_map<std::string, void *> libHandles;
/// @brief Vector of available simulators
std::vector<std::string> availableSimulators;
/// @brief Vector of available platforms
std::vector<std::string> availablePlatforms;
/// @brief Map of available targets.
std::unordered_map<std::string, RuntimeTarget> targets;
/// @brief Map of simulation targets
std::unordered_map<std::string, RuntimeTarget> simulationTargets;
/// @brief Store the name of the default target
std::string defaultTarget;
/// @brief Store the name of the current target
std::string currentTarget;
public:
LinkedLibraryHolder();
~LinkedLibraryHolder();
/// @brief Return the registered simulator with the given name.
nvqir::CircuitSimulator *getSimulator(const std::string &name);
/// @brief Return the registered quantum_platform with the given name.
quantum_platform *getPlatform(const std::string &name);
/// @brief Return the available runtime target with given name.
/// Throws an exception if no target available with that name.
RuntimeTarget getTarget(const std::string &name) const;
/// @brief Return the current target.
RuntimeTarget getTarget() const;
/// @brief Return all available runtime targets
std::vector<RuntimeTarget> getTargets() const;
/// @brief Return true if a target exists with the given name.
bool hasTarget(const std::string &name);
/// @brief Set the current target.
void setTarget(const std::string &targetName,
std::map<std::string, std::string> extraConfig = {});
/// @brief Reset the target back to the default.
void resetTarget();
};
namespace python {
namespace detail {
void switchToResourceCounterSimulator();
void stopUsingResourceCounterSimulator();
void setChoiceFunction(std::function<bool()> choice);
cudaq::Resources *getResourceCounts();
} // namespace detail
std::string getTransportLayer(LinkedLibraryHolder *holder);
} // namespace python
} // namespace cudaq