Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature python interface #53

Merged
merged 10 commits into from
Sep 19, 2024
30 changes: 30 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ set(CMAKE_CXX_STANDARD 17)

project(nuTens)

# Changes default install path to be a subdirectory of the build dir.
# Can set build dir at configure time with -DCMAKE_INSTALL_PREFIX=/install/path
if(CMAKE_INSTALL_PREFIX STREQUAL "" OR CMAKE_INSTALL_PREFIX STREQUAL
"/usr/local")
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}")
elseif(NOT DEFINED CMAKE_INSTALL_PREFIX)
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}")
endif()


# Need to add some special compile flags to check the code test coverage
OPTION(NT_TEST_COVERAGE "produce code coverage reports when running tests" OFF)
IF(NT_TEST_COVERAGE)
Expand Down Expand Up @@ -46,6 +56,19 @@ ELSE()
message("Won't benchmark")
ENDIF()

# If user wants to enable python interface we need to include pybind
OPTION(NT_ENABLE_PYTHON "enable python interface" OFF)
IF(NT_ENABLE_PYTHON)
message("Enabling python")
CPMAddPackage(
GITHUB_REPOSITORY "pybind/pybind11"
VERSION 2.13.5
)

ELSE()
message("Won't enable python interface")
ENDIF()


## check build times
## have this optional as it's not supported on all CMake platforms
Expand All @@ -66,6 +89,13 @@ IF(NT_ENABLE_BENCHMARKING)
add_subdirectory(benchmarks)
ENDIF()

IF(NT_ENABLE_PYTHON)
set_property( TARGET tensor PROPERTY POSITION_INDEPENDENT_CODE ON )
set_property( TARGET propagator PROPERTY POSITION_INDEPENDENT_CODE ON )
set_property( TARGET spdlog PROPERTY POSITION_INDEPENDENT_CODE ON )
set_property( TARGET logging PROPERTY POSITION_INDEPENDENT_CODE ON )
add_subdirectory(python)
ENDIF()

