Skip to content

Commit

Permalink
resfn and rhsfn now work with numba jit/njit
Browse files Browse the repository at this point in the history
  • Loading branch information
c-randall committed Jan 15, 2025
1 parent bf7ee9b commit facdbdc
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 146 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,11 @@ jobs:
- name: Pytest
run: nox -s tests -- no-reports

- name: learn micromamba
run: |
micromamba remove sundials
micromamba create -n test python=${{ matrix.python-version }}
micromamba activate test
micromamba info
micromamba list
36 changes: 13 additions & 23 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,24 +87,19 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup conda/python
uses: conda-incubator/setup-miniconda@v3
with: # ci_environment.yml specifies sundials version to compile against
auto-update-conda: true
miniconda-version: latest
- name: Setup Python and SUNDIALS
uses: mamba-org/setup-micromamba@v2
with: # ci_environment.yml specifies sundials version to compile
environment-file: environments/ci_environment.yml
python-version: ${{ matrix.python-version }}
activate-environment: sun
channels: conda-forge
conda-remove-defaults: "true"
create-args: python=${{ matrix.python-version }}

- name: Install build
run: pip install build

- name: List info
run: |
conda info
conda list
micromamba info
micromamba list
- name: Set up environment variables for MacOS
if: runner.os == 'macOS'
Expand Down Expand Up @@ -153,9 +148,9 @@ jobs:
env: # Remove known SUNDIALS header and lib paths
DYLD_LIBRARY_PATH:
run: |
conda uninstall sundials
conda create -n test python=${{ matrix.python-version }}
conda activate test
micromamba remove sundials
micromamba create -n test python=${{ matrix.python-version }}
micromamba activate test
python -m pip install --upgrade pip
pip install wheels/*.whl -v
Expand Down Expand Up @@ -188,16 +183,11 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup conda/python
uses: conda-incubator/setup-miniconda@v3
with: # ci_environment.yml specifies sundials version to compile against
auto-update-conda: true
miniconda-version: latest
- name: Setup Python and SUNDIALS
uses: mamba-org/setup-micromamba@v2
with: # ci_environment.yml specifies sundials version to compile
environment-file: environments/ci_environment.yml
python-version: ${{ matrix.python-version }}
activate-environment: sun
channels: conda-forge
conda-remove-defaults: "true"
create-args: python=${{ matrix.python-version }}

- name: Install build
run: pip install build
Expand Down
97 changes: 0 additions & 97 deletions inprogress/getfullargspec.py

This file was deleted.

1 change: 1 addition & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,5 @@ def run_build_ext(session: nox.Session) -> None:
"""

session.run('pip', 'install', '--upgrade', '--quiet', 'cython')
session.run('python', 'setup.py', 'build_ext', '--inplace')
24 changes: 11 additions & 13 deletions src/sksundae/_cy_cvode.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
# cython: embedsignature=True, embeddedsignature.format='python'

# Standard library
import inspect
from warnings import warn
from types import MethodType
from inspect import getfullargspec
from typing import Callable, Iterable

# Dependencies
Expand Down Expand Up @@ -814,27 +814,25 @@ cdef _collect_stats(void* mem):
def _check_signature(name: str, func: Callable, expected: tuple[int]) -> int:
"""Check 'rhsfn', 'eventsfn', and 'jacfn' signatures."""

argspec = getfullargspec(func)
if isinstance(func, MethodType): # if method, remove self/cls
argspec.args.pop(0)
elif argspec.args[0] in ("self", "cls"):
argspec.args.pop(0)
signature = inspect.signature(func)
parameters = signature.parameters.values()

if argspec.varargs or argspec.varkw:
has_args = any([p.kind == inspect._VAR_POSITIONAL for p in parameters])
has_kwargs = any([p.kind == inspect._VAR_KEYWORD for p in parameters])

if has_args or has_kwargs:
raise ValueError(f"'{name}' cannot include *args or **kwargs.")
elif argspec.kwonlyargs:
raise ValueError(f"'{name}' cannot include keyword-only args.")

if name == "rhsfn" and len(argspec.args) not in expected:
if name == "resfn" and len(parameters) not in expected:
raise ValueError(f"'{name}' has an invalid signature. It must only"
" have 3 (w/o userdata) or 4 (w/ userdata) args.")
elif len(argspec.args) not in expected:
elif len(parameters) not in expected:
raise ValueError(f"'{name}' signature is inconsistent with 'rhsfn'."
" look for a missing or extraneous 'userdata' arg.")

if name == "rhsfn" and len(argspec.args) == 3:
if name == "rhsfn" and len(parameters) == 3:
with_userdata = 0
elif name == "rhsfn" and len(argspec.args) == 4:
elif name == "rhsfn" and len(parameters) == 4:
with_userdata = 1
else:
with_userdata = None
Expand Down
24 changes: 11 additions & 13 deletions src/sksundae/_cy_ida.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
# cython: embedsignature=True, embeddedsignature.format='python'

# Standard library
import inspect
from warnings import warn
from types import MethodType
from inspect import getfullargspec
from typing import Callable, Iterable

# Dependencies
Expand Down Expand Up @@ -878,27 +878,25 @@ cdef _collect_stats(void* mem):
def _check_signature(name: str, func: Callable, expected: tuple[int]) -> int:
"""Check 'resfn', 'eventsfn', and 'jacfn' signatures."""

argspec = getfullargspec(func)
if isinstance(func, MethodType): # if method, remove self/cls
argspec.args.pop(0)
elif argspec.args[0] in ("self", "cls"):
argspec.args.pop(0)
signature = inspect.signature(func)
parameters = signature.parameters.values()

if argspec.varargs or argspec.varkw:
has_args = any([p.kind == inspect._VAR_POSITIONAL for p in parameters])
has_kwargs = any([p.kind == inspect._VAR_KEYWORD for p in parameters])

if has_args or has_kwargs:
raise ValueError(f"'{name}' cannot include *args or **kwargs.")
elif argspec.kwonlyargs:
raise ValueError(f"'{name}' cannot include keyword-only args.")

if name == "resfn" and len(argspec.args) not in expected:
if name == "resfn" and len(parameters) not in expected:
raise ValueError(f"'{name}' has an invalid signature. It must only"
" have 4 (w/o userdata) or 5 (w/ userdata) args.")
elif len(argspec.args) not in expected:
elif len(parameters) not in expected:
raise ValueError(f"'{name}' signature is inconsistent with 'resfn'."
" look for a missing or extraneous 'userdata' arg.")

if name == "resfn" and len(argspec.args) == 4:
if name == "resfn" and len(parameters) == 4:
with_userdata = 0
elif name == "resfn" and len(argspec.args) == 5:
elif name == "resfn" and len(parameters) == 5:
with_userdata = 1
else:
with_userdata = None
Expand Down

0 comments on commit facdbdc

Please sign in to comment.