GSoC’23 - GNU Octave: Project Completion

GSoC
Code
Internship
GNU Octave
Author

Vipul Cariappa

Published

August 27, 2023

Project Overview

My project focused on improving the state of the octave-pythonic package of Octave. Octave-Pythonic provides support to use/call Python functions, modules and classes from within Octave REPL. Octave-Pythonic aims to be MATLAB compatible.

My goal for the project was to fix bugs, add in many of the missing features, support the latest version of Python and fix issues related to using Octave-Pythonic on Windows.

Overview of the Work Done

Some of the work mentioned below is not merged into the main branch of the project. I will try and update this blog post when they eventually get merged. Please look at the end for any new updates.

  • The Octave-Pythonic repository was initially hosted and maintained by a single person. We moved the repository under the GNU Octave project on GitLab.

  • Octave-Pythonic supported Python version up to 3.9. Now it has been updated to support the latest Python version 3.11. During this change, we also dropped support to Python 2 and Python versions less than 3.7 (Link to closed Merge Request).

  • The CI/CD pipeline on GitLab was updated to use the official Docker image hosted by GNU Octave for testing. We are running our test suit against multiple versions of Python and multiple versions of Octave to ensure proper support. We could not implement automated testing on Windows by the end of GSoC. There were multiple issues we faced with Windows (Link to closed Merge Request).

  • I have provided a proof of concept for pyimport command. pyimport lets the user import Python functions, classes, modules and namespaces into the Octave REPL. The proof of concept was appreciated by was not merged because MATLAB does not offer any similar mechanism (Link to the implementation).

  • I have provided a proof of concept of a wrapper around Octave objects so that they can be used within the Python interpreter. The main idea is to use a single object within both the interpreters without any copies. I managed to get the basic idea working. But this feature breaks compatibility with MATLAB, so the changes are not merged (Link to the implementation).

  • Support performing arithmetic and other operations on Python objects (Link to open Merge Request. Not yet merged).

  • Improvement to Windows compatibility.

    • I found the main cause of the failing installation of Octave-Pythonic on Windows. On Windows, Octave bundles its own version of Python. That version is a minimal version that cannot be used to build Python packages. This has now been documented and updated instruction to install Octave-Pythonic on Windows is available (Link to closed Merge Request).

    • We could not get the automated testing on GitLab pipelines working to test Octave-Pythonic on Windows. At present, we manage to get Octave installed, but for some reason, it looks like it does not do anything (Link to open Merge Request. Not yet merged).

  • Python Objects were not freed from memory after its use. This is fixed and implemented (Link to open Merge Request. Not yet merged).

  • Verification of existing issues on the Octave interpreter which needs to be fixed to be used in Pythonic (The following are the ones that still require work).

    • Support to access dict items
      We can access elements from dict using dict_name{"key"}, but assigning elements using dict_name{"key"} = value gives a syntax error.

    • Function handles to Python functions, bound methods, or other callable objects
      We can not create any handles to Python objects. It may require detection of the usage of @ within the pyobject, which cannot be done as of now. There may also be some other way to implement it.

    • Python objects can’t be loaded or saved using the Octave load and save commands
      We are waiting for HDF5 file I/O support in Octave to implement this functionality. Currently, Octave does not support HDF5 file I/O.

    • Stack trace is not returned on error
      This required the implementation of MException. Which is not implemented.

    • Iterating through Python object using for loop
      This will again require support from the Octave interpreter to implement some kind of mechanism to iterate over classdef object.

  • We have implemented pyenv function. pyenv is a MATLAB compatible function used to select a Python version to use when using Octave-Pythonic (Link to open Merge Request. Not yet merged).

  • We have added in new page on the Pythonic Wiki page with reference API documentation.

  • We created multiple releases. The release v0.1.3 was done by me.

Other things I worked on during GSoC

These include bug reports and other contributions to the GNU Octave project directly or other affiliated projects.