CausalGraphs.jl
A Julia-native framework for representing, analyzing, composing, comparing, and visualizing cause-effect knowledge and models.
Domain-independent causal relationships.
Cause-Effect Knowledge
Build structured graphs independent from models and views.
Multiple Models
Derive models from a single knowledge base without duplication.
Metrology Support
First-class integration with uncertainty propagation workflows.
Introduction
CausalGraphs.jl is a Julia library for rigorously modeling, analyzing, and visualizing cause-and-effect relationships.
Unlike simple drawing tools, CausalGraphs.jl strictly separates knowledge (the relationship graph) from views (Ishikawa diagrams, dependency graphs) and models (measurement models, uncertainty propagation, fault trees).
Common Use Cases
- Metrology and Uncertainty : Map uncertainty sources in a measurement model (e.g., Ishikawa / GUM) to automatically generate mathematical propagation models.
- Systems Engineering and Reliability : Model Fault Trees to identify the root causes of complex problems.
- Incident Analysis (Root Cause Analysis) : Formally record "what caused what" to capture knowledge following an IT or industrial failure.
Visual Examples (Cause-Effect Trees)
Thanks to its decoupled architecture, the same knowledge graph can be exported in visual formats.
Example 1: Metrology (Mass Calibration)
Here is how to build a typical cause-and-effect tree for weighing uncertainty.
using CausalGraphs
using Markdown
struct MermaidDisplay
content::String
end
Base.show(io::IO, ::MIME"text/html", m::MermaidDisplay) = print(io, """
<div class="mermaid">
$(m.content)
</div>
""")
# 1. Create the graph
g = CauseEffectGraph()
# 2. Add the main effect (the problem or measurement)
effect = add_effect!(g, "Weighing Uncertainty")
# 3. Add categories (the "5Ms")
mat = add_category!(g, "Material")
env = add_category!(g, "Environment")
eqp = add_category!(g, "Equipment")
man = add_category!(g, "Manpower")
meth = add_category!(g, "Method")
# 4. Link the effect to categories
add_edge!(g, mat, effect)
add_edge!(g, env, effect)
add_edge!(g, eqp, effect)
add_edge!(g, man, effect)
add_edge!(g, meth, effect)
# 5. Add root causes
add_cause!(g, env, "Air temperature")
add_cause!(g, env, "Buoyancy")
add_cause!(g, eqp, "Balance drift")
add_cause!(g, eqp, "Resolution")
add_cause!(g, mat, "Density")
add_cause!(g, man, "Parallax error")
add_cause!(g, meth, "Calibration procedure")
# 6. Automatic visual rendering via Mermaid
MermaidDisplay(to_ishikawa(g))Example 2: Software Engineering (Server Crash)
Let's model an investigation following a server crash in a web infrastructure.
using CausalGraphs
using Markdown
g_it = CauseEffectGraph()
crash = add_effect!(g_it, "Website Downtime")
db = add_category!(g_it, "Database")
net = add_category!(g_it, "Network")
code = add_category!(g_it, "Application Code")
add_edge!(g_it, db, crash)
add_edge!(g_it, net, crash)
add_edge!(g_it, code, crash)
add_cause!(g_it, db, "CPU Saturation (Locks)")
add_cause!(g_it, db, "Disk Full")
add_cause!(g_it, net, "DDoS Attack")
add_cause!(g_it, net, "TLS Certificate Expiration")
add_cause!(g_it, code, "Memory Leak (OOM)")
add_cause!(g_it, code, "Faulty Deployment")
# Visual rendering
# We can reuse the MermaidDisplay struct defined above, but we have to define it again because Documenter @example blocks are isolated by default unless named the same or using a shared setup.
# Wait, let's redefine it just to be safe.
struct MermaidDisplay
content::String
end
Base.show(io::IO, ::MIME"text/html", m::MermaidDisplay) = print(io, """
<div class="mermaid">
$(m.content)
</div>
""")
MermaidDisplay(to_mermaid(g_it))API Reference
CausalGraphs.AbstractModel — Type
AbstractModelAutomatically generated docstring for AbstractModel.
CausalGraphs.AbstractNode — Type
AbstractNodeAutomatically generated docstring for AbstractNode.
CausalGraphs.CategoryNode — Type
CategoryNodeAutomatically generated docstring for CategoryNode.
CausalGraphs.CauseEffectGraph — Type
CauseEffectGraphAutomatically generated docstring for CauseEffectGraph.
CausalGraphs.CauseNode — Type
CauseNodeAutomatically generated docstring for CauseNode.
CausalGraphs.Causes — Type
CausesAutomatically generated docstring for Causes.
CausalGraphs.ContributesTo — Type
ContributesToAutomatically generated docstring for ContributesTo.
CausalGraphs.DecomposesInto — Type
DecomposesIntoAutomatically generated docstring for DecomposesInto.
CausalGraphs.DependsOn — Type
DependsOnAutomatically generated docstring for DependsOn.
CausalGraphs.Edge — Type
EdgeAutomatically generated docstring for Edge.
CausalGraphs.EffectNode — Type
EffectNodeAutomatically generated docstring for EffectNode.
CausalGraphs.IntermediateNode — Type
IntermediateNodeAutomatically generated docstring for IntermediateNode.
CausalGraphs.IshikawaLayout — Type
IshikawaLayoutA structural layout representing an Ishikawa (Fishbone) diagram. Stores the main effect, category branches, and the underlying root causes for each category.
CausalGraphs.MeasurementModel — Method
MeasurementModelAutomatically generated docstring for MeasurementModel.
CausalGraphs.Model — Type
ModelAutomatically generated docstring for Model.
CausalGraphs.Model — Method
ModelAutomatically generated docstring for Model.
CausalGraphs.NodeID — Type
NodeIDAutomatically generated docstring for NodeID.
CausalGraphs.RelationshipType — Type
RelationshipTypeAutomatically generated docstring for RelationshipType.
Base.write — Method
Base.write(path::AbstractString, g::Union{CauseEffectGraph, AbstractModel})Saves the causal graph or model to a file. The format is inferred from the file extension. Supported formats: .json, .dot (GraphViz).
CausalGraphs.add_category! — Method
add_category!Automatically generated docstring for add_category!.
CausalGraphs.add_cause! — Method
add_cause!Automatically generated docstring for add_cause!.
CausalGraphs.add_cause! — Method
add_cause!Automatically generated docstring for add_cause!.
CausalGraphs.add_edge! — Function
add_edge!Automatically generated docstring for add_edge!.
CausalGraphs.add_effect! — Method
add_effect!Automatically generated docstring for add_effect!.
CausalGraphs.add_input! — Method
add_input!Automatically generated docstring for add_input!.
CausalGraphs.add_intermediate! — Method
add_intermediate!Automatically generated docstring for add_intermediate!.
CausalGraphs.add_to_model! — Method
add_to_model!Automatically generated docstring for add_to_model!.
CausalGraphs.add_to_model! — Method
add_to_model!Automatically generated docstring for add_to_model!.
CausalGraphs.ancestors — Method
ancestorsAutomatically generated docstring for ancestors.
CausalGraphs.compare_models — Method
compare_modelsAutomatically generated docstring for compare_models.
CausalGraphs.descendants — Method
descendantsAutomatically generated docstring for descendants.
CausalGraphs.direct_causes — Method
direct_causesAutomatically generated docstring for direct_causes.
CausalGraphs.direct_effects — Method
direct_effectsAutomatically generated docstring for direct_effects.
CausalGraphs.edge_from_dict — Method
edge_from_dictAutomatically generated docstring for edge_from_dict.
CausalGraphs.has_cycles — Method
has_cyclesAutomatically generated docstring for has_cycles.
CausalGraphs.is_valid — Method
is_validAutomatically generated docstring for is_valid.
CausalGraphs.node_from_dict — Method
node_from_dictAutomatically generated docstring for node_from_dict.
CausalGraphs.paths — Method
pathsAutomatically generated docstring for paths.
CausalGraphs.print_tree — Method
print_tree(g, root_id; indent)Prints a text-based tree representation of the causal graph.
CausalGraphs.read_json — Method
read_jsonAutomatically generated docstring for read_json.
CausalGraphs.rel_from_string — Method
rel_from_stringAutomatically generated docstring for rel_from_string.
CausalGraphs.root_causes — Method
root_causesAutomatically generated docstring for root_causes.
CausalGraphs.set_output! — Method
set_output!Automatically generated docstring for set_output!.
CausalGraphs.to_dict — Method
to_dictAutomatically generated docstring for to_dict.
CausalGraphs.to_dict — Method
to_dictAutomatically generated docstring for to_dict.
CausalGraphs.to_dict — Method
to_dictAutomatically generated docstring for to_dict.
CausalGraphs.to_dict — Method
to_dictAutomatically generated docstring for to_dict.
CausalGraphs.to_dict — Method
to_dictAutomatically generated docstring for to_dict.
CausalGraphs.to_dict — Method
to_dictAutomatically generated docstring for to_dict.
CausalGraphs.to_dict — Method
to_dictAutomatically generated docstring for to_dict.
CausalGraphs.to_dot — Method
to_dot(g)Generates a GraphViz DOT string representation of the graph.
CausalGraphs.to_ishikawa — Method
to_ishikawa(g)Generates a Mermaid JS Ishikawa (fishbone) string representation of the causal graph. Assumes the graph contains one main effect and categories linked to it.
CausalGraphs.to_mermaid — Method
to_mermaid(g; direction="LR")Generates a Mermaid JS graph string representation of the causal graph.
CausalGraphs.write_json — Method
write_jsonAutomatically generated docstring for write_json.