Skip to main content

sgamesolver

Stochastic game solver, short: sgamesolver, is a python package to compute stationary or Markov-perfect equilibria of stochastic games, using the homotopy continuation method.

Some useful links:

sgamesolver is free and open source, under the MIT license. If you use the program for any published research, please cite Eibelshäuser/Poensgen (2019).

Installation

sgamesolver is hosted on PyPI, so installation is usually as simple as

pip install sgamesolver

Head over to the docs for other options for installation.

Usage

Solving a stochastic game is done in three steps:

  • define a game
  • pick a homotopy function
  • set up and run the solver
import sgamesolver

game = sgamesolver.SGame.random_game(64, 2, 4, seed=42)

qre = sgamesolver.homotopy.QRE(game)

qre.solver_setup()
qre.solve()

print(qre.equilibrium)

A quick rundown of these steps – more details are found in the docs:

1. Set up a stochastic game
game = sgamesolver.SGame.random_game(64, 2, 4, seed=42)

Stochastic games are represented by the class SGame. For this quick example, we are using the method random_game to randomize a game with 64 states, 2 players, and 4 actions per player and state. (Setting a seed just makes the result reproducible.)

Of course, you probably didn't come here to solve a random game, but have a specific game in mind. The documentation contains instructions and examples on how to create an SGame which represents the stochastic game you want to solve. (By the way, sgamesolver can also solve normal form games, sequential games, repeated games, and also finite Markov decision problems – each of these is just a simple case of a stochastic game.)

2. Select and set up a homotopy function for your game
qre = sgamesolver.homotopy.QRE(game)

sgamesolver uses the homotopy principle to solve stochastic games, a general technique to solve systems of non-linear equations. In short, the idea is as follows: Instead of solving some very hard problem directly (in our case: finding an equilibrium), a continuous transformation is applied to the system, yielding a related, but much simpler problem, for which one can easily obtain a solution. This transformation is then gradually reversed while tracking the solution, until arriving at a solution for the original problem – here, the desired stationary equilibrium. (You can find more background in the documentation – although such knowledge is not necessary for using the program.)

The (mathematical) function used for this transformation is called homotopy function. In general, there are many possibilities to construct a suitable one. sgamesolver currently includes two: The one we picked for this example, sgamesolver.homotopy.QRE, is based on an extension of quantal response equilibrium to stochastic games (Eibelshäuser/Poensgen 2019b). The other, sgamesolver.homotopy.LogTracing, implements the logarithmic tracing procedure for stochastic games (Eibelshäuser/Klockmann/Poensgen/von Schenk 2022). Which one to pick? In our experience, the former is more robust – while the latter has the advantage that it allows to search for multiple equilibria. More homotopy functions are to come! In any case, please make sure to cite the paper that introduced whichever homotopy you end up using.

3. Let the homotopy solver do its job

Finally, we will set up the solver and start it:

qre.solver_setup()
qre.solve()

Then it's time to lean back and watch for a bit:

==================================================
Start homotopy continuation
Step    37: t =  3.612 ↑, s =  20.47, ds =  3.418

... until ...

Step   247: t = 1.147e+04 ↑, s = 9.385e+04, ds =  1000.
Step   247: Continuation successful. Total time elapsed: 0:00:15
End homotopy continuation
==================================================
An equilibrium was found via homotopy continuation.

... success! Ideally, the solver will be able to find a solution without requiring any further interaction, as in this example. In cases where this does not work out, check out the section on troubleshooting in the documentation.

4. Aftermath

We can now display the solution:

print(qre.equilibrium)

which outputs equilibrium strategies and values for all 64 states:

+++++++++ state00 +++++++++
                       a0    a1    a2    a3  
player0 : v=15.09, σ=[1.000 0.000 0.000 0.000]
player1 : v=15.63, σ=[0.000 0.000 1.000 0.000]

+++++++++ state01 +++++++++
                       a0    a1    a2    a3  
player0 : v=14.76, σ=[0.000 0.961 0.000 0.039]
player1 : v=15.61, σ=[0.354 0.000 0.000 0.646]

+++++++++ state02 +++++++++
                       a0    a1    a2    a3  
player0 : v=14.84, σ=[1.000 0.000 0.000 0.000]
player1 : v=15.61, σ=[0.000 0.000 1.000 0.000]

... (abridged here for brevity) ...

+++++++++ state63 +++++++++
                       a0    a1    a2    a3  
player0 : v=14.92, σ=[0.000 1.000 0.000 0.000]
player1 : v=15.75, σ=[1.000 0.000 0.000 0.000]

Of course, you now also can access equilibrium strategies (and values) as numpy arrays and use them for further calculations or simulations.

