GithubHelp home page GithubHelp logo

stochasticsampling's Introduction

Implementation of a Monte-Carlo like statistical sampling method for a time integration of a Fokker-Planck equation, coupled to a hydrodynamic field.

TERMS OF USE

In addition to the terms of the GPLv3, any publications that make use of this work or derived work must cite http://doi.org/10.25358/openscience-3103.

Build prerequisits

  • rustc >= 1.21-nightly
  • FFTW3 3.x
  • libclang 3.x

For a minimal build environment, have a look into the Docker image defined by test/CI/Dockerfile.

Due to the use of serde and syntax extension in testing code, rust nightly is necessary at the moment.

Build

If all prerequisites are fulfilled, build with

env RUSTFLAGS="-C target-cpu=native" cargo build --release

to get performance benefits from auto-vectorization.

Dependencies

Compile FFTW3 with

./configure --enable-threads --enable-sse2 --enable-avx --enable-avx2 --enable-avx512 --prefix fftw-3.3.7/build CFLAGS="-march=native"

Documentation

Usage instructions can be found when

Run cargo doc. Or make_documentation.sh in the root directory to include also non public functions into the documentation.

Output format

By default the simulation output consistst of concatinated LZMA compressed blobs in the MessagePack format. It also includes an uncompressed header encoding the simulation parameters at the beginning of the output file.

A byte buffer containing such a compressed blob at an offset offset and size size can be trivially read with python with

import lzma
import msgpack

with open('output.msgpack.lzma', 'rb') as f:
    f.seek(offset)
    buffer = f.read(size)
    buffer = lzma.decompress(buffer)
    msgpack.unpackb(buffer, encoding='utf-8')

Profiling

One way to optain a runtime profile is using perf:

env RAYON_NUM_THREADS=1 perf record --call-graph=lbr <simulation>

or

env RAYON_NUM_THREADS=1 perf record -F 99 -b --call-graph=dwarf <simulation>

Using frame-pointer is not reliable since the are often omitted in builds (as are they in opt-level >= 2 in rust). lbr is faster, but only available on Intel Haswell CPUs and later. On Skylake it is limited to a call depth of 16. dwarf results in rich information, but produces quiet heavy profiles. It might be necessary to reduce the sampling rate, for example -F 99, in perf.

In case flamegraph tools are installed, a flamegraph can be produces from the perf profile with

perf script | stackcollapse-perf | flamegraph > flame.svg

stochasticsampling's People

Contributors

clamydo avatar

Watchers

 avatar

stochasticsampling's Issues

Save orientation as vector

In GitLab by @fkjogu on Jun 29, 2018, 10:00

Currently the particle's orientation is saved as spherical angles but most calculations use a vector representation. The conversion back and forth is very expensive. By saving the orientation vector this could be reduced to just one conversation to angles when sampling into the distribution.

The implementation of rotational diffusion requires trigonometric functions evaluated at the angles. It has to be rewritten to make the above possible.

Create output module

In GitLab by @fkjogu on Dec 21, 2016, 08:23

Create module that handles writing to the storage. Basically move the code from main.rs into its own module.

Get rid of Mf64

In GitLab by @fkjogu on Mar 27, 2017, 10:24

In hindsight, this type seems to be nice, but unnecessary. Since the wrap around only needs to happen at one place, the particle configuration update. Mf64 introduces memory overhead (saves modulo quotient for every coordinate) and might lead to performance degradation.

Also consider to introduce check, before applying the wrap around. Most particles don't need that. Might be cheaper.

Borrow Settings

In GitLab by @fkjogu on Nov 26, 2016, 22:31

Try to borrow Settings. You might learn something.

Shift grid to zero to include zero

In GitLab by @fkjogu on Dec 27, 2016, 09:11

Since the magnetic field points in this direction, consider shifting grid half a cell to contain a zero angle as a grid point.

Needs benchmark, since it might be more expensive

    index = round(pos / grid_width) % grid_size

Move integrator into own module (crate?)

In GitLab by @fkjogu on Dec 21, 2016, 08:21

In order to allow for different integrators and in the spirit of encapsulation, move the integrator into its own module (crate?).

To ease the use, a possible venture would be to use a integrator trait.

Although different integrators probably need different initialization, the integration call should be similar. Modifications in the future are likely, when it is more clear, what other integrators are there.

Example:

trait Integrator {
    fn evolve(particles: &mut Vec<Particle>, distribution: &Distribution, noise: &[f64]) -> Option<FlowField>
}

Do not truncate Oseen-Tensor

In GitLab by @fkjogu on Nov 25, 2016, 15:47

At the current state, the Oseen-Tensor is truncated at the simulation box boundary. That introduces artifacts. Although it is not clear yet, how big the errors are. To be more correct, the Hashimoto-Tensor must be used instead.

Parallize computation with threads

