• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

pyneqsys/H24-Nov-2020-1,9281,532

pyneqsys.egg-info/H03-May-2022-243187

AUTHORSH A D24-Jan-201838 21

CHANGES.rstH A D24-Nov-20202.2 KiB9978

LICENSEH A D24-Jan-20181.3 KiB2419

MANIFEST.inH A D24-Jan-201871 54

PKG-INFOH A D24-Nov-202011.4 KiB243187

README.rstH A D24-Nov-20209 KiB223168

setup.cfgH A D24-Nov-2020272 1712

setup.pyH A D24-Nov-20203.7 KiB10585

README.rst

1pyneqsys
2========
3
4.. image:: http://hera.physchem.kth.se:9090/api/badges/bjodah/pyneqsys/status.svg
5   :target: http://hera.physchem.kth.se:9090/bjodah/pyneqsys
6   :alt: Build status
7.. image:: https://circleci.com/gh/bjodah/pyneqsys.svg?style=svg
8   :target: https://circleci.com/gh/bjodah/pyneqsys
9   :alt: Build status on CircleCI
10.. image:: https://secure.travis-ci.org/bjodah/pyneqsys.svg?branch=master
11   :target: http://travis-ci.org/bjodah/pyneqsys
12   :alt: Build status on Travis-CI
13.. image:: https://img.shields.io/pypi/v/pyneqsys.svg
14   :target: https://pypi.python.org/pypi/pyneqsys
15   :alt: PyPI version
16.. image:: https://img.shields.io/badge/python-2.7,3.5,3.6-blue.svg
17   :target: https://www.python.org/
18   :alt: Python version
19.. image:: http://joss.theoj.org/papers/10.21105/joss.00531/status.svg
20   :target: https://doi.org/10.21105/joss.00531
21   :alt: DOI
22.. image:: https://img.shields.io/pypi/l/pyneqsys.svg
23   :target: https://github.com/bjodah/pyneqsys/blob/master/LICENSE
24   :alt: License file
25.. image:: http://hera.physchem.kth.se/~pyneqsys/branches/master/htmlcov/coverage.svg
26   :target: http://hera.physchem.kth.se/~pyneqsys/branches/master/htmlcov
27   :alt: coverage
28
29pyneqsys provides a convenience class for
30representing and solving non-linear equation systems from symbolic expressions
31(provided e.g. with the help of SymPy_).
32
33The numerical root finding is perfomed using either:
34
35- scipy: `scipy.optimize.root <http://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.root.html>`_
36- mpmath (arbitrary precision): `mpmath.calculus.optimization.MDNewton <http://mpmath.org/doc/1.0.0/calculus/optimization.html#mpmath.calculus.optimization.MDNewton>`_
37- kinsol (from SUNDIALS): `pykinsol.solve <http://bjodah.github.io/pykinsol/latest/pykinsol.html#pykinsol.solve>`_
38- nleq2 (ZIB library free for academic use): `pynleq2.solve <http://bjodah.github.io/pynleq2/pynleq2.html#pynleq2.solve>`_
39- levmar (Levenberg-Marquardt): `levmar.levmar <https://bjodah.github.io/levmar/latest/levmar.html#levmar.levmar>`_
40
41In addition to offering a unified interface to different solvers, pyneqsys
42can also derive the Jacobian analytically (when using ``pyneqsys.SymbolicSys``).
43This is useful since doing so manually is widely recognized as both tedious and error
44prone.
45
46The symbolic representation is usually in the form of SymPy_ expressions,
47but the user may choose another symbolic back-end (see `sym <https://github.com/bjodah/sym>`_).
48
49In addition to deriving the Jacobian analytically the symbolic representation can for
50example apply row-reduce. This is usful for when you have a overdetermined system (
51formed from e.g. applying conservation laws) and want to solve the system by
52root-finding rather than using a least-square optimization of e.g. Levenberg-Marquardt
53style.
54
55Last, but not the least having a symbolic representation of your system of equations
56allows you to generate publication quality latex representations of your equations (through
57SymPy's latex printer) from a **single** source‒no more error prone hand-rewriting of the same
58equations in another format for presentation!
59
60.. _SymPy: http://www.sympy.org
61
62Documentation
63-------------
64Autogenerated API documentation for latest stable release is found here:
65`<https://bjodah.github.io/pyneqsys/latest>`_
66(and the development version for the current master branch is found here:
67`<http://hera.physchem.kth.se/~pyneqsys/branches/master/html>`_).
68
69Installation
70------------
71Simplest way to install pyneqsys and its dependencies is through the `conda package manager <http://conda.pydata.org/docs/>`_:
72
73::
74
75   $ conda install -c bjodah pyneqsys pytest
76   $ pytest --pyargs pyneqsys
77
78Optional dependencies
79~~~~~~~~~~~~~~~~~~~~~
80If you used ``conda`` to install pyneqsys_ you can skip this section.
81But if you use ``pip`` you may want to know that the default installation
82of ``pyneqsys`` only requires SciPy::
83
84   $ pip install pyneqsys
85   $ pytest --pyargs pyneqsys -rs
86
87The above command should finish without errors but with some skipped tests.
88The reason for why some tests are skipped should be because missing optional solvers.
89To install the optional solvers you will first need to install third party libraries for
90the solvers and then their python bindings. The 3rd party requirements are as follows:
91
92- `pykinsol <https://github.com/bjodah/pykinsol>`_ (requires SUNDIALS_ ==2.7.0)
93- `levar <https://github.com/bjodah/levmar>`_
94- `mpmath <http://www.mpmath.org>`_
95
96
97if you want to see what packages need to be installed on a Debian based system you may look at this
98`Dockerfile <scripts/environment/Dockerfile>`_.
99
100If you manage to install all three external libraries you may install pyneqsys with the option "all"::
101
102  $ pip install pyneqsys[all]
103  $ pytest --pyargs pyneqsys -rs
104
105now there should be no skipped tests. If you try to install pyneqsys on a machine where you do not have
106root permissions you may find the flag ``--user`` helpful when using pip. Also if there are multiple
107versions of python installed you may want to invoke python for an explicit version of python, e.g.::
108
109  $ python3.6 -m pip install --user pyneqsys[all]
110
111see `setup.py <setup.py>`_ for the exact list of requirements.
112
113.. _SUNDIALS: https://computation.llnl.gov/projects/sundials
114
115Using Docker
116~~~~~~~~~~~~
117If you have `Docker <https://www.docker.com>`_ installed, you may use it to host a jupyter
118notebook server::
119
120  $ ./scripts/host-jupyter-using-docker.sh . 8888
121
122the first time you run the command some dependencies will be downloaded. When the installation
123is complete there will be a link visible which you can open in your browser. You can also run
124the test suite using the same docker-image::
125
126  $ ./scripts/host-jupyter-using-docker.sh . 0
127
128there will be one skipped test (due to symengine missing in this pip installed environment) and
129quite a few instances of RintimeWarning.
130
131Examples
132--------
133Example reformulated from `SciPy documentation <http://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.root.html>`_:
134
135.. code:: python
136
137   >>> from pyneqsys.symbolic import SymbolicSys
138   >>> neqsys = SymbolicSys.from_callback(
139   ...     lambda x: [(x[0] - x[1])**3/2 + x[0] - 1,
140   ...                (x[1] - x[0])**3/2 + x[1]], 2)
141   >>> x, info = neqsys.solve([1, 0])
142   >>> assert info['success']
143   >>> print(x)
144   [0.8411639 0.1588361]
145
146here we did not need to enter the jacobian manually, SymPy did that for us.
147For expressions containing transcendental functions we need to provide a
148"backend" keyword arguemnt to enable symbolic derivation of the jacobian:
149
150.. code:: python
151
152   >>> import math
153   >>> def powell(x, params, backend=math):
154   ...     A, exp = params[0], backend.exp
155   ...     return A*x[0]*x[1] - 1, exp(-x[0]) + exp(-x[1]) - (1 + A**-1)
156   >>> powell_sys = SymbolicSys.from_callback(powell, 2, 1, names='x0 x1'.split())
157   >>> x, info = powell_sys.solve([1, 1], [1000.0])
158   >>> assert info['success']
159   >>> print(', '.join(['%.6e' % _ for _ in sorted(x)]))
160   1.477106e-04, 6.769996e+00
161
162pyneqsys also allows the user to solve a system of equations for a span of
163values for a parameter, and optionally plot the result vs. the varied value:
164
165.. code:: python
166
167   >>> import matplotlib.pyplot as plt
168   >>> import numpy as np
169   >>> x0_varied, x0_idx = np.linspace(1e3, 3e3), 0
170   >>> all_x, all_info = powell_sys.solve_and_plot_series(x, [1000.0], x0_varied, x0_idx)
171   >>> plt.savefig('example.png')
172
173.. image:: https://raw.githubusercontent.com/bjodah/pyneqsys/master/examples/example.png
174
175For more examples look see
176`examples/ <https://github.com/bjodah/pyneqsys/tree/master/examples>`_, and rendered jupyter notebooks here:
177`<http://hera.physchem.kth.se/~pyneqsys/branches/master/examples>`_
178
179Run notebooks using binder
180~~~~~~~~~~~~~~~~~~~~~~~~~~
181Using only a web-browser (and an internet connection) it is possible to explore the
182notebooks here: (by the courtesy of the people behind mybinder)
183
184.. image:: http://mybinder.org/badge.svg
185   :target: https://mybinder.org/v2/gh/bjodah/pyneqsys/d8775becc6f30b4d3e7920f53d5f318c0672195b?filepath=index.ipynb
186   :alt: Binder
187
188Citing
189------
190If you make use of pyneqsys in e.g. academic work you may cite the following peer-reviewed publication:
191
192.. image:: http://joss.theoj.org/papers/10.21105/joss.00531/status.svg
193   :target: https://doi.org/10.21105/joss.00531
194   :alt: Journal of Open Source Software DOI
195
196Depending on what underlying solver you are using you should also cite the appropriate paper
197(you can look at the list of references in the JOSS article). If you need to reference,
198in addition to the paper, a specific point version of pyneqsys (for e.g. reproducibility)
199you can get per-version DOIs from the zendodo archive:
200
201.. image:: https://zenodo.org/badge/43504371.svg
202   :target: https://zenodo.org/badge/latestdoi/43504371
203   :alt: Zenodo DOI
204
205
206Licensing
207---------
208The source code is Open Source and is released under the simplified 2-clause BSD license. See LICENSE_ for further details.
209
210.. _LICENSE: LICENSE
211
212
213Contributing
214------------
215Contributors are welcome to suggest improvements at https://github.com/bjodah/pyneqsys
216(see further details `here <CONTRIBUTING.rst>`_).
217
218Author
219------
220Björn I. Dahlgren, contact:
221
222- gmail address: bjodah
223