Upgrade to Pro — share decks privately, control downloads, hide ads and more …

xarray-simlab: A Python package to build, customize and run computational models interactively

Benoît Bovy
December 14, 2018

xarray-simlab: A Python package to build, customize and run computational models interactively

Lightning talk given at AGU (Dec 2018) on the xarray-simlab Python package.

https://github.com/benbovy/xarray-simlab
https://xarray-simlab.readthedocs.io/en/latest/

Benoît Bovy

December 14, 2018
Tweet

More Decks by Benoît Bovy

Other Decks in Science

Transcript

  1. xarray-simlab 1 GFZ Potsdam, Germany Benoît Bovy1 and Jean Braun1

    AGU 2018 A Python package to build, customize and run computational models interactively
  2. The problem After several years of “organic” development and lots

    of
 experiments: Hard to maintain, steep learning curve We, (Geo)Scientists, mostly implement models ourselves. Software and API design is not our primary concern.
  3. Our proposed solution xarray-simlab: a domain-agnostic, lightweight
 modelling framework in

    Python. Goal: Let domain experts focus their coding effort on
 scientific development.
  4. What users need to provide Model components: small Python classes

    @xsimlab.process class Topography(object): elevation = xsimlab.variable(dims=('y', 'x'), intent='inout', description='topographic elevation') total_erosion = xsimlab.foreign(TotalErosion, 'erosion') total_uplift = xsimlab.foreign(TotalRockUplift, ‘uplift’) def initialize(self): self.elevation_change = np.zeros_like(self.elevation) def run_step(self, *args): self.elevation_change = self.total_uplift - self.total_erosion def finalize_step(self): self.elevation += self.elevation_change # Declare some (references to) variables… # Do something with it (maybe wrap existing code)
  5. What users need to provide Models: collections of components model

    = xsimlab.Model({'grid': Grid2D, 'boundaries': BoundaryFacesXY, 'block_uplift': BlockUplift, 'flow_routing': FlowRouterD8, 'area': PropagateArea, 'spower': StreamPower, 'diffusion': LinearDiffusion, 'erosion': TotalErosion, 'uplift': TotalRockUplift, 'topography': Topography})
  6. What users get (for free) Interactive introspection model.visualize(show_inputs=True) grid boundaries

    flow_routing area diffusion block_uplift uplift spower erosion topography k_coef u_coef length m_exp spacing n_exp elevation k_coef Input variables Workflow dependencies Processes
  7. What users get (for free) Extensible models extended_model = model.update_processes({'lithology':

    Lithology}) extended_model.visualize(show_inputs=True) grid boundaries flow_routing area diffusion block_uplift uplift spower lithology erosion topography rock_resistivity u_coef length m_exp spacing n_exp elevation
  8. What users get (for free) xarray interface (Dataset in ->

    Dataset out) in_ds = xsimlab.create_setup(model=model, clocks={…}, input_vars={…}, output_vars={…}) out_ds = in_ds.xsimlab.run(model=model) <xarray.Dataset> Dimensions: (out_time: 16, time: 151, x: 401, y: 401) Coordinates: * time (time) float64 0.0 1e+04 2e+04 3e+04 ... * out_time (out_time) float64 0.0 1e+05 2e+05 ... Dimensions without coordinates: x, y Data variables: grid__length float64 1e+05 grid__spacing float64 250.0 topography__elevation (out_time, y, x) float64 0.4789 0.03577 ... spower__k_coef float64 7e-05 spower__m_exp float64 0.4 spower__n_exp int64 1 diffusion__k_coef float64 0.1 block_uplift__u_coef float64 0.002 grid__x (x) float64 0.0 250.0 500.0 750.0 1e+03 ... grid__y (y) float64 0.0 250.0 500.0 750.0 1e+03 ...
  9. Roadmap Much more features • Auto-documentation • Command-line interface and

    I/O files • Graphical interfaces (web-based, Jupyter widgets, desktop…) • Tools for simulation diagnostics / monitoring / profiling • Optimization / inference / sensitivity analyses • Parallel computation (using Dask) • Run models and analyse outputs in the cloud or HPC (Pangeo) • … Code repository: https://github.com/benbovy/xarray-simlab Documentation: http://xarray-simlab.readthedocs.io Feedback and contributions are very welcome!