From 54b0ba70db8f9aea795475d96ae7f50c032d3a27 Mon Sep 17 00:00:00 2001 From: Andreas Dutzler Date: Fri, 14 Apr 2023 23:57:16 +0200 Subject: [PATCH 1/6] Threaded einsum: Fall-back to numpy if einsumt is not available --- CHANGELOG.md | 3 +++ src/felupe/_assembly/_base.py | 7 ++++++- src/felupe/_basis/_basis.py | 6 +++++- src/felupe/constitution/_kinematics.py | 6 +++++- src/felupe/math/_tensor.py | 6 +++++- 5 files changed, 24 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b0822a4b..3950e053 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,9 @@ All notable changes to this project will be documented in this file. The format - Make the endpoint of `math.linsteps(endpoint=True)` optional. - Don't modify the mesh for the dual regions `RegionConstantQuad()` and `RegionConstantHexahedron()`. Instead, it is required to pass a dual (disconnected) mesh with one point per cell `RegionConstantQuad(mesh.dual(points_per_cell=1))`. +### Fixed +- Catch `ModuleNotFoundError` if `from einsumt import einsumt` fails (in JupyterLite) and fall back to `from numpy import einsum as einsumt`. + ## [7.0.0] - 2023-04-07 ### Added diff --git a/src/felupe/_assembly/_base.py b/src/felupe/_assembly/_base.py index f328ff25..f43f3692 100644 --- a/src/felupe/_assembly/_base.py +++ b/src/felupe/_assembly/_base.py @@ -26,7 +26,12 @@ """ import numpy as np -from einsumt import einsumt + +try: + from einsumt import einsumt +except ModuleNotFoundError: + from numpy import einsum as einsumt + from scipy.sparse import csr_matrix as sparsematrix diff --git a/src/felupe/_basis/_basis.py b/src/felupe/_basis/_basis.py index 4d93b920..c82f72b0 100644 --- a/src/felupe/_basis/_basis.py +++ b/src/felupe/_basis/_basis.py @@ -26,7 +26,11 @@ """ import numpy as np -from einsumt import einsumt + +try: + from einsumt import einsumt +except ModuleNotFoundError: + from numpy import einsum as einsumt class Basis: diff --git a/src/felupe/constitution/_kinematics.py b/src/felupe/constitution/_kinematics.py index b63ff53d..7ae08cde 100644 --- a/src/felupe/constitution/_kinematics.py +++ b/src/felupe/constitution/_kinematics.py @@ -26,7 +26,11 @@ """ import numpy as np -from einsumt import einsumt + +try: + from einsumt import einsumt +except ModuleNotFoundError: + from numpy import einsum as einsumt from ..math import cdya_ik, cdya_il, det, dot, dya, identity, inv, transpose diff --git a/src/felupe/math/_tensor.py b/src/felupe/math/_tensor.py index 3b696aba..7a6b604d 100644 --- a/src/felupe/math/_tensor.py +++ b/src/felupe/math/_tensor.py @@ -26,7 +26,11 @@ """ import numpy as np -from einsumt import einsumt + +try: + from einsumt import einsumt +except ModuleNotFoundError: + from numpy import einsum as einsumt def identity(A=None, dim=None, shape=None): From c18004a43dfd2e1fbf21162d87f00e2ac1e3148d Mon Sep 17 00:00:00 2001 From: Andreas Dutzler Date: Sat, 15 Apr 2023 00:13:54 +0200 Subject: [PATCH 2/6] Update tox.ini --- tox.ini | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tox.ini b/tox.ini index 315a5d32..ae72f9a2 100644 --- a/tox.ini +++ b/tox.ini @@ -7,6 +7,8 @@ deps = pytest pytest-cov matplotlib -extras = all commands = - pytest {posargs} \ No newline at end of file + pytest {posargs} + +[testenv:all] +extras = all \ No newline at end of file From dd90200c737bd3a8396a17f17c1b120a0b44d112 Mon Sep 17 00:00:00 2001 From: Andreas Dutzler Date: Sat, 15 Apr 2023 00:21:14 +0200 Subject: [PATCH 3/6] Requirements: Make `einsumt` optional again --- CHANGELOG.md | 1 + README.md | 2 +- docs/index.rst | 2 +- pyproject.toml | 4 ++-- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3950e053..1786a412 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ All notable changes to this project will be documented in this file. The format - Don't invoke `CharacteristicCurve.evaluate()` from `CharacteristicCurve.plot()`, raise an error if the current job is not evaluated instead. - Make the endpoint of `math.linsteps(endpoint=True)` optional. - Don't modify the mesh for the dual regions `RegionConstantQuad()` and `RegionConstantHexahedron()`. Instead, it is required to pass a dual (disconnected) mesh with one point per cell `RegionConstantQuad(mesh.dual(points_per_cell=1))`. +- Make requirement `einsumt` optional again due to issues with JupyterLite. ### Fixed - Catch `ModuleNotFoundError` if `from einsumt import einsumt` fails (in JupyterLite) and fall back to `from numpy import einsum as einsumt`. diff --git a/README.md b/README.md index b6e708e3..4b90ca34 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Install Python, fire up a terminal and run pip install felupe[all] ``` -where `[all]` installs all optional dependencies. By default, FElupe depends on `numpy`, `scipy` and `einsumt`. In order to make use of all features of FElupe, it is suggested to install all optional dependencies (`h5py`, `meshio` and `tensortrax`). +where `[all]` installs all optional dependencies. By default, FElupe depends on `numpy` and `scipy`. In order to make use of all features of FElupe, it is suggested to install all optional dependencies (`einsumt`, `h5py`, `meshio` and `tensortrax`). # Getting Started A quarter model of a solid cube with hyperelastic material behaviour is subjected to a uniaxial elongation applied at a clamped end-face. This involves the creation of a mesh, a region as well as a displacement field (encapsulated in a field container). Furthermore, the boundary conditions are created by a template for a uniaxial loadcase. An isotropic pseudo-elastic Ogden-Roxburgh Mullins-softening model formulation in combination with an isotropic hyperelastic Neo-Hookean material formulation is applied on a nearly-incompressible solid body. A step generates the consecutive substep-movements of a given boundary condition. The step is further added to a list of steps of a job (here, a characteristic-curve job is used). During evaluation, each substep of each step is solved by an iterative Newton-Rhapson procedure. The solution is exported after each completed substep as a time-series XDMF file. For more details beside this high-level code snippet, please have a look at the [documentation](https://felupe.readthedocs.io/en/latest/?badge=latest). diff --git a/docs/index.rst b/docs/index.rst index e298f26d..edf5da7e 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -57,7 +57,7 @@ Another key feature is the easy and straightforward definition of mixed field fo Installation ------------ -Install Python, open the terminal and run ``pip install felupe[all]``, where ``[all]`` installs all optional dependencies. By default, FElupe depends on ``numpy`, ``scipy`` and ``einsumt``. However, ``meshio``, ``h5py`` and ``tensortrax`` are highly recommended. In order to make use of all features of FElupe, it is suggested to install all optional dependencies. For more flexible constitutive material definitions using Automatic Differentation consider also installing `matADi `_. +Install Python, open the terminal and run ``pip install felupe[all]``, where ``[all]`` installs all optional dependencies. By default, FElupe depends on ``numpy`` and ``scipy``. However, ``einsumt``, ``h5py``, ``meshio`` and ``tensortrax`` are highly recommended. In order to make use of all features of FElupe, it is suggested to install all optional dependencies. For more flexible constitutive material definitions using Automatic Differentation consider also installing `matADi `_. .. code-block:: shell diff --git a/pyproject.toml b/pyproject.toml index 2a6b2525..a1b1f8a8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -44,13 +44,13 @@ requires-python = ">=3.7" dependencies = [ "numpy", "scipy", - "einsumt", ] [project.optional-dependencies] all = [ - "meshio", + "einsumt", "h5py", + "meshio", "tensortrax", ] From 4265844e69ce421c57d428e24dc0867865d37f61 Mon Sep 17 00:00:00 2001 From: Andreas Dutzler Date: Sat, 15 Apr 2023 00:22:32 +0200 Subject: [PATCH 4/6] Update pyproject.toml --- pyproject.toml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index a1b1f8a8..5113ca60 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -47,6 +47,11 @@ dependencies = [ ] [project.optional-dependencies] +test = [ + "h5py", + "meshio", + "tensortrax", +] all = [ "einsumt", "h5py", From db24fc30bb3b3841b3d6047c083a0937731f884e Mon Sep 17 00:00:00 2001 From: Andreas Dutzler Date: Sat, 15 Apr 2023 00:22:34 +0200 Subject: [PATCH 5/6] Update tox.ini --- tox.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/tox.ini b/tox.ini index ae72f9a2..833df5b4 100644 --- a/tox.ini +++ b/tox.ini @@ -7,6 +7,7 @@ deps = pytest pytest-cov matplotlib +extras = test commands = pytest {posargs} From ffd296cccdb9c58cb0a4d593c554c3e259c9a468 Mon Sep 17 00:00:00 2001 From: Andreas Dutzler Date: Sat, 15 Apr 2023 00:32:04 +0200 Subject: [PATCH 6/6] Add `matplotlib` to optional requirements this was missing --- CHANGELOG.md | 1 + README.md | 2 +- docs/index.rst | 2 +- pyproject.toml | 2 ++ 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1786a412..93f88e6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ All notable changes to this project will be documented in this file. The format - Make the endpoint of `math.linsteps(endpoint=True)` optional. - Don't modify the mesh for the dual regions `RegionConstantQuad()` and `RegionConstantHexahedron()`. Instead, it is required to pass a dual (disconnected) mesh with one point per cell `RegionConstantQuad(mesh.dual(points_per_cell=1))`. - Make requirement `einsumt` optional again due to issues with JupyterLite. +- Add `matplotlib` to optional requirements. ### Fixed - Catch `ModuleNotFoundError` if `from einsumt import einsumt` fails (in JupyterLite) and fall back to `from numpy import einsum as einsumt`. diff --git a/README.md b/README.md index 4b90ca34..068566a3 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Install Python, fire up a terminal and run pip install felupe[all] ``` -where `[all]` installs all optional dependencies. By default, FElupe depends on `numpy` and `scipy`. In order to make use of all features of FElupe, it is suggested to install all optional dependencies (`einsumt`, `h5py`, `meshio` and `tensortrax`). +where `[all]` installs all optional dependencies. By default, FElupe depends on `numpy` and `scipy`. In order to make use of all features of FElupe, it is suggested to install all optional dependencies (`einsumt`, `h5py`, `matplotlib`, `meshio` and `tensortrax`). # Getting Started A quarter model of a solid cube with hyperelastic material behaviour is subjected to a uniaxial elongation applied at a clamped end-face. This involves the creation of a mesh, a region as well as a displacement field (encapsulated in a field container). Furthermore, the boundary conditions are created by a template for a uniaxial loadcase. An isotropic pseudo-elastic Ogden-Roxburgh Mullins-softening model formulation in combination with an isotropic hyperelastic Neo-Hookean material formulation is applied on a nearly-incompressible solid body. A step generates the consecutive substep-movements of a given boundary condition. The step is further added to a list of steps of a job (here, a characteristic-curve job is used). During evaluation, each substep of each step is solved by an iterative Newton-Rhapson procedure. The solution is exported after each completed substep as a time-series XDMF file. For more details beside this high-level code snippet, please have a look at the [documentation](https://felupe.readthedocs.io/en/latest/?badge=latest). diff --git a/docs/index.rst b/docs/index.rst index edf5da7e..43976689 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -57,7 +57,7 @@ Another key feature is the easy and straightforward definition of mixed field fo Installation ------------ -Install Python, open the terminal and run ``pip install felupe[all]``, where ``[all]`` installs all optional dependencies. By default, FElupe depends on ``numpy`` and ``scipy``. However, ``einsumt``, ``h5py``, ``meshio`` and ``tensortrax`` are highly recommended. In order to make use of all features of FElupe, it is suggested to install all optional dependencies. For more flexible constitutive material definitions using Automatic Differentation consider also installing `matADi `_. +Install Python, open the terminal and run ``pip install felupe[all]``, where ``[all]`` installs all optional dependencies. By default, FElupe depends on ``numpy`` and ``scipy``. However, ``einsumt``, ``h5py``, ``matplotlib``, ``meshio`` and ``tensortrax`` are highly recommended. In order to make use of all features of FElupe, it is suggested to install all optional dependencies. For more flexible constitutive material definitions using Automatic Differentation consider also installing `matADi `_. .. code-block:: shell diff --git a/pyproject.toml b/pyproject.toml index 5113ca60..ce158fd2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -49,12 +49,14 @@ dependencies = [ [project.optional-dependencies] test = [ "h5py", + "matplotlib", "meshio", "tensortrax", ] all = [ "einsumt", "h5py", + "matplotlib", "meshio", "tensortrax", ]