The caugi package provides a native JSON-based serialization format for saving and loading causal graphs. This format enables reproducible research, data sharing, and caching of graph structures.
The caugi format uses a simple, human-readable JSON structure:
{
"$schema": "https://caugi.org/schemas/caugi-v1.schema.json",
"format": "caugi",
"version": "1.0.0",
"graph": {
"class": "DAG",
"nodes": [
"A",
"B",
"C",
"D"
],
"edges": [
{
"from": "A",
"to": "B",
"edge": "-->"
},
{
"from": "A",
"to": "C",
"edge": "-->"
},
{
"from": "B",
"to": "D",
"edge": "-->"
},
{
"from": "C",
"to": "D",
"edge": "-->"
}
]
},
"meta": {
"comment": "Example causal graph",
"tags": [
"research",
"example"
]
}
}
$schema
reference for IDE validationThe format supports all caugi edge types using their DSL operators:
| Operator | Description | Graph Types |
|---|---|---|
--> |
Directed edge | DAG, PDAG, ADMG, UNKNOWN |
--- |
Undirected edge | UG, PDAG, UNKNOWN |
<-> |
Bidirected edge | ADMG, UNKNOWN |
o-> |
Partially directed | PDAG, UNKNOWN |
--o |
Partially undirected | PDAG, UNKNOWN |
o-o |
Partial (both circles) | PDAG, UNKNOWN |
For programmatic use, you can serialize to/from strings:
# Serialize to JSON string
json_str <- caugi_serialize(cg)
cat(substr(json_str, 1, 200), "...\n")
#> {
#> "$schema": "https://caugi.org/schemas/caugi-v1.schema.json",
#> "format": "caugi",
#> "version": "1.0.0",
#> "graph": {
#> "class": "DAG",
#> "nodes": [
#> "A",
#> "B",
#> "C",
#> "D"
#> ...
# Deserialize from JSON string
cg_from_json <- caugi_deserialize(json_str)For large graphs, you can defer building:
The format supports all caugi graph classes:
# DAG
dag <- caugi(X %-->% Y, Y %-->% Z, class = "DAG")
# PDAG (with undirected edges)
pdag <- caugi(X %-->% Y, Y %---% Z, class = "PDAG")
# ADMG (with bidirected edges)
admg <- caugi(X %-->% Y, Y %<->% Z, class = "ADMG")
# UG (undirected graph)
ug <- caugi(X %---% Y, Y %---% Z, class = "UG")
# Save them all
write_caugi(dag, tempfile(fileext = ".caugi.json"))
write_caugi(pdag, tempfile(fileext = ".caugi.json"))
write_caugi(admg, tempfile(fileext = ".caugi.json"))
write_caugi(ug, tempfile(fileext = ".caugi.json"))We recommend using .caugi.json as the file extension to
clearly indicate both the format and content type. This helps tools
recognize the files and enables automatic handling by IDEs and
validators.
All files generated by write_caugi() include a
$schema field pointing to the formal JSON Schema
specification:
https://caugi.org/schemas/caugi-v1.schema.json
This enables:
Serialization is implemented in Rust for high performance. Large graphs serialize and deserialize efficiently: