Skip to content

Feature/python#168

Open
Chrisgant wants to merge 38 commits intodevelfrom
feature/Python
Open

Feature/python#168
Chrisgant wants to merge 38 commits intodevelfrom
feature/Python

Conversation

@Chrisgant
Copy link
Copy Markdown
Collaborator

The python interface is now at a point where we can completely generate MarkovChains from python. The purpose of this new feature is simplification of the workflow and accessibility to non power users.

The interface includes exposed classes and functions for:

  • Lattices
  • Actions
  • Integrators
  • MarkovState
  • HMC

And type casters:

  • dict <-> NSL::Parameters
  • torch.device <-> NSL::Device
  • torch.tensor <-> Torch::Tensor
  • dict <-> NSL::Configuration
  • string <-> YAML
  • string <-> H5Node

An example can be found here.

Due to the amount of templates in our C++ code, some type specifications/simplifications were necessary.

@Chrisgant Chrisgant added the enhancement New feature or request label Apr 17, 2024
This was referenced May 7, 2024
Comment thread CMakeLists.txt

add_subdirectory(Documentation EXCLUDE_FROM_ALL)

add_subdirectory(Python) No newline at end of file
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Add CMake option to turn off Python binding

Comment thread Executables/Examples/example_param.yml
Comment thread Python/CMakeLists.txt
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

make install should move library to system directory @GioPede

Comment thread Python/bindConfiguration.cpp Outdated

// Conversion from Python to C++
bool load(handle src, bool) {
if (!isinstance<dict>(src)) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

should this be be py::dict?

Comment thread Python/bindConfiguration.cpp Outdated
static handle cast(const Configuration<Type>& src, return_value_policy policy, handle parent) {
py::dict out_dict;
for (const auto& item : src) {
out_dict[item.first.c_str()] = py::cast(item.second, policy, parent);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

check if c_str() is necessary, check that utf-8 is supported

Comment thread Python/bindAction.cpp Outdated
}

class SumAction : public NSL::Action::BaseAction<NSL::complex<double>, NSL::complex<double>>{
py::args _baseActionList;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

private block at end of class

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Consider rewriting the NSL::Action in a similar way to get rid of the variadic template

Comment thread Python/bindTensor.cpp
}
}

#define STRINGIFY(x) #x
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Delete Macro at end of file

Comment thread Python/bindTensor.cpp
});
}

void bindTensor(py::module &m) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Check if this is still used

@@ -39,5 +39,31 @@ class Integrator{
NSL::Action::Action<ActionTermTypes...> action_;
};

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

See comment about Action

Comment thread Python/bindIntegrator.cpp Outdated
.def("__call__", [](NSL::Integrator::Leapfrog<NSL::Python::SumAction> &integrator, py::args args){
if (args.size() == 1){
throw std::runtime_error("Invalid number of arguments");
} else if (args.size() == 2){
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

make this !=2 ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants