From 0805fa1b6e601a0f0bc21f82c0db2809b9d28559 Mon Sep 17 00:00:00 2001 From: Anton Lee Date: Fri, 13 Feb 2026 13:09:46 +1300 Subject: [PATCH] docs: improve homepages --- README.md | 56 ++++++----- docs/api/index.rst | 10 +- docs/conf.py | 1 + docs/contributing/code_review.md | 2 +- docs/contributing/faq.md | 2 +- docs/contributing/git.md | 2 +- docs/contributing/tests.md | 2 +- docs/contributing/update_moa.md | 2 +- docs/index.rst | 147 ++++++++++----------------- docs/installation.rst | 168 ------------------------------- docs/setup/developer.rst | 92 +++++++++++++++++ docs/{ => setup}/docker.md | 4 +- docs/setup/index.rst | 120 ++++++++++++++++++++++ pyproject.toml | 2 + src/capymoa/_prepare_jpype.py | 10 +- tests/test_import.py | 9 +- 16 files changed, 328 insertions(+), 301 deletions(-) delete mode 100644 docs/installation.rst create mode 100644 docs/setup/developer.rst rename docs/{ => setup}/docker.md (97%) create mode 100644 docs/setup/index.rst diff --git a/README.md b/README.md index 6137b10e4..109039e43 100644 --- a/README.md +++ b/README.md @@ -1,38 +1,48 @@ # [CapyMOA](https://capymoa.org) -![Banner Image](https://github.com/adaptive-machine-learning/CapyMOA/raw/main/docs/images/CapyMOA.jpeg) +[![Link to PyPI](https://img.shields.io/pypi/v/capymoa)](https://pypi.org/project/capymoa/) +[![image](https://coveralls.io/repos/github/adaptive-machine-learning/CapyMOA/badge.svg?branch=main)](https://coveralls.io/github/adaptive-machine-learning/CapyMOA?branch=main) +[![Link to Discord](https://img.shields.io/discord/1235780483845984367?label=Discord)](https://discord.gg/spd2gQJGAb) +[![Link to GitHub](https://img.shields.io/github/stars/adaptive-machine-learning/CapyMOA?style=flat)](https://github.com/adaptive-machine-learning/CapyMOA) +[![Docker Image Version (tag)](https://img.shields.io/docker/v/tachyonic/jupyter-capymoa/latest?logo=docker&label=Docker&color=blue)](https://hub.docker.com/r/tachyonic/jupyter-capymoa) -[![PyPi Version](https://img.shields.io/pypi/v/capymoa)](https://pypi.org/project/capymoa/) -[![Join the Discord](https://img.shields.io/discord/1235780483845984367?label=Discord)](https://discord.gg/spd2gQJGAb) -[![Documentation](https://img.shields.io/badge/docs-latest-blue)](https://capymoa.org) -[![GitHub](https://img.shields.io/github/stars/adaptive-machine-learning/CapyMOA?style=social)](https://github.com/adaptive-machine-learning/CapyMOA) +**CapyMOA does efficient machine learning for data streams in Python.** +A data stream is a sequences of items ariving one-by-one that is too +large to efficiently process non-sequentially. CapyMOA is a toolbox of +methods and evaluators for: classification, regression, clustering, +anomaly detection, semi-supervised learning, online continual learning, +and drift detection for data streams. -Machine learning library tailored for data streams. Featuring a Python API -tightly integrated with MOA (**Stream Learners**), PyTorch (**Neural -Networks**), and scikit-learn (**Machine Learning**). CapyMOA provides a -**fast** python interface to leverage the state-of-the-art algorithms in the -field of data streams. +For the default PyTorch CUDA GPU installation, run: -To setup CapyMOA, simply install it via pip. If you have any issues with the -installation (like not having Java installed) or if you want GPU support, please -refer to the [installation guide](https://capymoa.org/installation). Once installed take a -look at the [tutorials](https://capymoa.org/tutorials.html) to get started. +``` +pip install capymoa +``` -```bash -# CapyMOA requires Java. This checks if you have it installed -java -version +Refer to the [Setup](https://capymoa.org/setup) guide for other options, +including CPU-only and dev dependencies. -# CapyMOA requires PyTorch. This installs the CPU version -pip install torch torchvision --index-url https://download.pytorch.org/whl/cpu +```python +from capymoa.datasets import Electricity +from capymoa.classifier import HoeffdingTree +from capymoa.evaluation import prequential_evaluation -# Install CapyMOA and its dependencies -pip install capymoa +# 1. Load a streaming dataset +stream = Electricity() -# Check that the install worked -python -c "import capymoa; print(capymoa.__version__)" +# 2. Create a machine learning model +model = HoeffdingTree(stream.get_schema()) + +# 3. Run with test-then-train evaluation +results = prequential_evaluation(stream, model) + +# 3. Success! +print(f"Accuracy: {results.accuracy():.2f}%") ``` +Next, we recomend the [Tutorials](https://capymoa.org/tutorials). + > **âš ī¸ WARNING** > > CapyMOA is still in the early stages of development. The API is subject to diff --git a/docs/api/index.rst b/docs/api/index.rst index 72050cd7d..ee0065ce3 100644 --- a/docs/api/index.rst +++ b/docs/api/index.rst @@ -88,4 +88,12 @@ Functions --------- .. automodule:: capymoa - :members: \ No newline at end of file + :members: + + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` \ No newline at end of file diff --git a/docs/conf.py b/docs/conf.py index 1d3a0d842..df5bb0f2a 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -108,6 +108,7 @@ html_theme = "pydata_sphinx_theme" html_static_path = ["_static"] html_css_files = ["css/citation.css"] +html_show_sourcelink = False # Setup symbolic links for notebooks diff --git a/docs/contributing/code_review.md b/docs/contributing/code_review.md index 826f76412..8df71c986 100644 --- a/docs/contributing/code_review.md +++ b/docs/contributing/code_review.md @@ -17,7 +17,7 @@ This document describes the code review process for CapyMOA. It is intended for ## Commit Messages -**tldr; Run `python -m invoke commit` (or `invoke commit`, `python -m commitizen commit`) to commit changes.** (Requires that you've [installed the optional development dependencies](../installation.rst).) +**tldr; Run `python -m invoke commit` (or `invoke commit`, `python -m commitizen commit`) to commit changes.** (Requires that you've [installed the optional development dependencies](../setup/developer.rst).) CapyMOA uses conventional commit messages to streamline the release process. diff --git a/docs/contributing/faq.md b/docs/contributing/faq.md index fdd823adc..e2a36f946 100644 --- a/docs/contributing/faq.md +++ b/docs/contributing/faq.md @@ -89,7 +89,7 @@ If a check fails, review the error messages and try to reproduce the issue local ## How do I format my code? `invoke fmt` will format and check your code using `ruff`. Ruff is installed as part of -the [development dependencies](../installation.rst). Formatting helps make diff reviews +the [development dependencies](../setup/developer.rst). Formatting helps make diff reviews easier and keeps the codebase consistent. ## How do I write a commit message? diff --git a/docs/contributing/git.md b/docs/contributing/git.md index d6d17f2d1..fac3e86cb 100644 --- a/docs/contributing/git.md +++ b/docs/contributing/git.md @@ -69,7 +69,7 @@ git status git commit -m "My message" ``` -* Refer to the [installation guide](../installation.rst) to set up your development +* Refer to the [installation guide](../setup/developer.rst) to set up your development environment. ### 5. Upload Your Changes to Your Fork diff --git a/docs/contributing/tests.md b/docs/contributing/tests.md index 2f435af94..6c45619e6 100644 --- a/docs/contributing/tests.md +++ b/docs/contributing/tests.md @@ -1,7 +1,7 @@ # Adding Tests Ensure you have installed the development dependencies by following the instructions -in the [installation guide](../installation.rst). To run all tests, use the following command: +in the [installation guide](../setup/developer.rst). To run all tests, use the following command: ```bash invoke test diff --git a/docs/contributing/update_moa.md b/docs/contributing/update_moa.md index a77f80c01..c621c20aa 100644 --- a/docs/contributing/update_moa.md +++ b/docs/contributing/update_moa.md @@ -5,7 +5,7 @@ project uses. **It is only intended for developers who are contributing to CapyMOA**. Before you start, make sure you have the following: * You have installed the development dependencies and have an editable install - of CapyMOA. If you have not, follow the instructions in the [installation guide](../installation.rst). + of CapyMOA. If you have not, follow the instructions in the [installation guide](../setup/developer.rst). * You must **NOT** have set the environment variables that would override the default `moa.jar` location. `CAPYMOA_MOA_JAR` must be unset. diff --git a/docs/index.rst b/docs/index.rst index dde4b134d..e82baa226 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -1,8 +1,11 @@ -.. CapyMOA documentation master file, created by - sphinx-quickstart on Fri Feb 23 08:41:28 2024. - You can adapt this file completely to your liking, but it should at least - contain the root `toctree` directive. +.. toctree:: + :hidden: + setup/index + tutorials + api/index + about + contributing/index CapyMOA ======= @@ -13,6 +16,9 @@ CapyMOA .. image:: https://img.shields.io/pypi/v/capymoa :target: https://pypi.org/project/capymoa/ :alt: Link to PyPI + +.. image:: https://coveralls.io/repos/github/adaptive-machine-learning/CapyMOA/badge.svg?branch=main + :target: https://coveralls.io/github/adaptive-machine-learning/CapyMOA?branch=main .. image:: https://img.shields.io/discord/1235780483845984367?label=Discord :target: https://discord.gg/spd2gQJGAb @@ -22,59 +28,43 @@ CapyMOA :target: https://github.com/adaptive-machine-learning/CapyMOA :alt: Link to GitHub -Machine learning library tailored for data streams. Featuring a Python API -tightly integrated with MOA (**Stream Learners**), PyTorch (**Neural -Networks**), and scikit-learn (**Machine Learning**). CapyMOA provides a -**fast** python interface to leverage the state-of-the-art algorithms in the -field of data streams. +.. image:: https://img.shields.io/docker/v/tachyonic/jupyter-capymoa/latest?logo=docker&label=Docker&color=blue + :target: https://hub.docker.com/r/tachyonic/jupyter-capymoa + :alt: Docker Image Version (tag) -To setup CapyMOA, simply install it via pip. If you have any issues with the -installation (like not having Java installed) or if you want GPU support, please -refer to :ref:`installation`. Once installed take a look at the -:ref:`tutorials` to get started. +**CapyMOA does efficient machine learning for data streams in Python.** A data stream is +a sequences of items ariving one-by-one that is too large to efficiently process +non-sequentially. CapyMOA is a toolbox of methods and evaluators for: classification, +regression, clustering, anomaly detection, semi-supervised learning, online continual +learning, and drift detection for data streams. +Install with pip: .. code-block:: bash - # CapyMOA requires Java. This checks if you have it installed - java -version - - # CapyMOA requires PyTorch. This installs the CPU version - pip install torch torchvision --index-url https://download.pytorch.org/whl/cpu - - # Install CapyMOA and its dependencies pip install capymoa - # Check that the install worked - python -c "import capymoa; print(capymoa.__version__)" +Refer to the :ref:`setup` guide for other options, including CPU-only and dev dependencies. -.. warning:: +.. code-block:: python - CapyMOA is still in the early stages of development. The API is subject to - change until version 1.0.0. If you encounter any issues, please report them - on the `GitHub Issues `_ - page or talk to us on `Discord `_. + from capymoa.datasets import Electricity + from capymoa.classifier import HoeffdingTree + from capymoa.evaluation import prequential_evaluation -.. image:: /images/arf100_cpu_time.png - :alt: Performance plot - :align: center - :class: only-light + # 1. Load a streaming dataset + stream = Electricity() -.. image:: /images/arf100_cpu_time_dark.png - :alt: Performance plot - :align: center - :class: only-dark + # 2. Create a machine learning model + model = HoeffdingTree(stream.get_schema()) + + # 3. Run with test-then-train evaluation + results = prequential_evaluation(stream, model) -Benchmark comparing CapyMOA against other data stream libraries. The benchmark -was performed using an ensemble of 100 ARF learners trained on -:class:`capymoa.datasets.RTG_2abrupt` dataset containing 100,000 samples and 30 -features. You can find the code to reproduce this benchmark in -`benchmarking.py `_. -*CapyMOA has the speed of MOA with the flexibility of Python and the richness of -Python's data science ecosystem.* + # 3. Success! + print(f"Accuracy: {results.accuracy():.2f}%") -📖 Cite Us --------------- +Next, we recomend the :ref:`tutorials`. If you use CapyMOA in your research, please cite us using the following Bibtex entry:: @@ -89,57 +79,30 @@ If you use CapyMOA in your research, please cite us using the following Bibtex e url={https://arxiv.org/abs/2502.07432} } -.. _installation: - -🚀 Installation ---------------- - -Installation instructions for CapyMOA: - -.. toctree:: - :maxdepth: 2 - - installation - docker - -🎓 Tutorials ------------- -Tutorials to help you get started with CapyMOA. - -.. toctree:: - :maxdepth: 2 - - tutorials - -📚 Reference Manual -------------------- -Reference documentation describing the interfaces fo specific classes, functions, -and modules. - -.. toctree:: - :maxdepth: 2 - - api/index - -â„šī¸ About us ------------ - -.. toctree:: - about +.. figure:: /images/arf100_cpu_time.png + :alt: Performance plot + :align: center + :class: only-light -đŸ—ī¸ Contributing ---------------- -This part of the documentation is for developers and contributors. + Benchmark comparing CapyMOA against other data stream libraries [#f1]_. -.. toctree:: - :maxdepth: 2 +.. figure:: /images/arf100_cpu_time_dark.png + :alt: Performance plot + :align: center + :class: only-dark - contributing/index + Benchmark comparing CapyMOA against other data stream libraries [#f1]_. +.. warning:: -Indices and tables -================== + CapyMOA is still in the early stages of development. The API is subject to + change until version 1.0.0. If you encounter any issues, please report them + on the `GitHub Issues `_ + page or talk to us on `Discord `_. -* :ref:`genindex` -* :ref:`modindex` -* :ref:`search` +.. [#f1] + Benchmark comparing CapyMOA against other data stream libraries. The benchmark was + performed using an ensemble of 100 ARF learners trained on + :class:`capymoa.datasets.RTG_2abrupt` dataset containing 100,000 samples and 30 + features. You can find the code to reproduce this benchmark in + `benchmarking.py `_. diff --git a/docs/installation.rst b/docs/installation.rst deleted file mode 100644 index 813510696..000000000 --- a/docs/installation.rst +++ /dev/null @@ -1,168 +0,0 @@ -Installation -============ - -This document describes how to install CapyMOA and its dependencies. CapyMOA is -tested against Python 3.10, 3.11, and 3.12. Newer versions of Python will likely -work but have yet to be tested. - -#. **Virtual Environment (Optional)** - - We recommend using a virtual environment to manage your Python - environment. Miniconda is a good choice for managing Python - environments. You can install Miniconda from - `here `__. Once you have - Miniconda installed, you can create a new environment with: - - .. code:: bash - - conda create -n capymoa python=3.11 - conda activate capymoa - - When your environment is activated, you can install CapyMOA by following - the instructions below. - -#. **Java (Required)** - - CapyMOA requires Java to be installed and accessible in your - environment. You can check if Java is installed by running the following - command in your terminal: - - .. code:: bash - - java -version - - If Java is not installed, you can download OpenJDK (Open Java - Development Kit) from `this link `__, or - alternatively the Oracle JDK from `this - link `__. Linux users can also install - OpenJDK using their distribution's package manager. - - Now that Java is installed, you should see an output similar to the - following when you run the command ``java -version``: - - :: - - openjdk version "17.0.9" 2023-10-17 - OpenJDK Runtime Environment (build 17.0.9+8) - OpenJDK 64-Bit Server VM (build 17.0.9+8, mixed mode) - - -#. **PyTorch (Required)** - - The CapyMOA algorithms using deep learning require PyTorch. It is not - installed by default because different versions are required for - different hardware. If you want to use these algorithms, follow the - instructions `here `__ to get - the correct version for your hardware. Ensure that you install PyTorch in - the same virtual environment where you want to install CapyMOA. - - For CPU only, you can install PyTorch with: - - .. code:: bash - - pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu - -#. **Install CapyMOA** - - .. code:: bash - - pip install capymoa - - To verify your installation, run: - - .. code:: bash - - python -c "import capymoa; print(capymoa.__version__)" - -Install CapyMOA for Development -=============================== - -If you want to make changes to CapyMOA, you should follow these steps to set up -an editable installation of CapyMOA, with development and documentation -dependencies. - -#. **Dependencies** - - Follow the instructions above to install PyTorch, Java, and optionally a - virtual environment. - -#. **Pandoc** - - Ensure that you have `Pandoc `__ installed on your system. - If it's not installed, you can install it by running the following command on - - .. tab-set:: - - .. tab-item:: Ubuntu - - .. code-block:: bash - - sudo apt-get install -y pandoc - - .. tab-item:: macOS - - .. code-block:: bash - - sudo brew install pandoc - - .. tab-item:: Windows/Other - - Follow the instructions on the `Pandoc website `__. - - .. tab-item:: conda - - .. code-block:: bash - - conda install -c conda-forge pandoc - - -#. **Clone the Repository** - - If you want to contribute to CapyMOA, you should clone the repository, - install development dependencies, and install CapyMOA in editable mode. - - If you are intending to contribute to CapyMOA, consider making a - `fork `__ - of the repository and cloning your fork instead of the main - repository. This way, you can push changes to your fork and create - pull requests to the main repository. - - .. code:: bash - - git clone https://github.com/adaptive-machine-learning/CapyMOA.git - # or clone via the SSH protocol (often preferred if you use SSH keys for git): - # ``git clone with git@github.com:adaptive-machine-learning/CapyMOA.git`` - - -#. **Install CapyMOA in Editable Mode** - - To install CapyMOA in editable mode with development and documentation - dependencies, navigate to the root of the repository and run: - - .. code-block:: bash - - cd CapyMOA - pip install --editable ".[dev,doc]" - - -#. **Congratulations!** - - You have successfully installed CapyMOA in editable mode. - - A number of utility scripts are defined in ``tasks.py`` to perform common - tasks. You can list all available tasks by running: - - .. code-block:: bash - - python -m invoke --list # or `invoke --list` - - .. program-output:: python -m invoke --list - - Each of these tasks can be run in the terminal through ``invoke ``. Running the task to build documentation would look like this: - - .. code-block:: bash - - invoke docs.build - - See the :doc:`contributing/index` guide for more information on how to - contribute to CapyMOA. diff --git a/docs/setup/developer.rst b/docs/setup/developer.rst new file mode 100644 index 000000000..0645c6bd0 --- /dev/null +++ b/docs/setup/developer.rst @@ -0,0 +1,92 @@ +Developer Setup +--------------- + +If you want to make changes to CapyMOA, you should follow these steps to set up +an editable installation of CapyMOA, with development and documentation +dependencies. + +#. **Dependencies** + + Follow the instructions above to install PyTorch, Java, and optionally a + virtual environment. + +#. **Pandoc** + + Ensure that you have `Pandoc `__ installed on your system. + If it's not installed, you can install it by running the following command on + + .. tab-set:: + + .. tab-item:: Ubuntu + + .. code-block:: bash + + sudo apt-get install -y pandoc + + .. tab-item:: macOS + + .. code-block:: bash + + sudo brew install pandoc + + .. tab-item:: Windows/Other + + Follow the instructions on the `Pandoc website `__. + + .. tab-item:: conda + + .. code-block:: bash + + conda install -c conda-forge pandoc + + +#. **Clone the Repository** + + If you want to contribute to CapyMOA, you should clone the repository, + install development dependencies, and install CapyMOA in editable mode. + + If you are intending to contribute to CapyMOA, consider making a + `fork `__ + of the repository and cloning your fork instead of the main + repository. This way, you can push changes to your fork and create + pull requests to the main repository. + + .. code:: bash + + git clone https://github.com/adaptive-machine-learning/CapyMOA.git + # or clone via the SSH protocol (often preferred if you use SSH keys for git): + # ``git clone with git@github.com:adaptive-machine-learning/CapyMOA.git`` + + +#. **Install CapyMOA in Editable Mode** + + To install CapyMOA in editable mode with development and documentation + dependencies, navigate to the root of the repository and run: + + .. code-block:: bash + + cd CapyMOA + pip install --editable ".[dev,doc]" + + +#. **Congratulations!** + + You have successfully installed CapyMOA in editable mode. + + A number of utility scripts are defined in ``tasks.py`` to perform common + tasks. You can list all available tasks by running: + + .. code-block:: bash + + python -m invoke --list # or `invoke --list` + + .. program-output:: python -m invoke --list + + Each of these tasks can be run in the terminal through ``invoke ``. Running the task to build documentation would look like this: + + .. code-block:: bash + + invoke docs.build + + See the :doc:`/contributing/index` guide for more information on how to + contribute to CapyMOA. \ No newline at end of file diff --git a/docs/docker.md b/docs/setup/docker.md similarity index 97% rename from docs/docker.md rename to docs/setup/docker.md index 58f1e2d1a..b15bf7d74 100644 --- a/docs/docker.md +++ b/docs/setup/docker.md @@ -1,4 +1,4 @@ -# Docker +# Docker Setup CapyMOA provides a Docker image application containing a ready-to-go Jupyter notebook. If you require a reproducible environment or want to experiment with @@ -7,7 +7,7 @@ CapyMOA and have experience with Docker, this is the best place to begin. Before you begin, you must have Docker installed. You can download and install Docker from the [official website](https://docs.docker.com/get-docker/). -![Image of CapyMOA Jupyter Notebook](images/docker_demo.png) +![Image of CapyMOA Jupyter Notebook](../images/docker_demo.png) ## Example diff --git a/docs/setup/index.rst b/docs/setup/index.rst new file mode 100644 index 000000000..b771ca2b8 --- /dev/null +++ b/docs/setup/index.rst @@ -0,0 +1,120 @@ +.. toctree:: + :hidden: + + docker + developer + +.. _setup: + +Setup +===== + +This document describes how to install CapyMOA and its dependencies. CapyMOA is +tested against Python 3.10, 3.11, and 3.12. Newer versions of Python will likely +work but have yet to be tested. + +Once you have installed the :ref:`dependencies`, you may +install CapyMOA using pip (optionally in a :ref:`venv`): + +.. code:: bash + + pip install capymoa + +To verify your installation, run: + +.. code:: bash + + python -c "import capymoa; print(capymoa.__version__)" + +.. _venv: + +Virtual Environment +^^^^^^^^^^^^^^^^^^^ + +We recommend using a virtual environment to isolate CapyMOA and its dependencies +from your other projects. This is especially important if you have other +projects that require different versions of the same dependencies. + +If you chose to use a virtual environment, you have some choices: + +* **Python Virtual Environment** + PyVenv is a built-in tool for creating virtual + environments in Python. You can create a new virtual environment with: + + .. code:: bash + + python3 -m venv .capymoa-venv + source .capymoa-venv/bin/activate + # On Windows, use `.capymoa-venv\Scripts\activate` + +* **Conda Environment** + Miniconda is a good choice for managing Python environments. You can install + Miniconda from `here `__. + Once you have Miniconda installed, you can create a new environment with: + + .. code:: bash + + conda create -n capymoa python=3.11 + conda activate capymoa + + When your environment is activated, you can install CapyMOA by following the + instructions below. + +.. _dependencies: + +Dependencies +^^^^^^^^^^^^ + +CapyMOA has some required dependencies that may require manual installation +before CapyMOA can be used: + +Java +~~~~ + +CapyMOA requires a Java runtime. You can check if Java is installed by running +the following command in your terminal: + +.. code:: bash + + java -version + +If Java is not installed, you can download OpenJDK (Open Java Development +Kit) from `this link `__, or alternatively the +Oracle JDK from `this link `__. You only need +to install the Java Runtime (JRE). Linux and macOS users can also install +OpenJDK using their distribution's package manager: + +.. tab-set:: + + .. tab-item:: Ubuntu + + .. code-block:: bash + + sudo apt-get install -y default-jre-headless + + .. tab-item:: macOS + + .. code-block:: bash + + brew install openjdk + +CapyMOA will attempt to find the Java automatically unless the ``JAVA_HOME`` +environment variable is set. This allows you to have multiple Java versions +or have Java installed outside of the system path. + +PyTorch +~~~~~~~ + +The CapyMOA algorithms using deep learning require PyTorch. If you want to use +these algorithms, follow the instructions +`here `__ to get the correct version for +your hardware. Ensure that you install PyTorch in the same virtual environment +where you want to install CapyMOA. + +For CPU only, you can install PyTorch with: + +.. code:: bash + + pip3 install torch torchvision torchaudio \ + --index-url https://download.pytorch.org/whl/cpu + diff --git a/pyproject.toml b/pyproject.toml index 5f838c20e..22836d6a4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -58,6 +58,8 @@ dependencies = [ "scikit-learn~=1.7", "seaborn~=0.13", "tqdm~=4.67", + "torch~=2.9", + "torchvision~=0.24", ] [project.optional-dependencies] diff --git a/src/capymoa/_prepare_jpype.py b/src/capymoa/_prepare_jpype.py index 2b5e543a8..9f8b3fc90 100644 --- a/src/capymoa/_prepare_jpype.py +++ b/src/capymoa/_prepare_jpype.py @@ -44,9 +44,7 @@ def _get_java_home() -> Path: ) except FileNotFoundError: raise CapymoaImportError( - "Java not found ensure `java -version` runs successfully. " - "Alternatively, you may set the JAVA_HOME environment variable to the " - "path of your Java installation for non-standard installations." + "Java not found. See https://capymoa.org/setup/#java." ) java_home = Path(result.stdout.decode().strip()) @@ -95,7 +93,11 @@ def _start_jpype(): jpype.addClassPath(moa_jar) # Start the JVM - jpype.startJVM(jpype.getDefaultJVMPath(), *capymoa_jvm_args()) + args = capymoa_jvm_args() + # Some versions of Java require this flag to allow access to parts of java.lang.System + # https://stackoverflow.com/q/79725728 + args.append("--enable-native-access=ALL-UNNAMED") + jpype.startJVM(jpype.getDefaultJVMPath(), *args) # The JVM automatically shutdown with python, no need to explicitly call the shutdown method # https://jpype.readthedocs.io/en/latest/userguide.html#shutdownjvm diff --git a/tests/test_import.py b/tests/test_import.py index d12c38df4..71415d7d9 100644 --- a/tests/test_import.py +++ b/tests/test_import.py @@ -26,12 +26,9 @@ def test_bad_infer_java_home(env): result = subprocess.run(CMD_ABOUT, capture_output=True, env=env) print(result.stdout.decode()) assert result.returncode != 0 - exception = result.stderr.decode().splitlines()[-1] - assert exception == ( - "capymoa._prepare_jpype.CapymoaImportError: Java not found ensure " - "`java -version` runs successfully. Alternatively, you may set the " - "JAVA_HOME environment variable to the path of your Java installation " - "for non-standard installations." + exception = str(result.stderr.decode().splitlines()[-1]) + assert exception.startswith( + "Java not found. See https://capymoa.org/setup/#java." )