eq_strat = qre.equilibrium.strategies
eq_values = qre.equilibrium.values

Metadata

Release files for sgamesolver 1.0.2

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

Source distribution (sdist)

Source distribution for sgamesolver 1.0.2
File Size Uploaded Provenance
sgamesolver-1.0.2.tar.gz 458.1 kB Without provenance Details

Built distributions (wheels)

Table of built distributions (wheels) for sgamesolver 1.0.2
File
sgamesolver-1.0.2-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
sgamesolver-1.0.2-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details
sgamesolver-1.0.2-cp39-cp39-win_amd64.whl CPython 3.9 CPython 3.9 Windows x86-64 Details
sgamesolver-1.0.2-cp38-cp38-win_amd64.whl CPython 3.8 CPython 3.8 Windows x86-64 Details
sgamesolver-1.0.2-cp37-cp37m-win_amd64.whl CPython 3.7 CPython 3.7 pymalloc Windows x86-64 Details
sgamesolver-1.0.2-cp36-cp36m-win_amd64.whl CPython 3.6 CPython 3.6 pymalloc Windows x86-64 Details

Total release size: 2.3 MB

Release files / sgamesolver-1.0.2.tar.gz

Download URL sgamesolver-1.0.2.tar.gz
Size 458.1 kB
Tags Source
SHA-256 checksum
How to use checksums
714433b1a421a5c24ac39cf0eebfddfed023140fe652a05dbd7d509ce5f87c46
BLAKE2b-256 checksum
How to use checksums
26568fbc6cbdcc5ca50c8d6a7594e84ef614f1965fac4b2ab1b49ce83f3dea97
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Release files / sgamesolver-1.0.2-cp311-cp311-win_amd64.whl

Download URL sgamesolver-1.0.2-cp311-cp311-win_amd64.whl
Size 338.1 kB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
45ff044162d43242b923f3e25265052b18dca4a119c8ff8033af8d53ca131111
BLAKE2b-256 checksum
How to use checksums
9bf646e9d7afad33d88b667d17acca32fd9194514d0d83acffe8f9707f72109d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Release files / sgamesolver-1.0.2-cp310-cp310-win_amd64.whl

Download URL sgamesolver-1.0.2-cp310-cp310-win_amd64.whl
Size 305.6 kB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
d2f679d879ca20228ed585ee917f207f523dccd55c8e11e116b3538de49c0107
BLAKE2b-256 checksum
How to use checksums
e344c16778deb36a3fc68c0c2d025ffc7b02b197b5b5da0fbc3bfcb30a14d6e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Release files / sgamesolver-1.0.2-cp39-cp39-win_amd64.whl

Download URL sgamesolver-1.0.2-cp39-cp39-win_amd64.whl
Size 308.5 kB
Tags CPython 3.9 Windows x86-64
SHA-256 checksum
How to use checksums
888c36a0c14b3b2ed9f6f5d9216d8fe1dadb5d9391d3320576069e0d5cdfcf6e
BLAKE2b-256 checksum
How to use checksums
525440d7730728dafd3e926297323f855c3a22791b6bc45e95194f8393350c0f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Release files / sgamesolver-1.0.2-cp38-cp38-win_amd64.whl

Download URL sgamesolver-1.0.2-cp38-cp38-win_amd64.whl
Size 307.4 kB
Tags CPython 3.8 Windows x86-64
SHA-256 checksum
How to use checksums
4a9d69e6fbe254d9f6ef739ea64929537a2903c73fb347bc4c835881f31659f4
BLAKE2b-256 checksum
How to use checksums
f56bdf57f2f830f6d2b1c96b1884d815ca1bcc2e7192155171063a663ae1795d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Release files / sgamesolver-1.0.2-cp37-cp37m-win_amd64.whl

Download URL sgamesolver-1.0.2-cp37-cp37m-win_amd64.whl
Size 299.6 kB
Tags CPython 3.7 CPython 3.7 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
1d2bf62cf8486034b3912d1ad7c95370359eeb0eb76667cf302fd84bd05e8631
BLAKE2b-256 checksum
How to use checksums
6fe319d46a4ebc169e0e523ff8644403c15bb982a668c26fc2e321a045b310de
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Release files / sgamesolver-1.0.2-cp36-cp36m-win_amd64.whl

Download URL sgamesolver-1.0.2-cp36-cp36m-win_amd64.whl
Size 329.4 kB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
8c282f1d21b834c20ca8930bbbcf130fb68b92a2cdcb436a1a1e34b5c0e024b1
BLAKE2b-256 checksum
How to use checksums
3d42cbbd70ded9179c417069938003f4fd2114706cabeaca3c4d33833e3a2fb4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Security for sgamesolver 1.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

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