Skip to main content
File added late

1 file was added to this release more than 14 days after its initial publication. Inspect the release files before installing.

==========
pysolve
==========
Solving systems of linear equations
-----------------------------------

The purpose of this code is to aid in expressing and solving
sets of equations using Python.

This tool will take a textual description of the equations
and then run the solver iteratively until it converges to a solution.

The solver provides the following choices for solving:
- Gauss-Seidel
- Newton-Raphson
- Broyden

It also uses parts of sympy to aid in parsing the equations.

The initial motivation for this tool was to solve economic
models based on Stock Flow Consistent (SFC) models.


Installation
--------------
::
pip install pysolve


Usage
-------------

.. code::
from pysolve.model import Model
from pysolve.utils import round_solution,is_close

model = Model()

model.set_var_default(0)
model.var('Cd', desc='Consumption goods demand by households')
model.var('Cs', desc='Consumption goods supply')
model.var('Gs', desc='Government goods, supply')
model.var('Hh', desc='Cash money held by households')
model.var('Hs', desc='Cash money supplied by the government')
model.var('Nd', desc='Demand for labor')
model.var('Ns', desc='Supply of labor')
model.var('Td', desc='Taxes, demand')
model.var('Ts', desc='Taxes, supply')
model.var('Y', desc='Income = GDP')
model.var('YD', desc='Disposable income of households')

# This is a shorter way to declare multiple variables
# model.vars('Y', 'YD', 'Ts', 'Td', 'Hs', 'Hh', 'Gs', 'Cs',
# 'Cd', 'Ns', 'Nd')
model.param('Gd', desc='Government goods, demand', initial=20)
model.param('W', desc='Wage rate', initial=1)
model.param('alpha1', desc='Propensity to consume out of income', initial=0.6)
model.param('alpha2', desc='Propensity to consume o of wealth', initial=0.4)
model.param('theta', desc='Tax rate', initial=0.2)

model.add('Cs = Cd')
model.add('Gs = Gd')
model.add('Ts = Td')
model.add('Ns = Nd')
model.add('YD = (W*Ns) - Ts')
model.add('Td = theta * W * Ns')
model.add('Cd = alpha1*YD + alpha2*Hh(-1)')
model.add('Hs - Hs(-1) = Gd - Td')
model.add('Hh - Hh(-1) = YD - Cd')
model.add('Y = Cs + Gs')
model.add('Nd = Y/W')

# solve until convergence
for _ in xrange(100):
model.solve(iterations=100, threshold=1e-3)

prev_soln = model.solutions[-2]
soln = model.solutions[-1]
if is_close(prev_soln, soln, rtol=1e-3):
break

print round_solution(model.solutions[-1], decimals=1)

For additional examples, view the iPython notebooks at
http://nbviewer.ipython.org/github/kennt/monetary-economics/tree/master/


Tutorial
--------
A short tutorial with more explanation is available at
http://nbviewer.ipython.org/github/kennt/monetary-economics/blob/master/extra/pysolve%20tutorial.ipynb

TODO list
---------
- Sparse matrix support (memory improvements for large systems)
- Documentation


Changelog
---------

0.2.0 (in progress)
-------------------
- Tutorial
- Improved documentation

0.1.7
-----
- Tutorial

0.1.6
-----
- Added support for solving with Broyden's method
- Optimized the code for Broyden and Newton-Raphson, should be much faster now.

0.1.5
-----
- Added the d() function. Implements the difference between the current value
and the value from a previous iteration. d(x) is equivalent to x - x(-1)
- Added support for the following sympy functions: abs, Min, Max, sign, sqrt
- Added some helper functions to aid in debugging larger models
- Added support for solving via Newton-Raphson

0.1.4
-----
- Improved error reporting when unable to solve an equation (due to variable
missing a value).
- Also, evaluate() used to require that all variables have a value, but that
may not be true on initialization, so this requirement has been removed.

0.1.3 (and before)
------------------
- Added support for the exp() and log() functions.
- Fixed a bug where the usage of '>=' within an if_true() would cause an error.


Metadata

Release files for pysolve3 0.1.3.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

File added late

1 file was uploaded more than 14 days after the first file in this release.

While project maintainers occasionally add legitimate files to an existing release, late additions can also indicate a security compromise.

We recommend inspecting the release files before installing.

Source distribution (sdist)

Source distribution for pysolve3 0.1.3.3
File Size Uploaded
pysolve3-0.1.3.3.tar.gz 22.1 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for pysolve3 0.1.3.3
File Interpreter ABI Platform
pysolve3-0.1.3.3-py3.7.egg Legacy Egg format - - Details
pysolve3-0.1.3.3-py3-none-any.whl Python 3 none any Details

Total release size: 110.7 kB

Release files / pysolve3-0.1.3.3.tar.gz

Download URL pysolve3-0.1.3.3.tar.gz
Size 22.1 kB
Tags Source
SHA-256 checksum
How to use checksums
48c54b8969cfc6ddb7f368efb988038a62984cc3ab33729aa00023507ea952d9
BLAKE2b-256 checksum
How to use checksums
df9934a5d567f93291128e539191677f6f9f88b7f95530acb32470e01b3ef6fc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.5.0.1 requests/2.19.1 setuptools/40.7.1 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.7.2

Release files / pysolve3-0.1.3.3-py3.7.egg

File added late

This file was uploaded more than 14 days after the first file in this release.

While project maintainers occasionally add legitimate files to an existing release, late additions can also indicate a security compromise.

We recommend inspecting the release file before installing.

Download URL pysolve3-0.1.3.3-py3.7.egg
Size 61.4 kB
Tags Egg
SHA-256 checksum
How to use checksums
55e8758e4655c814da7cde1f59e81b3587a77023836b31dbb95b2fc529c04480
BLAKE2b-256 checksum
How to use checksums
195e3dbb76802988fd2a140b38a0ecb6230d63584f26f85dfa411a1a3206055f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.5.0.1 requests/2.19.1 setuptools/40.7.1 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.7.2

Release files / pysolve3-0.1.3.3-py3-none-any.whl

Download URL pysolve3-0.1.3.3-py3-none-any.whl
Size 27.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2ae5fbd0bf722dd71e3567e2eaed4d7207181865427cc05de010bc754a5e7ca7
BLAKE2b-256 checksum
How to use checksums
5b6e4a1de7556abea56eb483bd1cbb1a5f6927811182cf21f5e2cfcfad30c2f7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.5.0.1 requests/2.19.1 setuptools/40.7.1 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.7.2

Release history Release notifications | RSS feed

0.1.5

2 release files

0.1.4.1

1 release file

0.1.4

2 release files

This release

0.1.3.3 This release

3 release files

0.1.2

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page