Giter Club home page Giter Club logo

necsim-rust's Introduction

necsim-rust โ€ƒ CI Status Rust Doc License Status Code Coverage Binder Demo Gitpod Ready-to-Code DOI

Introduction

necsim-rust is a Rust reimplementation of the C++ library necsim and its Python wrapper pycoalescence, which are used to run neutral coalescence biodiversity simulations.

necsim-rust aims to provide a smaller, more concise subset of the functionality of necsim and pycoalescence but be easier to use and extend. For instance, necsim-rust contains the classical coalescence algorithm. Additionally, it implements two Gillespie-based algorithms and a novel independent algorithm with a CPU and a CUDA variant. Furthermore, necsim-rust can use MPI to parallelise the simulation.

necsim-rust is built in a modular way to reduce code duplication and allow the user (and other programmers) to plug together different components to customise the simulated scenario, the algorithm it is simulated with as well as finer implementation details. Currently, necsim-rust supports four built-in scenarios:

  • non-spatial model
  • spatially implicit model with migration from a non-spatial metacommunity to a non-spatial local community
  • spatially explicit (almost) infinite model with Gaussian Normal dispersal
  • spatially-explicit simulation with habitat and dispersal maps

Prerequisites

First, you need to clone the necsim-rust GitHub repository:

git clone https://github.com/juntyr/necsim-rust.git

necsim-rust is written in the Rust language, which must be installed in your PATH first. necsim-rust includes a rust-toolchain file that configures Rust to use a working nightly toolchain version and install all components required for compilation. If you want to use necsim-rust on a target different than x86_64-unknown-linux-gnu, please update the rust-toolchain config file accordingly.

The necsim-plugins-species reporter depends on libsqlite3-dev, and the necsim-plugins-tskit reporter and the necsim-partitioning-mpi parallelisation backend (enabled with the mpi-partitioning feature) depend on libclang-dev. You can install these optional packages using

sudo apt-get install libclang-dev libsqlite3-dev

Installation

To install rustcoalescence, you need to decide which algorithms you want to compile with it. You can enable the provided algorithms by enabling their corresponding features. For instance, to compile all CPU-based algorithms with all scenarios, you can use

cargo install --path rustcoalescence --locked --features gillespie-algorithms --features independent-algorithm --features all-scenarios

To install with CUDA support, you first need to ensure that the dynamic CUDA libraries are in the LD_LIBRARY_PATH and enable the cuda-algorithm feature:

LIBRARY_PATH="$LD_LIBRARY_PATH" cargo install --path rustcoalescence --locked [...] --features cuda-algorithm

To compile with MPI support, you need to enable the mpi-partitioning feature:

cargo install --path rustcoalescence --locked [...] --features mpi-partitioning

After compilation, you can then run rustcoalescence using:

rustcoalescence [...]

If you want to use any of the provided reporter analysis plugins, you have to compile them manually. For instance, to compile the common plugin which includes the Biodiversity(), Counter(), Execution(), Progress() and Verbose() reporters, you can run:

> cargo build --release --manifest-path necsim/plugins/common/Cargo.toml

Compiling for Development

If you want to compile the library for development, you can use any of the above installation commands, but replace

cargo install --path rustcoalescence --locked [...]

with

cargo build --release [...]

Running rustcoalescence

rustcoalescence has two subcommands: simulate and replay and accepts command-line arguments in the following format:

rustcoalescence <SUBCOMMAND> args..

Here, args.. is a configuration string in RON format, which can also directly be read from a configuration file:

rustcoalescence <SUBCOMMAND> "$(<config.ron)"

Please refer to docs/simulate.ron and docs/replay.ron for a detailed description of all configuration options. ./simulate.ron and ./replay.ron also provide example configurations.

Project structure