# Print out a handy message to more easily see the config options
message( STATUS "The following variables have been used to configure the build: " )
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ nuTens uses [Googles benchmark library](https://github.com/google/benchmark) to
- [x] Add suite of benchmarking tests
- [x] Integrate benchmarks into CI ( maybe use [hyperfine](https://github.com/sharkdp/hyperfine) and [bencher](https://bencher.dev/) for this? )
- [ ] Add proper unit tests
- [ ] Expand CI to include more platforms
- [x] Expand CI to include more platforms
- [ ] Add support for modules (see [PyTorch doc](https://pytorch.org/cppdocs/api/classtorch_1_1nn_1_1_module.html))
- [ ] Propagation in variable matter density
- [ ] Add support for Tensorflow backend
- [ ] Add python interface
- [x] Add python interface

2 changes: 1 addition & 1 deletion benchmarks/benchmarks.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

#include <benchmark/benchmark.h>

Check failure on line 2 in benchmarks/benchmarks.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

benchmarks/benchmarks.cpp:2:10 [clang-diagnostic-error]

'benchmark/benchmark.h' file not found
#include <nuTens/propagator/const-density-solver.hpp>
#include <nuTens/propagator/propagator.hpp>
#include <nuTens/tensors/tensor.hpp>
Expand Down Expand Up @@ -97,7 +97,7 @@

// set up the propagator
Propagator matterProp(3, 100.0);
std::unique_ptr<BaseMatterSolver> matterSolver = std::make_unique<ConstDensityMatterSolver>(3, 2.6);
std::shared_ptr<BaseMatterSolver> matterSolver = std::make_shared<ConstDensityMatterSolver>(3, 2.6);
matterProp.setPMNS(PMNS);
matterProp.setMasses(masses);
matterProp.setMatterSolver(matterSolver);
Expand All @@ -113,10 +113,10 @@
}

// Register the function as a benchmark
BENCHMARK(BM_vacuumOscillations)->Name("Vacuum Oscillations")->Args({1 << 10, 1 << 10});

Check warning on line 116 in benchmarks/benchmarks.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

benchmarks/benchmarks.cpp:116:11 [cppcoreguidelines-avoid-non-const-global-variables]

variable 'BM_vacuumOscillations' is non-const and globally accessible, consider making it const

// Register the function as a benchmark
BENCHMARK(BM_constMatterOscillations)->Name("Const Density Oscillations")->Args({1 << 10, 1 << 10});

Check warning on line 119 in benchmarks/benchmarks.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

benchmarks/benchmarks.cpp:119:11 [cppcoreguidelines-avoid-non-const-global-variables]

variable 'BM_constMatterOscillations' is non-const and globally accessible, consider making it const

// Run the benchmark
BENCHMARK_MAIN();
1 change: 1 addition & 0 deletions nuTens/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
add_library(logging logging.hpp)
target_link_libraries(logging spdlog::spdlog)
set_target_properties(logging PROPERTIES LINKER_LANGUAGE CXX)
target_include_directories(logging PUBLIC "${SPDLOG_INCLUDE_DIRS}")

set( NT_LOG_LEVEL "INFO" CACHE STRING "the level of detail to log to the console" )

Expand Down
4 changes: 2 additions & 2 deletions nuTens/propagator/const-density-solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ void ConstDensityMatterSolver::calculateEigenvalues(const Tensor &energies, Tens
for (int j = 0; j < nGenerations; j++)
{
hamiltonian.setValue({"...", i, j},
Tensor::div(diagMassMatrix.getValue({i, j}), energies.getValue({"...", 0})) -
electronOuter.getValue({i, j}));
Tensor::div(diagMassMatrix.getValues({i, j}), energies.getValues({"...", 0})) -
electronOuter.getValues({i, j}));
}
}

Expand Down
7 changes: 4 additions & 3 deletions nuTens/propagator/const-density-solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@

// construct the outer product of the electron neutrino row of the PMNS
// matrix used to construct the hamiltonian
electronOuter = Tensor::scale(Tensor::outer(PMNS.getValue({0, 0, "..."}), PMNS.getValue({0, 0, "..."}).conj()),
Constants::Groot2 * density);
electronOuter =
Tensor::scale(Tensor::outer(PMNS.getValues({0, 0, "..."}), PMNS.getValues({0, 0, "..."}).conj()),
Constants::Groot2 * density);
};

/// @brief Set new mass eigenvalues for this solver
Expand All @@ -64,7 +65,7 @@

masses = newMasses;

Tensor m = masses.getValue({0, "..."});
Tensor m = masses.getValues({0, "..."});
Tensor diag = Tensor::scale(Tensor::mul(m, m), 0.5);

// construct the diagonal mass^2 matrix used in the hamiltonian
Expand All @@ -79,7 +80,7 @@
/// shape should look like {Nbatches, 1, 1}.
/// @param[out] eigenvectors The returned eigenvectors
/// @param[out] eigenvalues The corresponding eigenvalues
void calculateEigenvalues(const Tensor &energies, Tensor &eigenvectors, Tensor &eigenvalues);

Check warning on line 83 in nuTens/propagator/const-density-solver.hpp

View workflow job for this annotation

GitHub Actions / cpp-linter

nuTens/propagator/const-density-solver.hpp:83:10 [clang-diagnostic-inconsistent-missing-override]

'calculateEigenvalues' overrides a member function but is not marked 'override'

private:
Tensor PMNS;
Expand Down
2 changes: 1 addition & 1 deletion nuTens/propagator/propagator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Tensor Propagator::_calculateProbs(const Tensor &energies, const Tensor &massesS
{
for (int j = 0; j < _nGenerations; j++)
Copy link
Contributor

Choose a reason for hiding this comment

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

clang-tidy diagnostic

nuTens/propagator/propagator.cpp:45:23: error: [clang-diagnostic-error]

use of undeclared identifier 'c10'

const static std::map<c10::DeviceType, deviceType> invDeviceTypeMap = {{torch::kCPU, kCPU}, {torch::kCUDA, kGPU}};
                      ^

clang-tidy diagnostic

nuTens/propagator/propagator.cpp:45:73: error: [clang-diagnostic-error]

use of undeclared identifier 'torch'

const static std::map<c10::DeviceType, deviceType> invDeviceTypeMap = {{torch::kCPU, kCPU}, {torch::kCUDA, kGPU}};
                                                                        ^

clang-tidy diagnostic

nuTens/propagator/propagator.cpp:45:94: error: [clang-diagnostic-error]

use of undeclared identifier 'torch'

const static std::map<c10::DeviceType, deviceType> invDeviceTypeMap = {{torch::kCPU, kCPU}, {torch::kCUDA, kGPU}};
                                                                                             ^

clang-tidy diagnostic

nuTens/propagator/propagator.hpp:42:35: error: [clang-diagnostic-error]

use of undeclared identifier 'c10'

const static std::map<deviceType, c10::DeviceType> deviceTypeMap = {{kCPU, torch::kCPU}, {kGPU, torch::kCUDA}};
                                  ^

clang-tidy diagnostic

nuTens/propagator/propagator.hpp:42:76: error: [clang-diagnostic-error]

use of undeclared identifier 'torch'

const static std::map<deviceType, c10::DeviceType> deviceTypeMap = {{kCPU, torch::kCPU}, {kGPU, torch::kCUDA}};
                                                                           ^

clang-tidy diagnostic

nuTens/propagator/propagator.hpp:42:97: error: [clang-diagnostic-error]

use of undeclared identifier 'torch'

const static std::map<deviceType, c10::DeviceType> deviceTypeMap = {{kCPU, torch::kCPU}, {kGPU, torch::kCUDA}};
                                                                                                ^

clang-tidy diagnostic

nuTens/propagator/propagator.hpp:45:23: error: [clang-diagnostic-error]

use of undeclared identifier 'c10'

const static std::map<c10::DeviceType, deviceType> invDeviceTypeMap = {{torch::kCPU, kCPU}, {torch::kCUDA, kGPU}};
                      ^

clang-tidy diagnostic

nuTens/propagator/propagator.hpp:45:73: error: [clang-diagnostic-error]

use of undeclared identifier 'torch'

const static std::map<c10::DeviceType, deviceType> invDeviceTypeMap = {{torch::kCPU, kCPU}, {torch::kCUDA, kGPU}};
                                                                        ^

clang-tidy diagnostic

nuTens/propagator/propagator.hpp:45:94: error: [clang-diagnostic-error]

use of undeclared identifier 'torch'

const static std::map<c10::DeviceType, deviceType> invDeviceTypeMap = {{torch::kCPU, kCPU}, {torch::kCUDA, kGPU}};
                                                                                             ^

clang-tidy diagnostic

nuTens/tensors/dtypes.hpp:30:14: error: [clang-diagnostic-error]

use of undeclared identifier 'std'

const static std::map<scalarType, c10::ScalarType> scalarTypeMap = {{kFloat, torch::kFloat},
             ^

clang-tidy diagnostic

nuTens/tensors/dtypes.hpp:30:35: error: [clang-diagnostic-error]

use of undeclared identifier 'c10'

const static std::map<scalarType, c10::ScalarType> scalarTypeMap = {{kFloat, torch::kFloat},
                                  ^

clang-tidy diagnostic

nuTens/tensors/dtypes.hpp:30:78: error: [clang-diagnostic-error]

use of undeclared identifier 'torch'

const static std::map<scalarType, c10::ScalarType> scalarTypeMap = {{kFloat, torch::kFloat},
                                                                             ^

clang-tidy diagnostic

nuTens/tensors/dtypes.hpp:31:79: error: [clang-diagnostic-error]

use of undeclared identifier 'torch'

                                                                    {kDouble, torch::kDouble},
                                                                              ^

clang-tidy diagnostic

nuTens/tensors/dtypes.hpp:32:85: error: [clang-diagnostic-error]

use of undeclared identifier 'torch'

                                                                    {kComplexFloat, torch::kComplexFloat},
                                                                                    ^

clang-tidy diagnostic

nuTens/tensors/dtypes.hpp:33:86: error: [clang-diagnostic-error]

use of undeclared identifier 'torch'

                                                                    {kComplexDouble, torch::kComplexDouble}};
                                                                                     ^

clang-tidy diagnostic

nuTens/tensors/dtypes.hpp:36:14: error: [clang-diagnostic-error]

use of undeclared identifier 'std'

const static std::map<c10::ScalarType, scalarType> invScalarTypeMap = {{torch::kFloat, kFloat},
             ^

clang-tidy diagnostic

nuTens/tensors/dtypes.hpp:36:23: error: [clang-diagnostic-error]

use of undeclared identifier 'c10'

const static std::map<c10::ScalarType, scalarType> invScalarTypeMap = {{torch::kFloat, kFloat},
                      ^

clang-tidy diagnostic

nuTens/tensors/dtypes.hpp:36:73: error: [clang-diagnostic-error]

use of undeclared identifier 'torch'

const static std::map<c10::ScalarType, scalarType> invScalarTypeMap = {{torch::kFloat, kFloat},
                                                                        ^

clang-tidy diagnostic

nuTens/tensors/dtypes.hpp:37:73: error: [clang-diagnostic-error]

use of undeclared identifier 'torch'

                                                                       {torch::kDouble, kDouble},
                                                                        ^

clang-tidy diagnostic

nuTens/tensors/dtypes.hpp:38:73: error: [clang-diagnostic-error]

use of undeclared identifier 'torch'

                                                                       {torch::kComplexFloat, kComplexFloat},
                                                                        ^

clang-tidy diagnostic

nuTens/tensors/dtypes.hpp:39:73: error: [clang-diagnostic-error]

use of undeclared identifier 'torch'

                                                                       {torch::kComplexDouble, kComplexDouble}};
                                                                        ^

clang-tidy diagnostic

nuTens/tensors/dtypes.hpp:42:14: error: [clang-diagnostic-error]

use of undeclared identifier 'std'

const static std::map<deviceType, c10::DeviceType> deviceTypeMap = {{kCPU, torch::kCPU}, {kGPU, torch::kCUDA}};
             ^

clang-tidy diagnostic

nuTens/tensors/dtypes.hpp:42:35: error: [clang-diagnostic-error]

use of undeclared identifier 'c10'

const static std::map<deviceType, c10::DeviceType> deviceTypeMap = {{kCPU, torch::kCPU}, {kGPU, torch::kCUDA}};
                                  ^

clang-tidy diagnostic

nuTens/tensors/dtypes.hpp:42:76: error: [clang-diagnostic-error]

use of undeclared identifier 'torch'

const static std::map<deviceType, c10::DeviceType> deviceTypeMap = {{kCPU, torch::kCPU}, {kGPU, torch::kCUDA}};
                                                                           ^

clang-tidy diagnostic

nuTens/tensors/dtypes.hpp:42:97: error: [clang-diagnostic-error]

use of undeclared identifier 'torch'

const static std::map<deviceType, c10::DeviceType> deviceTypeMap = {{kCPU, torch::kCPU}, {kGPU, torch::kCUDA}};
                                                                                                ^

clang-tidy diagnostic

nuTens/tensors/dtypes.hpp:45:14: error: [clang-diagnostic-error]

use of undeclared identifier 'std'

const static std::map<c10::DeviceType, deviceType> invDeviceTypeMap = {{torch::kCPU, kCPU}, {torch::kCUDA, kGPU}};
             ^

clang-tidy diagnostic

nuTens/tensors/dtypes.hpp:45:23: error: [clang-diagnostic-error]

use of undeclared identifier 'c10'

const static std::map<c10::DeviceType, deviceType> invDeviceTypeMap = {{torch::kCPU, kCPU}, {torch::kCUDA, kGPU}};
                      ^

clang-tidy diagnostic

nuTens/tensors/dtypes.hpp:45:73: error: [clang-diagnostic-error]

use of undeclared identifier 'torch'

const static std::map<c10::DeviceType, deviceType> invDeviceTypeMap = {{torch::kCPU, kCPU}, {torch::kCUDA, kGPU}};
                                                                        ^

clang-tidy diagnostic

nuTens/tensors/tensor.hpp:42:35: error: [clang-diagnostic-error]

use of undeclared identifier 'c10'

const static std::map<deviceType, c10::DeviceType> deviceTypeMap = {{kCPU, torch::kCPU}, {kGPU, torch::kCUDA}};
                                  ^

clang-tidy diagnostic

nuTens/tensors/tensor.hpp:42:76: error: [clang-diagnostic-error]

use of undeclared identifier 'torch'

const static std::map<deviceType, c10::DeviceType> deviceTypeMap = {{kCPU, torch::kCPU}, {kGPU, torch::kCUDA}};
                                                                           ^

clang-tidy diagnostic

nuTens/tensors/tensor.hpp:42:97: error: [clang-diagnostic-error]

use of undeclared identifier 'torch'

const static std::map<deviceType, c10::DeviceType> deviceTypeMap = {{kCPU, torch::kCPU}, {kGPU, torch::kCUDA}};
                                                                                                ^

clang-tidy diagnostic

nuTens/tensors/tensor.hpp:45:23: error: [clang-diagnostic-error]

use of undeclared identifier 'c10'

const static std::map<c10::DeviceType, deviceType> invDeviceTypeMap = {{torch::kCPU, kCPU}, {torch::kCUDA, kGPU}};
                      ^

clang-tidy diagnostic

nuTens/tensors/tensor.hpp:45:73: error: [clang-diagnostic-error]

use of undeclared identifier 'torch'

const static std::map<c10::DeviceType, deviceType> invDeviceTypeMap = {{torch::kCPU, kCPU}, {torch::kCUDA, kGPU}};
                                                                        ^

clang-tidy diagnostic

nuTens/tensors/tensor.hpp:45:94: error: [clang-diagnostic-error]

use of undeclared identifier 'torch'

const static std::map<c10::DeviceType, deviceType> invDeviceTypeMap = {{torch::kCPU, kCPU}, {torch::kCUDA, kGPU}};
                                                                                             ^

clang-tidy diagnostic

nuTens/tensors/torch-tensor.cpp:30:35: error: [clang-diagnostic-error]

use of undeclared identifier 'c10'

const static std::map<scalarType, c10::ScalarType> scalarTypeMap = {{kFloat, torch::kFloat},
                                  ^

clang-tidy diagnostic

nuTens/tensors/torch-tensor.cpp:30:78: error: [clang-diagnostic-error]

use of undeclared identifier 'torch'

const static std::map<scalarType, c10::ScalarType> scalarTypeMap = {{kFloat, torch::kFloat},
                                                                             ^

clang-tidy diagnostic

nuTens/tensors/torch-tensor.cpp:31:79: error: [clang-diagnostic-error]

use of undeclared identifier 'torch'

                                                                    {kDouble, torch::kDouble},
                                                                              ^

clang-tidy diagnostic

nuTens/tensors/torch-tensor.cpp:32:85: error: [clang-diagnostic-error]

use of undeclared identifier 'torch'

                                                                    {kComplexFloat, torch::kComplexFloat},
                                                                                    ^

clang-tidy diagnostic

nuTens/tensors/torch-tensor.cpp:33:86: error: [clang-diagnostic-error]

use of undeclared identifier 'torch'

                                                                    {kComplexDouble, torch::kComplexDouble}};
                                                                                     ^

clang-tidy diagnostic

nuTens/tensors/torch-tensor.cpp:38:73: error: [clang-diagnostic-error]

use of undeclared identifier 'torch'

                                                                       {torch::kComplexFloat, kComplexFloat},
                                                                        ^

clang-tidy diagnostic

nuTens/tensors/torch-tensor.cpp:39:73: error: [clang-diagnostic-error]

use of undeclared identifier 'torch'

                                                                       {torch::kComplexDouble, kComplexDouble}};
                                                                        ^

clang-tidy diagnostic

nuTens/tensors/torch-tensor.cpp:42:35: error: [clang-diagnostic-error]

use of undeclared identifier 'c10'

const static std::map<deviceType, c10::DeviceType> deviceTypeMap = {{kCPU, torch::kCPU}, {kGPU, torch::kCUDA}};
                                  ^

clang-tidy diagnostic

nuTens/tensors/torch-tensor.cpp:42:76: error: [clang-diagnostic-error]

use of undeclared identifier 'torch'

const static std::map<deviceType, c10::DeviceType> deviceTypeMap = {{kCPU, torch::kCPU}, {kGPU, torch::kCUDA}};
                                                                           ^

clang-tidy diagnostic

nuTens/tensors/torch-tensor.cpp:42:97: error: [clang-diagnostic-error]

use of undeclared identifier 'torch'

const static std::map<deviceType, c10::DeviceType> deviceTypeMap = {{kCPU, torch::kCPU}, {kGPU, torch::kCUDA}};
                                                                                                ^

clang-tidy diagnostic

nuTens/tensors/torch-tensor.cpp:45:23: error: [clang-diagnostic-error]

use of undeclared identifier 'c10'

const static std::map<c10::DeviceType, deviceType> invDeviceTypeMap = {{torch::kCPU, kCPU}, {torch::kCUDA, kGPU}};
                      ^

clang-tidy diagnostic

nuTens/tensors/torch-tensor.cpp:45:73: error: [clang-diagnostic-error]

use of undeclared identifier 'torch'

const static std::map<c10::DeviceType, deviceType> invDeviceTypeMap = {{torch::kCPU, kCPU}, {torch::kCUDA, kGPU}};
                                                                        ^

clang-tidy diagnostic

nuTens/tensors/torch-tensor.cpp:45:94: error: [clang-diagnostic-error]

use of undeclared identifier 'torch'

const static std::map<c10::DeviceType, deviceType> invDeviceTypeMap = {{torch::kCPU, kCPU}, {torch::kCUDA, kGPU}};
                                                                                             ^

clang-tidy diagnostic

python/pyNuTens.cpp:22:1: warning: [cppcoreguidelines-avoid-non-const-global-variables]

variable 'pybind11_module_def_pyNuTens' is non-const and globally accessible, consider making it const

PYBIND11_MODULE(pyNuTens, m)
^
/home/runner/.local/lib/python3.10/site-packages/torch/include/pybind11/detail/common.h:392:44: note: expanded from macro 'PYBIND11_MODULE'
    static ::pybind11::module_::module_def PYBIND11_CONCAT(pybind11_module_def_, name)            \
                                           ^
/home/runner/.local/lib/python3.10/site-packages/torch/include/pybind11/detail/common.h:312:40: note: expanded from macro 'PYBIND11_CONCAT'
#define PYBIND11_CONCAT(first, second) first##second
                                       ^
note: expanded from here

clang-tidy diagnostic

python/pyNuTens.cpp:22:1: warning: [cppcoreguidelines-pro-bounds-pointer-arithmetic]

do not use pointer arithmetic

PYBIND11_MODULE(pyNuTens, m)
^
/home/runner/.local/lib/python3.10/site-packages/torch/include/pybind11/detail/common.h:397:9: note: expanded from macro 'PYBIND11_MODULE'
        PYBIND11_CHECK_PYTHON_VERSION                                                             \
        ^
/home/runner/.local/lib/python3.10/site-packages/torch/include/pybind11/detail/common.h:322:17: note: expanded from macro 'PYBIND11_CHECK_PYTHON_VERSION'
            || (runtime_ver[len] >= '0' && runtime_ver[len] <= '9')) {                            \
                ^

clang-tidy diagnostic

tests/tensor-basic.cpp:31:79: error: [clang-diagnostic-error]

use of undeclared identifier 'torch'

                                                                    {kDouble, torch::kDouble},
                                                                              ^

clang-tidy diagnostic

tests/tensor-basic.cpp:32:85: error: [clang-diagnostic-error]

use of undeclared identifier 'torch'

                                                                    {kComplexFloat, torch::kComplexFloat},
                                                                                    ^

clang-tidy diagnostic

tests/tensor-basic.cpp:33:86: error: [clang-diagnostic-error]

use of undeclared identifier 'torch'

                                                                    {kComplexDouble, torch::kComplexDouble}};
                                                                                     ^

clang-tidy diagnostic

tests/tensor-basic.cpp:36:14: error: [clang-diagnostic-error]

use of undeclared identifier 'std'

const static std::map<c10::ScalarType, scalarType> invScalarTypeMap = {{torch::kFloat, kFloat},
             ^

clang-tidy diagnostic

tests/tensor-basic.cpp:36:23: error: [clang-diagnostic-error]

use of undeclared identifier 'c10'

const static std::map<c10::ScalarType, scalarType> invScalarTypeMap = {{torch::kFloat, kFloat},
                      ^

clang-tidy diagnostic

tests/tensor-basic.cpp:36:73: error: [clang-diagnostic-error]

use of undeclared identifier 'torch'

const static std::map<c10::ScalarType, scalarType> invScalarTypeMap = {{torch::kFloat, kFloat},
                                                                        ^

{
weightMatrix.setValue({"...", i, j}, weightVector.getValue({"...", j}));
weightMatrix.setValue({"...", i, j}, weightVector.getValues({"...", j}));
}
}
weightMatrix.requiresGrad(true);
Expand Down
4 changes: 2 additions & 2 deletions nuTens/propagator/propagator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Propagator

/// @brief Set a matter solver to use to deal with matter effects
/// @param newSolver A derivative of BaseMatterSolver
inline void setMatterSolver(std::unique_ptr<BaseMatterSolver> &newSolver)
inline void setMatterSolver(std::shared_ptr<BaseMatterSolver> &newSolver)
{
NT_PROFILE();
_matterSolver = std::move(newSolver);
Expand Down Expand Up @@ -113,5 +113,5 @@ class Propagator
int _nGenerations;
float _baseline;

std::unique_ptr<BaseMatterSolver> _matterSolver;
std::shared_ptr<BaseMatterSolver> _matterSolver;
};
2 changes: 2 additions & 0 deletions nuTens/tensors/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ IF(NT_USE_PCH)
target_link_libraries(tensor PUBLIC nuTens-pch)

ELSE()
target_link_libraries(tensor PUBLIC logging)

IF(TORCH_FOUND)

target_link_libraries(tensor PUBLIC "${TORCH_LIBRARIES}")
Expand Down
27 changes: 26 additions & 1 deletion nuTens/tensors/dtypes.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#pragma once

#if USE_PYTORCH
#include <torch/torch.h>
#endif

/*!
* @file dtypes.hpp
* @brief Defines various datatypes used in the project
Expand All @@ -16,13 +20,34 @@ enum scalarType
kDouble,
kComplexFloat,
kComplexDouble,
kUninitScalar,
};

/// Devices that a Tensor can live on
enum deviceType
{
kCPU,
kGPU
kGPU,
kUninitDevice,
};

#if USE_PYTORCH
/// map between the data types used in nuTens and those used by pytorch
const static std::map<scalarType, c10::ScalarType> scalarTypeMap = {{kFloat, torch::kFloat},
{kDouble, torch::kDouble},
{kComplexFloat, torch::kComplexFloat},
{kComplexDouble, torch::kComplexDouble}};

/// inverse map between the data types used in nuTens and those used by pytorch
const static std::map<c10::ScalarType, scalarType> invScalarTypeMap = {{torch::kFloat, kFloat},
{torch::kDouble, kDouble},
{torch::kComplexFloat, kComplexFloat},
{torch::kComplexDouble, kComplexDouble}};

// map between the device types used in nuTens and those used by pytorch
const static std::map<deviceType, c10::DeviceType> deviceTypeMap = {{kCPU, torch::kCPU}, {kGPU, torch::kCUDA}};

// inverse map between the device types used in nuTens and those used by pytorch
const static std::map<c10::DeviceType, deviceType> invDeviceTypeMap = {{torch::kCPU, kCPU}, {torch::kCUDA, kGPU}};
#endif
} // namespace NTdtypes
Loading
Loading