Skip to content

Commit

Permalink
Updated code & workflow for Python 3.13 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
swryan committed Oct 28, 2024
1 parent 53dd40e commit 03141a8
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 26 deletions.
2 changes: 2 additions & 0 deletions .github/scripts/install_latest_deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ echo "Install latest versions of 'docs' dependencies"
echo "============================================================="
python -m pip install --upgrade --pre matplotlib
python -m pip install --upgrade --pre numpydoc
echo "*** ipykernel 7.x seems to be broken at the moment"
python -m pip install 'ipykernel<7'
python -m pip install --upgrade --pre jupyter-book
python -m pip install --upgrade --pre sphinx-sitemap
python -m pip install --upgrade --pre ipyparallel
Expand Down
26 changes: 16 additions & 10 deletions .github/workflows/openmdao_latest_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ jobs:
matrix:
include:
# test latest versions on ubuntu
# Include PETSc/pyOptSparse, which require NumPy<2
# Include pyOptSparse, which requires NumPy<2
- NAME: Ubuntu Latest, NumPy<2
OS: ubuntu-latest
PY: 3
PY: '3.12'
NUMPY: '<2'
PETSc: true
PYOPTSPARSE: true
Expand All @@ -60,25 +60,31 @@ jobs:
BUILD_DOCS: true

# test latest versions on ubuntu
# Exclude PETSc/pyOptSparse, which require NumPy<2
- NAME: Ubuntu Latest, NumPy 2 (No PETSc/pyOptSparse)
# Exclude pyOptSparse, which requires NumPy<2
# NumPy>=2.1 is required with Python 3.13
- NAME: Ubuntu Latest, NumPy 2 (No pyOptSparse)
OS: ubuntu-latest
PY: 3
PY: '3.13'
NUMPY: '>=2.1'
PETSc: true

# test latest versions on macos
# Include PETSc/pyOptSparse, which require NumPy<2
# Include pyOptSparse, which requires NumPy<2
- NAME: MacOS Latest, NumPy<2
OS: macos-13
PY: 3
PY: '3.12'
NUMPY: '<2'
PETSc: true
PYOPTSPARSE: true

# test latest versions on macos
# Exclude PETSc/pyOptSparse, which require NumPy<2
- NAME: MacOS Latest, NumPy 2 (No PETSc/pyOptSparse)
# Exclude pyOptSparse, which require NumPy<2
# NumPy>=2.1 is required with Python 3.13
- NAME: MacOS Latest, NumPy 2 (No pyOptSparse)
OS: macos-13
PY: 3
PY: '3.13'
NUMPY: '>=2.1'
PETSc: true

runs-on: ${{ matrix.OS }}

Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/openmdao_test_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,12 @@ jobs:
- NAME: Ubuntu Oldest
OS: ubuntu-latest
PY: '3.9'
NUMPY: '1.23'
NUMPY: '1.24'
SCIPY: '1.9'
OPENMPI: '4.0'
MPI4PY: '3.0'
PETSc: '3.13'
PYOPTSPARSE: 'v2.9.0'
PYOPTSPARSE: 'v2.10.2'
SNOPT: '7.2'
OPTIONAL: '[all]'
TESTS: true
Expand Down Expand Up @@ -647,9 +647,9 @@ jobs:
python -m pip install --upgrade pip
echo "============================================================="
echo "Install lxml for Windows (No Python 3.11 version on pypi)"
echo "Install mkl 2024.1.0 (test failure with 2024.2.2)"
echo "============================================================="
conda install lxml
conda install mkl=2024.1.0
echo "============================================================="
echo "Install OpenMDAO"
Expand Down
11 changes: 6 additions & 5 deletions openmdao/core/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -2999,11 +2999,12 @@ def _setup_connections(self):
# out_shape != in_shape is allowed if there's no ambiguity in storage order
if (in_shape is None or out_shape is None or
not array_connection_compatible(in_shape, out_shape)):
self._collect_error(
f"{self.msginfo}: The source and target shapes do not match or "
f"are ambiguous for the connection '{abs_out}' to '{abs_in}'. "
f"The source shape is {out_shape} "
f"but the target shape is {in_shape}.", ident=(abs_out, abs_in))
with np.printoptions(legacy='1.21'):
self._collect_error(
f"{self.msginfo}: The source and target shapes do not match or "
f"are ambiguous for the connection '{abs_out}' to '{abs_in}'. "
f"The source shape is {out_shape} "
f"but the target shape is {in_shape}.", ident=(abs_out, abs_in))
continue