necsim-rust consists of the following crates:

  • necsim/: this folder contains the core declaration of the simulation and implementation of its components
    • core/: necsim-core declares the core structs, simulation cogs traits, as well as the generic Simulation.
      • maths/: necsim-core-maths declares the required f64 intrinsics for simulating in a no-std environment, and provides a default implementation.
      • bond/: necsim-core-bond declares helper data types which guarantee a limited value range and are used for encoding preconditions through data types.
    • impls/:
      • no-std/: necsim-impls-no-std contains the implementations of cogs that do not require the Rust standard library
      • std/: necsim-impls-std contains the implementations of cogs that do require the Rust standard library
      • cuda/: necsim-impls-cuda contains the implementations of CUDA specific cogs
    • plugins/:
      • core/: necsim-plugins-core implements the reporter plugin system and provides the functionality to export and load plugins
      • common/: necsim-plugins-common implements common analysis reporters, e.g. to measure biodiversity, print a progress bar, etc.
      • metacommunity/: necsim-plugins-metacommunity implements a reporter which measures migrations to a static external metacommunity, which can be simulated separately using the non-spatial scenario
      • csv/: necsim-plugins-csv implements a reporter which records events in a CSV file
      • species/: necsim-plugins-species produces an SQLite database which lists the parent-child relationships of all simulated individuals as well as their species
    • partitioning/:
      • core/: necsim-partitioning-core declares the core partitioning traits
      • monolithic/: necsim-partitioning-monolithic implements monolithic, i.e. non-parallel partitioning
      • mpi/: necsim-partitioning-mpi implements the MPI-based partitioning backend
      • threads/: necsim-partitioning-threads implements the multithreading-based partitioning backend
  • rustcoalescence/: rustcoalescence provides the command-line interface.
    • scenarios/: rustcoalescence-scenarios contains the glue code to put together the cogs for the built-in scenarios. It is specifically built only for reducing code duplication in rustcoalescence, not for giving a minimal example of how to construct a simulation.
    • algorithms/:
      • gillespie/: rustcoalescence-algorithms-gillespie contains the glue code to put together the cogs for the two monolithic Gillespie coalescence algorithms. It is specifically built only for reducing code duplication in rustcoalescence, not for giving a minimal example of how to construct a simulation.
        • src/gillespie: GillespieAlgorithm (also known as the classical algorithm) is a good allrounder that is built on Gillespie's "next-reaction" method. While it includes a specialised implementation for uniform turnover rates, it generally uses a dynamic alias method sampler (individual-based) to pick the next event. Therefore, it performs better on habitats with a high probability to disperse to a different location (i.e. small per-location demes).
        • src/event_skipping: EventSkippingAlgorithm is a specialised mathematically correct algorithm that skips self-dispersal events without coalescence. It is built on Gillespie's "next-reaction" method and uses a dynamic alias method sampler (location-based) to pick the next event. Therefore, it is very fast on habitats with high self-dispersal probabilities (i.e. large per-location demes), or when the speciation probability is very small.
      • independent/: rustcoalescence-algorithms-independent contains the glue code to put together the cogs for the independent coalescence algorithm on the CPU. The algorithm treats the simulation as an embarrassingly parallel problem. It can also be used to simulate subdomains of the simulation separately and piece the results back afterwards without loss of consistency.
      • cuda/: rustcoalescence-algorithms-cuda contains the glue code to put together the cogs for the independent coalescence algorithm on a CUDA 3.5 capable GPU. The algorithm treats the simulation as an embarrassingly parallel problem. It can also be used to simulate subdomains of the simulation separately and piece the results back afterwards without loss of consistency.

GDAL GeoTiff compatibility

pycoalescence and necsim both used GDAL to load habitat, dispersal and turnover maps. As rustcoalescence is more strict about type checking the TIFF files, you can use the following commands to convert and compress your GeoTIFF files:

gdalwarp -ot Uint32 -co "COMPRESS=LZW" -dstnodata 0 -to "SRC_METHOD=NO_GEOTRANSFORM" -to "DST_METHOD=NO_GEOTRANSFORM" input_habitat.tif output_habitat.tif
gdalwarp -ot Float64 -co "COMPRESS=LZW" -dstnodata 0 -to "SRC_METHOD=NO_GEOTRANSFORM" -to "DST_METHOD=NO_GEOTRANSFORM" input_dispersal.tif output_dispersal.tif
gdalwarp -ot Float64 -co "COMPRESS=LZW" -dstnodata 0 -to "SRC_METHOD=NO_GEOTRANSFORM" -to "DST_METHOD=NO_GEOTRANSFORM" input_turnover.tif output_turnover.tif

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

