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

Add Rust bindings #559

Open
calcmogul opened this issue Jun 14, 2024 · 2 comments
Open

Add Rust bindings #559

calcmogul opened this issue Jun 14, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@calcmogul
Copy link
Member

calcmogul commented Jun 14, 2024

This would make it possible for Choreo to call the solver directly in Tauri.

Use Jormungandr as a reference for what to bind. Instead of NumPy, use nalgebra.

We need to be able to overload the math operators (see https://doc.rust-lang.org/core/ops/) for various combinations of:

  • double
  • int
  • Variable
  • VariableMatrix
  • VariableBlock

We also need to overload the equality operator to return a constraint object instead of bool; and overload the comparison operators to return a constraint object instead of Ordering. If that's not possible, provide the following:

  • Constraints::eq(lhs, rhs)
  • Constraints::lt(lhs, rhs)
  • Constraints::le(lhs, rhs)
  • Constraints::gt(lhs, rhs)
  • Constraints::ge(lhs, rhs)
@calcmogul calcmogul added the enhancement New feature or request label Jun 14, 2024
@BBScholar
Copy link

BBScholar commented Jun 14, 2024

Not sure if there's an alternative method, but I'm pretty sure rust's bindgen won't play nicely with Sleipnir. More specifically, bindgen does not handle templated functions or methods of templated classes.

See here: https://rust-lang.github.io/rust-bindgen/cpp.html#unsupported-features

@calcmogul
Copy link
Member Author

calcmogul commented Jun 14, 2024

Neither did pybind11 when I wrote the Python bindings, because templates are... templates for creating classes/functions, not classes/functions themselves. What you have to do is create specific instantiations, then wrap those. That happened transparently in pybind11:

void BindVariableBlock(py::module_& autodiff,
                       py::class_<VariableBlock<VariableMatrix>>& cls) {
  ...
  cls.def(
      "set_value",
      [](VariableBlock<VariableMatrix>& self, double value) {
        self.SetValue(value);
      },
      "value"_a, DOC(sleipnir, VariableBlock, SetValue));

The bindgen docs saying it doesn't support inline functions is concerning, because every function in Sleipnir is inline. We export them from the DLL, so I don't see why it shouldn't be able to link to and use them like pybind11 can.

Not calling destructors is also super wack, cuz destructors are the bread-and-butter of C++ (and Rust).

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

No branches or pull requests

2 participants