Skip to main content

A Python Library for Applied Mathematics in Physical Sciences.

Project description

Neumann - A Python Library for Applied Mathematics in Physical Sciences

Binder CircleCI Documentation Status License PyPI codecov Code style: black

Warning Neumann is in the early stages of it's lifetime, and some concepts may change in the future. If you want long-term stability, wait until version 1.0, which is planned to be released if the core concepts all seem to sit. Nonetheless, the library is well tested with a coverage value above 90%, so if something catches your eye use it with confidence, just don't forget to pin down the version of Neumann in your 'requirements.txt'.

Neumann is a Python library that provides tools to formulate and solve problems related to all kinds of scientific disciplines. It is a part of the DewLoosh ecosystem which is designed mainly to solve problems related to computational solid mechanics, but if something is general enough, it ends up here. A good example is the included vector and tensor algebra modules, or the various optimizers, which are applicable in a much broader context than they were originally designed for.

The most important features:

  • Linear Algebra

    • A mechanism that guarantees to maintain the property of objectivity of tensorial quantities.
    • A ReferenceFrame class for all kinds of frames, and dedicated RectangularFrame and CartesianFrame classes as special cases, all NumPy compliant.
    • NumPy compliant classes like Tensor and Vector to handle various kinds of tensorial quantities efficiently.
    • A JaggedArray and a Numba-jittable csr_matrix to handle sparse data.
  • Operations Research

    • Classes to define and solve linear and nonlinear optimization problems.
      • A LinearProgrammingProblem class to define and solve any kind of linear optimization problem.
      • A BinaryGeneticAlgorithm class to tackle more complicated optimization problems.
  • Graph Theory

    • Algorithms to calculate rooted level structures and pseudo peripheral nodes of a networkx graph, which are useful if you want to minimize the bandwidth of sparse symmetrix matrices.

Note Be aware, that the library uses JIT-compilation through Numba, and as a result, first calls to these functions may take longer, but pay off in the long run.

Documentation

The documentation is hosted on ReadTheDocs.

Installation

Neumann can be installed (either in a virtual enviroment or globally) from PyPI using pip on Python >= 3.7:

>>> pip install neumann

or chechkout with the following command using GitHub CLI

gh repo clone dewloosh/Neumann

and install from source by typing

>>> python install setup.py

Motivating Examples

Linear Algebra

Define a reference frame $\mathbf{B}$ relative to the frame $\mathbf{A}$:

>>> from neumann.linalg import ReferenceFrame, Vector, Tensor
>>> A = ReferenceFrame(name='A', axes=np.eye(3))
>>> B = A.orient_new('Body', [0, 0, 90*np.pi/180], 'XYZ', name='B')

Get the DCM matrix of the transformation between two frames:

>>> B.dcm(target=A)

Define a vector $\mathbf{v}$ in frame $\mathbf{A}$ and show the components of it in frame $\mathbf{B}$:

>>> v = Vector([0.0, 1.0, 0.0], frame=A)
>>> v.show(B)

Define the same vector in frame $\mathbf{B}$:

>>> v = Vector(v.show(B), frame=B)
>>> v.show(A)

Linear Programming

Solve the following Linear Programming Problem (LPP) with one unique solution:

>>> from neumann.optimize import LinearProgrammingProblem as LPP
>>> from neumann.function import Function, Equality
>>> import sympy as sy
>>> variables = ['x1', 'x2', 'x3', 'x4']
>>> x1, x2, x3, x4 = syms = sy.symbols(variables, positive=True)
>>> obj1 = Function(3*x1 + 9*x3 + x2 + x4, variables=syms)
>>> eq11 = Equality(x1 + 2*x3 + x4 - 4, variables=syms)
>>> eq12 = Equality(x2 + x3 - x4 - 2, variables=syms)
>>> problem = LPP(cost=obj1, constraints=[eq11, eq12], variables=syms)
>>> problem.solve()['x']
array([0., 6., 0., 4.])

NonLinear Programming

Find the minimizer of the Rosenbrock function:

>>> from neumann.optimize import BinaryGeneticAlgorithm
>>> def Rosenbrock(x):
...     a, b = 1, 100
...     return (a-x[0])**2 + b*(x[1]-x[0]**2)**2
>>> ranges = [[-10, 10], [-10, 10]]
>>> BGA = BinaryGeneticAlgorithm(Rosenbrock, ranges, length=12, nPop=200)
>>> BGA.solve()
...

License

This package is licensed under the MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

neumann-0.0.9.tar.gz (72.8 kB view details)

Uploaded Source

Built Distribution

neumann-0.0.9-py3-none-any.whl (85.5 kB view details)

Uploaded Python 3

File details

Details for the file neumann-0.0.9.tar.gz.

File metadata

  • Download URL: neumann-0.0.9.tar.gz
  • Upload date:
  • Size: 72.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for neumann-0.0.9.tar.gz
Algorithm Hash digest
SHA256 8ac4dc72593f10f2f5534ee831ee6de5cca5b0c414f2c6cbf19587c813643fec
MD5 808ec65ef3d9219001c1df6f0e86b480
BLAKE2b-256 62e26634560b989e2e66f68181700aaa379ce7905d3f8af30bd18924de51aca4

See more details on using hashes here.

Provenance

File details

Details for the file neumann-0.0.9-py3-none-any.whl.

File metadata

  • Download URL: neumann-0.0.9-py3-none-any.whl
  • Upload date:
  • Size: 85.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for neumann-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 fbcae6dcc4d3e87786a9ccb763d841b0cefb998bda4bd70f9d4302bf9c8807f1
MD5 8b74098208490a9b1cf97c1f30ffc154
BLAKE2b-256 4013b39cbe0e36d409933ddcf330ab57caae6ee7c546645351e8447f6d60b9d9

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page