In GitLab by @fkjogu on Nov 26, 2016, 11:40

For particle updates, that is trivial, because no halos or other communication between threads is needed.

FFTW3 already includes an API for this. Using the thread safe API also enables parallel unit tests (run condition can lead to segfault).

Calculation the distribution and flow field is a bit more involved, since it requires halos.

This also could be left for MPI integration. See #13.

A prefix with a dot inside messes up the path names

In GitLab by @fkjogu on Oct 10, 2017, 10:57

If a prefix contains a dot, everything after the dot is chopped of.

Example

/foo/kap20.0_sa-2.0-2017-10-09_164002_v0_4_2-c7e2a7b/kap20.0_sa-2.msgpack.lzma

instead of

/foo/kap20.0_sa-2.0-2017-10-09_164002_v0_4_2-c7e2a7b/kap20.0_sa-2.0-2017-10-09_164002_v0_4_2-c7e2a7b.msgpack.lzma

Add some logging

In GitLab by @fkjogu on Dec 13, 2016, 18:21

Add some useful logging facilities, so that the user can follow the steps a bit more closely.

Also parts of the internal state can be printed out in debug mode.

Improve error message when supplying an odd grid size

In GitLab by @fkjogu on Nov 25, 2016, 16:53

It panics with

Periodic Simpson's rule only works for even number of sample points, since the first point in the integration interval is also the last.

but does not tell, how to fix the error. This should be improved.

Create index for output file

In GitLab by @fkjogu on Dec 21, 2016, 11:19

To make the output file seekable, build an index file marking the positions of the concatenated objects holding the simulation output at a time step.

Pass closure to integrator for random number generation

In GitLab by @fkjogu on Dec 21, 2016, 08:07

Find out, if it makes sense to borrow closure over the random number generator to the integrator. Keep in mind, that racing conditions when going parallel should be avoided, in order to produce deterministic and reproducible results.

Create directory for output

In GitLab by @fkjogu on Mar 15, 2017, 10:05

Instead of writing the output files into the target directory, create directory to contain

  • Simulation output
  • Snapshots
  • parameter file

Enable distributed computation with MPI

In GitLab by @fkjogu on Nov 26, 2016, 11:56

FFTW3 includes API for MPI. Might be easy to use.

For (simple) histogram and integral over orientation a domain decomposition scheme is the most easiest.
Calculation of gradients needs to communicate halos.

See #12.

Fourier and real space do not use the same grid

In GitLab by @fkjogu on Apr 23, 2018, 17:51

Real space used cell centered values with cells align with the box borders. Which means the smallest position encoded is at half a cell width. On the other hand, FFT uses a grid, where a cell is centered around the origin. Which means, both grids are shifted half a cell widths against each other.

Related to #37

Angular grid does not contain (0,0,1) magnetic field axis

In GitLab by @fkjogu on Jun 30, 2017, 14:43

Since the grid points are not on the edges, but bin-centered, the closest point to the magnetic field axis pointing into the (0,0) direction is (theta_grid_width / 2, ..). Can probably lead to slight numerical errors.

Output the flow field as well

In GitLab by @fkjogu on Nov 25, 2016, 11:12

Along the distribution and the particle configurations the flow field of the solvent should also be accessible.

Make output configurable

In GitLab by @fkjogu on Nov 25, 2016, 11:16

Make it configurable what of the generated output of the simulation is dumped to the output file. This includes tunables like

  • only write a part of the particle configurations to the file
  • output the flow field (see #3)

Average histogram over multiple cells

In GitLab by @fkjogu on Nov 25, 2016, 15:49

The histogram algorithm simply counts, how many particles are in one grid cell and assign them to the cell center. To smoothen the discrete nature a bit, a weighted assignment to neighboring cells could be used.

Details

missing

Add version number to output metadata

In GitLab by @fkjogu on Dec 20, 2016, 24:21

Also include the app's version number into the message of the output file. Just extend 'Settings' with a version field, initialized on creating the a struct.

Add command line parameter to specify snapshot to resume to

In GitLab by @fkjogu on Jun 30, 2017, 15:12

Ideally, given the same output directory, the simulation should just continue the work.
Therefore, it should just

  • take the most current snapshot in the output directory as the initial state
  • append to the existing output file

Keep in mind, that in general the output file is more current than the last snapshot. Which means, just appending to it creates a branching in time. So maybe the better option would be to write to another output file and provide a merging tool.

Allow for user defined initial condition

In GitLab by @fkjogu on Nov 25, 2016, 11:10

Let the user define an initial condition, that can be given to the app.

Implementation

  • point to initial condition in an accessible format (CBOR?) in the parameter file

This is closely related to #1.

Remove check

In GitLab by @fkjogu on Nov 26, 2016, 22:42

fkoessel/mc-kinetics/blob/master/src/simulation/integrator.rs#L241

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.