Not working on Octave.

34 views
Skip to first unread message

Dr. Feeroz Babu

unread,
Nov 22, 2020, 2:24:42 AM11/22/20
to Manopt
Hi,
Prof. Nicolas

I am really interested to know how to see optimization on manifolds in Matlab or Octave. Finally I found you. I am finding some difficulties to run your codes in Octave. Kindly let me know how it will work on Octave.

  

Nicolas Boumal

unread,
Nov 22, 2020, 8:30:40 AM11/22/20
to Manopt
Hello,

Unfortunately, Manopt is not compatible with Octave. This is because certain features of Matlab regarding function handles and nested functions are not available in Octave, and those features are used intensively in the Manopt code base. I regularly check if newer versions of Octave have bridged this feature gap, but unfortunately this has not happened so far (there is a ticket open to that effect on Octave's side for many years now, but this is not a priority for their development team).

If Matlab is not an option, you may be interested in checking out the Python and Julia versions of Manopt, both available from the www.manopt.org website.

Best,
Nicolas

Nicolas Boumal

unread,
Jan 2, 2021, 11:00:46 AM1/2/21
to Manopt
Hello again,

Octave 6.1.0 came out, and it now supports nested functions! Support is note quite identical to Matlab's (there are differences for variables being defined outside the scope of nested functions, which leads to a number of issues), but at least the main path toward compatibility with Octave is now open.

The script in checkinstall runs without a hitch in Octave.

However, most examples in the examples/ folder run into some kind of trouble. It is quite possible that most of those issues can now be fixed. If this is something you explore, please feel free to send pull requests to the manopt GitHub repository: https://github.com/NicolasBoumal/manopt

Best wishes for the new year,
Nicolas

Nicolas Boumal

unread,
Jan 2, 2021, 11:31:50 AM1/2/21
to Manopt
Upon closer inspection, I see that tools such as productmanifold and powermanifold make heavy use of variables defined outside of nested subfunctions (specifically, see 'elems' and 'nelems' defined on lines 49-50 in productmanifold.m, as well as 'elements' which is an input of the mother function). It may require substantial changes to the code to get Octave compatibility here, and those changes would likely make the code harder to maintain. I welcome ideas for how to mitigate these issues.

On the bright side, the fact that basicexample.m works indicates that most core features of Manopt are already compatible, and that trustregions (arguably the main solver) and checkgradient + checkhessian are too. This should be penty enough for basic use of Manopt in the classroom for example.

Nicolas Boumal

unread,
Jan 4, 2021, 8:58:46 AM1/4/21
to Manopt
After discussions with Pierre-Antoine, here is a more precise highlight of a difference between nested function handles in Octave 6.1.0 and Matlab.

The following code works as expected both in Matlab and in Octave 6.1.0:


% Define this in main_610.m
function f = main_610(x)
    f = @fun;
    function y = fun()
        y = x;
    end
end
% Run this:
f = main_610(5); f()  % both systems display 5, as intended.


However, the following succeeds in Matlab and fails in Octave 6.1.0 (error: "z undefined")

% Define this in main_610.m
function f = main_610(x)
    z = 2*x;
    f = @fun;
    function y = fun()
        y = z; % fails in Octave 6.1.0 because the subfunction doesn't 'see' z; it sees x though.
    end
end
% Run this:
f = main_610(5); f()  % Matlab displays 10; Octave 6.1.0 throws an error.

Based on this, here is a possible conclusion regarding Octave 6.1.0: nested subfunctions can see the inputs of the mother function, but they cannot see other variables created within the mother function.

For productmanifold and powermanifold, this suggests that a possible way out is to copy/past the definitions of elems and nelems in all subfunctions... Not exactly an elegant solution (and we may need to do this in very many other places), but it wouldn't be too hard.

Perhaps Octave offers other ways to handle this (for example, a way to "tell" Octave that elems and nelems are "static"; or perhaps automatic detection of the static nature of such variables is on the feature list for futur releases). If anyone knows, please post here.

Best,
Nicolas

Nicolas Boumal

unread,
Jan 4, 2021, 10:36:17 AM1/4/21
to Manopt
The tools powermanifold and productmanifold are now compatible with Octave.

Luckily, this was doable with relatively small changes to the code. For productmanifold for example, the trick is to introduce a "helper" function: the helper is the actual factory; it gets called by the user-facing factory which does all necessary pre-computations, then passes them on to the helper as explicit inputs. This way, Octave is happy to refer to those inputs in nested subfunctions. This also means that there was no need to duplicate code.

I pushed a number of other changes that make more examples compatible with Octave and should provide pointers for users who want to extend Octave compatibility: look for commits in the manopt github repo that have the word "Octave" in the message, dating around January 2021.
Reply all
Reply to author
Forward
0 new messages