elif src_indices is not None:
Expand Down
15 changes: 12 additions & 3 deletions openmdao/core/tests/test_partial_color.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

import sys
import unittest
import itertools
from fnmatch import fnmatchcase
Expand Down Expand Up @@ -197,8 +197,17 @@ def __init__(self, sparsity, method='cs', isplit=1, osplit=1, **kwargs):
start = end
flines.append(' return ' + ','.join([f"r{n}" for n,_ in ofs]))
fbody = '\n'.join(flines)
exec(fbody) # nosec trusted input
f = omf.wrap(locals()['func'])

if sys.version_info >= (3,13):
# https://docs.python.org/3/whatsnew/3.13.html#pep667-porting-notes-py
# Code execution functions that implicitly target locals() (such as exec and eval)
# must be passed an explicit namespace to access their results in an optimized scope.
tmp_locals = dict()
exec(fbody, locals=tmp_locals) # nosec trusted input
f = omf.wrap(tmp_locals['func'])
else:
exec(fbody) # nosec trusted input
f = omf.wrap(locals()['func'])

for name, sz in wrts:
f.add_input(name, shape=sz)
Expand Down
4 changes: 2 additions & 2 deletions openmdao/core/total_jac.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,8 @@ def _compute_jac_scatters(self, mode, rowcol_size, get_remote):
start = end

if full_j_srcs:
full_src_inds = np.hstack(full_j_srcs)
full_tgt_inds = np.hstack(full_j_tgts)
full_src_inds = np.hstack(full_j_srcs, dtype=INT_DTYPE)
full_tgt_inds = np.hstack(full_j_tgts, dtype=INT_DTYPE)
else:
full_src_inds = np.zeros(0, dtype=INT_DTYPE)
full_tgt_inds = np.zeros(0, dtype=INT_DTYPE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@
"source": [
"## Using jax to Compute Partial Derivatives\n",
"\n",
"If the function used to instantiate the ExplicitFuncComp declares partials or coloring that use `method='jax'`, or if the component's `use_jax` option is set, then the jax AD package will be used to compute all of the component's derivatives. Currently it's not possible to mix jax with finite difference methods ('cs' and 'fd') in the same component.\n",
"If the function used to instantiate the ExplicitFuncComp declares partials or coloring that use `method='jax'`, or if the component's `derivs_method` option is set to `jax`, then the jax AD package will be used to compute all of the component's derivatives. Currently it's not possible to mix jax with finite difference methods ('cs' and 'fd') in the same component.\n",
"\n",
"Note that `jax` is not an OpenMDAO dependency, so you'll have to install it manually.\n",
"\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@
"source": [
"## Using jax to Compute Partial Derivatives\n",
"\n",
"If the function used to instantiate the ExplicitFuncComp declares partials or coloring that use `method='jax'`, or if the component's `use_jax` option is set, then the jax AD package will be used to compute all of the component's derivatives. Currently it's not possible to mix jax with finite difference methods ('cs' and 'fd') in the same component.\n",
"If the function used to instantiate the ExplicitFuncComp declares partials or coloring that use `method='jax'`, or if the component's `derivs_method` option is set to `jax`, then the jax AD package will be used to compute all of the component's derivatives. Currently it's not possible to mix jax with finite difference methods ('cs' and 'fd') in the same component.\n",
"\n",
"Note that `jax` is an optional OpenMDAO dependency, but you can install it manually.\n",
"\n",
Expand Down

0 comments on commit 03141a8

Please sign in to comment.