Skip to content
Snippets Groups Projects
Verified Commit 8dd42fd4 authored by Daniel Hornung's avatar Daniel Hornung
Browse files

WIP DOC: Code gallery: first steps

parent 2fff66ff
No related branches found
No related tags found
1 merge request!41DOC: code gallery
Pipeline #18138 canceled
PyCaosDB Code Gallery
=====================
This chapter collects code examples which can be immediately run against an empty CaosDB instance.
.. toctree::
:maxdepth: 2
:caption: Contents:
:hidden:
simulation
import caosdb as db
import numpy as np
def main():
# 1. Set up the data model
setup_caosdb()
# 2.Run simulations
for i in range(200):
run_simulation(run=i, t_max=10)
if __name__ == '__main__':
main()
def setup_caosdb():
"""Create the data model and insert it into CaosDB
The data model consists of the following RecordTypes:
Software
with author and revision.
SoftwareRun
A specific run of the sofware, with input parameters, a date and a result.
Parameters
An aggregate of parameters, in this case the x,y,z initial values.
Result
The x,y,z values at the end of the software run.
The data model of course also contains the corresponding properties for these RecordTypes.
"""
def run_simulation(run, t_max):
"""
Integrate the Rössler attractor from random initial values.
"""
a = 0.2; b = 0.2; c = 5.7
def diff(x, dt):
return (dt * (-x[1] - x[2]),
dt * (x[0] + a * x[1]),
dt * (b + x[2] * (x[0] - c)))
x0 = np.random.uniform(-10, 10, 3)
dt = 0.01
x = x0
for t in range(0, t_max, dt):
x += diff(x, dt)
return (x0, x)
========================================
Managing data from numerical simulations
========================================
This code example
1. sets up the data model
2. runs simulations
3. stores the parameters and results into CaosDB
4. retrieves the parameters for interesting results
:download:`Download code<simulation.py>`
.. literalinclude:: simulation.py
......@@ -12,6 +12,7 @@ Welcome to PyCaosDB's documentation!
Concepts <concepts>
Configuration <configuration>
Administration <administration>
Code gallery <gallery/index>
API documentation<_apidoc/caosdb>
This is the documentation for the Python client library for CaosDB, ``PyCaosDB``.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment