Skip to main content

DagSim

Binder

DagSim is a Python-based framework and specification language for simulating data based on a Directed Acyclic Graph ( DAG) structure, without any constraints on variable types or functional relations. A succinct YAML format for defining the structure of the simulation model promotes transparency, while separate user-provided functions for generating each variable based on its parents ensure the modularization of the simulation code.

Link to the paper: https://journals.plos.org/plosone/article?id=10.1371/journal.pone.0284443

Installation

DagSim can be easily installed using pip.

Installing DagSim using pip

To install the DagSim package using pip, run:

pip install dagsim

Quickstart

To check that DagSim is installed properly, run the following command in the console/terminal:

dagsim-quickstart

Installing graphviz

If you use pip, you need to install graphviz on the system level in order to use the drawing functionality in DagSim. Please follow the instrcutions here on how to install graphviz depending on the operating system.

Simple example

Python code

Suppose we are interested in simulating two variables, X and Y, where X follows a standard Gaussian distribution, and Y is the square of X.

For each node we need a function to simulate the node's values:

  • For X, we can use the numpy.random.normal function
  • For Y, we can use either numpy.power or define our own function. We will use the second to illustrate how one can use user-define functions.
# needed imports
import dagsim.base as ds
import numpy as np

Here, we define our own square function:

def square(arg):
    return arg * arg

Then, we define the nodes in our graph/model by giving each node a name, the function to use in order to evaluate its value, and the arguments of the function, if any:

X = ds.Node(name="X", function=np.random.normal)
Y = ds.Node(name="Y", function=square, kwargs={"arg": X})

After that, we define the graph itself by giving it a name (optional) and a list of all the nodes to be included:

graph = ds.Graph(name="demo_graph", list_nodes=[X, Y])

If you wish, you can draw the graph by calling the draw method, as follows:

graph.draw()

Finally, we simulate data from this graph by calling the simulate method, and giving it the number of samples you want to simulate, and a name for the csv_file (optional) where the data should be saved.

data = graph.simulate(num_samples=10, csv_name="demo_data")

Here, data would be a dictionary with keys being the names of the nodes in the graph, and the corresponding values being the simulated values for each node returned as a Python list.

For more detailed instructions, check this page, and for other simple examples, please refer to the tutorials folder.

YAML Specification

dagsim also allows the specification of a simulation using a YAML file. You can run dagsim on a YAML file by running:

dagsim path/to/yaml/file [-v|--verbose] [-d|--draw] [-o output/path|--output_path=output/path]

For a tutorial on using a YAMl file for simulation, check this page.

Metadata

Release files for dagsim 1.0.10

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

Source distribution (sdist)

Source distribution for dagsim 1.0.10
File Size Uploaded Provenance
dagsim-1.0.10.tar.gz 29.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for dagsim 1.0.10
File Interpreter ABI Platform
dagsim-1.0.10-py3-none-any.whl Python 3 none any Details

Total release size: 60.3 kB

Release files / dagsim-1.0.10.tar.gz

Download URL dagsim-1.0.10.tar.gz
Size 29.9 kB
Tags Source
SHA-256 checksum
How to use checksums
3bcb6e7e9c3374d6926a29ed9b3d230ee6d3d0f7c5d8a619d18735f5ebe10771
BLAKE2b-256 checksum
How to use checksums
0c2338bf9472e11adf6b583b29dcc535fec2e4a7d1273b136fc04f38922be11a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / dagsim-1.0.10-py3-none-any.whl

Download URL dagsim-1.0.10-py3-none-any.whl
Size 30.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f42307f8d18fbef66faaf82302f7034f5e4746a94ce0c872acf19f98e45fa61b
BLAKE2b-256 checksum
How to use checksums
67e6663b8bccb5195219000b830ccc65564f508c25a69adbb286c677f082c8a1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Security for dagsim 1.0.10

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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