necsim-rust's People

Contributors

dependabot[bot] avatar juntyr avatar nicofirbas avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

necsim-rust's Issues

RUSTSEC-2021-0139: ansi_term is Unmaintained

ansi_term is Unmaintained

Details
Status unmaintained
Package ansi_term
Version 0.12.1
URL ogham/rust-ansi-term#72
Date 2021-08-18

The maintainer has adviced this crate is deprecated and will not
receive any maintenance.

The crate does not seem to have much dependencies and may or may not be ok to use as-is.

Last release seems to have been three years ago.

Possible Alternative(s)

The below list has not been vetted in any way and may or may not contain alternatives;

See advisory page for additional details.

RUSTSEC-2020-0159: Potential segfault in `localtime_r` invocations

Potential segfault in localtime_r invocations

Details
Package chrono
Version 0.4.19
URL chronotope/chrono#499
Date 2020-11-10

Impact

Unix-like operating systems may segfault due to dereferencing a dangling pointer in specific circumstances. This requires an environment variable to be set in a different thread than the affected functions. This may occur without the user's knowledge, notably in a third-party library.

Workarounds

No workarounds are known.

References

See advisory page for additional details.

RUSTSEC-2020-0071: Potential segfault in the time crate

Potential segfault in the time crate

Details
Package time
Version 0.1.44
URL time-rs/time#293
Date 2020-11-18
Patched versions >=0.2.23
Unaffected versions =0.2.0,=0.2.1,=0.2.2,=0.2.3,=0.2.4,=0.2.5,=0.2.6

Impact

Unix-like operating systems may segfault due to dereferencing a dangling pointer in specific circumstances. This requires an environment variable to be set in a different thread than the affected functions. This may occur without the user's knowledge, notably in a third-party library.

The affected functions from time 0.2.7 through 0.2.22 are:

  • time::UtcOffset::local_offset_at
  • time::UtcOffset::try_local_offset_at
  • time::UtcOffset::current_local_offset
  • time::UtcOffset::try_current_local_offset
  • time::OffsetDateTime::now_local
  • time::OffsetDateTime::try_now_local

The affected functions in time 0.1 (all versions) are:

  • at
  • at_utc
  • now

Non-Unix targets (including Windows and wasm) are unaffected.

Patches

Pending a proper fix, the internal method that determines the local offset has been modified to always return None on the affected operating systems. This has the effect of returning an Err on the try_* methods and UTC on the non-try_* methods.

Users and library authors with time in their dependency tree should perform cargo update, which will pull in the updated, unaffected code.

Users of time 0.1 do not have a patch and should upgrade to an unaffected version: time 0.2.23 or greater or the 0.3 series.

Workarounds

No workarounds are known.

References

time-rs/time#293

See advisory page for additional details.

RUSTSEC-2020-0036: failure is officially deprecated/unmaintained

failure is officially deprecated/unmaintained

Details
Status unmaintained
Package failure
Version 0.1.8
URL rust-lang-deprecated/failure#347
Date 2020-05-02

The failure crate is officially end-of-life: it has been marked as deprecated
by the former maintainer, who has announced that there will be no updates or
maintenance work on it going forward.

The following are some suggested actively developed alternatives to switch to:

See advisory page for additional details.

Pausing for parallel algorithms

Follow-up to #67 to also implement pausing for parallel algorithms

  • Implement internal early-stopping for parallel algorithms
  • Ensure parallel algorithms correctly set their progress, max time and sync times to account for pause + resume
  • Implement config file output on pause for parallel algorithms

Refactor `resume` branch before merge

  • rustcoalescence/src/args/mod.rs
  • rustcoalescence/src/cli/simulate/*
  • rustcoalescence/algorithms/src/lib.rs
  • rustcoalescence/algorithms/cuda/*
  • rustcoalescence/algorithms/gillespie/*
    • rustcoalescence/algorithms/gillespie/src/event_skipping.rs
    • rustcoalescence/algorithms/gillespie/src/gillespie/mod.rs
    • rustcoalescence/algorithms/gillespie/src/gillespie/classical.rs
  • rustcoalescence/algorithms/independent/*

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.