Upgrading from 2.x

In Pymanopt 3.0, backends provide the arithmetic of manifolds in addition to derivatives, so manifolds compute with the backend’s arrays instead of NumPy arrays. The backend decorators and the APIs of pymanopt.core.problem.Problem and the optimizers are unchanged.

  1. The pymanopt.autodiff package was removed. The Function class moved to pymanopt.function, and backends to pymanopt.backends.

  2. Python. Pymanopt requires Python 3.11 or later.

  3. Results are backend arrays. Optimizers no longer convert points to NumPy arrays, e.g. result.point is a torch.Tensor with PyTorch.

    point = result.point  # 2.x
    point = result.point.numpy()  # 3.0
    
  4. Inputs are backend arrays. An initial_point passed to an optimizer must be an array of the backend, and so should constants used in the cost function.

  5. Manifolds used outside of a problem need a backend. This affects, among others, random_point and pymanopt.tools.diagnostics.check_retraction().

    manifold = Sphere(3)  # 2.x
    manifold = Sphere(3, backend=NumpyBackend())  # 3.0
    
  6. Complex manifolds expect a complex data type. Otherwise a warning is emitted.

    @pymanopt.function.jax(manifold, dtype=JaxBackend.DEFAULT_COMPLEX_DTYPE())
    def cost(point): ...
    
  7. Custom manifolds. Replace NumPy calls by calls to self.backend, e.g. np.cos by self.backend.cos, and accept a backend argument that is forwarded to the base class constructor.

  8. Custom backends. Backends now implement the interface of pymanopt.backends.backend.Backend, which adds data type handling and the numerical functions used by manifolds. The is_available and prepare_function methods were removed. backend_decorator_factory(backend_cls) was replaced by pymanopt.function.decorator_factory(), which takes the module and class names of the backend.