Skip to content

Commit

Permalink
Merge branch 'master' into recurrence
Browse files Browse the repository at this point in the history
  • Loading branch information
wenbang24 authored Aug 13, 2024
2 parents e77d56f + 6cb07f4 commit 1bd482c
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 14 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/CI_apptainer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Apptainer

on:
push:
branches:
- 'master'
paths:
- '**'
tags:
- 'v*.*.*'
pull_request:
branches:
- 'master'
paths:
- '**'

jobs:
test:
runs-on: ${{ matrix.os }}
timeout-minutes: 60
defaults:
run:
shell: bash
strategy:
matrix:
os: [ubuntu-latest]

steps:
- uses: actions/checkout@v4
- uses: eWaterCycle/setup-apptainer@v2
with:
apptainer-version: 1.3.0
- name: Build apptainer
run: apptainer build --notest pysr.sif Apptainer.def
- name: Test apptainer
run: |
TMPDIR=$(mktemp -d)
cp pysr.sif $TMPDIR
cd $TMPDIR
apptainer test ./pysr.sif
55 changes: 55 additions & 0 deletions Apptainer.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Build an Apptainer SIF file containing a working copy of PySR and its prereqs
Bootstrap: docker
From: julia:1.10.4-bullseye
Stage: jl

Bootstrap: docker
From: python:3.12-bullseye
Stage: runtime

%environment
# Use the container Julia binary
export PATH="/usr/local/julia/bin:$PATH"

# Create a stacked environment for additional Julia packages
export JULIA_DEPOT_PATH="$HOME/.pysr:/pysr/depot:$JULIA_DEPOT_PATH"
export JULIA_LOAD_PATH="$HOME/.pysr:/pysr:$JULIA_LOAD_PATH"

%files from jl
/usr/local/julia /usr/local/julia

%files
./requirements.txt /pysr/requirements.txt
./pyproject.toml /pysr/pyproject.toml
./setup.py /pysr/setup.py
./pysr /pysr/pysr

%post
# Ensure we don't use the local pysr commands:
cd $(mktemp -d)

export PATH="/usr/local/julia/bin:$PATH"

# Install IPython and other useful libraries:
pip3 install --no-cache-dir ipython matplotlib pytest nbval
# Install PySR and requirements:
pip3 install --no-cache-dir /pysr

# Put the Julia dependencies in /pysr/depot
mkdir /pysr/depot
export JULIA_DEPOT_PATH="/pysr/depot"

# And set a specific environment for Julia dependencies
mkdir /pysr/env
export PYTHON_JULIAPKG_PROJECT="/pysr/env"

# Pull in all the Julia dependencies
python3 -c 'import pysr; pysr.load_all_packages()'

%test
python3 -m pysr test main,cli,startup

%runscript
# Start ipython when the container is executed
[ ! -d $HOME/.pysr ] && mkdir $HOME/.pysr
PYTHONPATH=/pysr ipython
36 changes: 24 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,12 @@ Similarly, with conda:
conda install -c conda-forge pysr
```

<details>
<summary>

### Dockerfile
### Docker

</summary>

You can also use the `Dockerfile` to install PySR in a docker container

Expand All @@ -100,23 +104,31 @@ docker run -it --rm pysr ipython

For more details, see the [docker section](#docker).

---
</details>

### Troubleshooting
<details>
<summary>

One issue you might run into can result in a hard crash at import with
a message like "`GLIBCXX_...` not found". This is due to another one of the Python dependencies
loading an incorrect `libstdc++` library. To fix this, you should modify your
`LD_LIBRARY_PATH` variable to reference the Julia libraries. For example, if the Julia
version of `libstdc++.so` is located in `$HOME/.julia/juliaup/julia-1.10.0+0.x64.linux.gnu/lib/julia/`
(which likely differs on your system!), you could add:
### Apptainer

</summary>

If you are using PySR on a cluster where you do not have root access,
you can use [Apptainer](https://apptainer.org/) to build a container
instead of Docker. The `Apptainer.def` file is analogous to the `Dockerfile`,
and can be built with:

```bash
apptainer build --notest pysr.sif Apptainer.def
```
export LD_LIBRARY_PATH=$HOME/.julia/juliaup/julia-1.10.0+0.x64.linux.gnu/lib/julia/:$LD_LIBRARY_PATH
```

to your `.bashrc` or `.zshrc` file.
and launched with

```bash
apptainer run pysr.sif
```

</details>

## Quickstart

Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ dependencies:
- pandas>=0.21.0,<3.0.0
- numpy>=1.20.0,<2.0.0
- scikit-learn>=1.0.0,<2.0.0
- pyjuliacall>=0.9.15,<0.10.0
- pyjuliacall>=0.9.21,<0.9.22
- click>=7.0.0,<9.0.0
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "pysr"
version = "0.19.3"
version = "0.19.4"
authors = [
{name = "Miles Cranmer", email = "[email protected]"},
]
Expand Down
1 change: 1 addition & 0 deletions pysr/julia_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def isinstalled(uuid_s: str):
def load_package(package_name: str, uuid_s: str) -> None:
if not isinstalled(uuid_s):
Pkg.add(name=package_name, uuid=uuid_s)
Pkg.resolve()

# TODO: Protect against loading the same symbol from two packages,
# maybe with a @gensym here.
Expand Down
2 changes: 2 additions & 0 deletions pysr/test/test_startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ def test_notebook(self):
self.skipTest("Julia version too old")
if platform.system() == "Windows":
self.skipTest("Notebook test incompatible with Windows")
if not os.access(Path(__file__).parent, os.W_OK):
self.skipTest("Read-only file system")

notebook_file = Path(__file__).parent / "test_nb.ipynb"
sanitize_file = Path(__file__).parent / "nb_sanitize.cfg"
Expand Down

0 comments on commit 1bd482c

Please sign in to comment.