pgmpy
Route pgmpy causal and probabilistic graphical-model tasks to focused modeling, learning, inference, causal, data I/O, and extension workflows.
- License 许可
- MIT
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- pgmpy
- license
- MIT
- metadata
- { "disco-role": "operating" }
- description
- Route pgmpy causal and probabilistic graphical-model tasks to focused modeling, learning, inference, causal, data I/O, and extension workflows.
- disable-model-invocation
- true
02 资源文件 5
- 参考文档references/package-map.md6.2 KB
- 参考文档references/repo-provenance.md2.2 KB
- 参考文档references/repo-routing-metadata.json532 B
- 参考文档references/troubleshooting.md4.5 KB
- 脚本scripts/check_pgmpy_environment.py5.0 KB
03 SKILL.md 正文
pgmpy
Use this repo skill when the task names pgmpy or asks for Python workflows around causal graphs, Bayesian networks, Markov networks, conditional probability distributions, structure learning, probabilistic inference, causal identification/effect estimation, example graphical models, model file formats, or pgmpy extension work.
pgmpy is a Python package for causal and probabilistic reasoning with graphical models. It provides graph/model classes, CPDs and factors, causal discovery, parameter estimation, inference, sampling/simulation, causal identification and prediction, datasets/example models, metrics, and read/write utilities.
First checks
- Install/use pgmpy with Python 3.10-3.14. For package use, start with
pip install pgmpyorconda install conda-forge::pgmpy. - For local repository maintenance, prefer
pip install -e .[tests]and focusedpytesttargets. Do not commit or push from an agent session. - Optional surfaces require explicit extras:
pgmpy[torch]forFunctionalBayesianNetwork/FunctionalCPD;pgmpy[optional]for plotting, xgboost, and LLM-assisted discovery dependencies. Provider credentials/network are still separate requirements. - To verify an installed package without source checkout access, run
python scripts/check_pgmpy_environment.py --jsonfrom the skill root. Add--check-optionalonly when optional imports matter. - Read
references/repo-provenance.mdbefore refreshing this skill for a changed checkout. - Read
references/package-map.mdwhen choosing between canonical modules, legacy compatibility imports, optional extras, and public entry points. - Read
references/troubleshooting.mdfor cross-cutting install/import, optional dependency, state-name, network/cache, and package-version issues before diving into a sub-skill.
Route by task
| User task | Read |
|---|---|
Build a DAG, PDAG, ADMG, MAG, BN, DBN, Markov network, factor graph, CPD, or factor; debug check_model() or CPD shapes. |
modeling-and-factors |
| Learn graph structure, choose PC/GES/HillClimb/Chow-Liu/TAN, select CI tests or scores, use expert knowledge, or fit CPDs from data. | learning-structure-and-parameters |
| Query posterior probabilities, run MAP, use Variable Elimination or Belief Propagation, sample/simulate from a fitted model, or work with DBN inference. | inference-sampling-and-simulation |
Identify adjustment/frontdoor sets, use CausalInference.query(..., do=...), estimate ATE, or use causal prediction regressors. |
causal-identification-and-effects |
| Load/list built-in datasets or example models, save/load BIF/XMLBIF/NET/UAI/XDSL files, or compute graph/data evaluation metrics. | data-io-and-evaluation |
| Add a new causal discovery algorithm, CI test, score, metric, dataset, or example model to a pgmpy checkout. | extending-pgmpy |
Routing rules and boundaries
- If the user only needs a graph object with roles and no CPDs, start in
modeling-and-factors; do not force a Bayesian-network model. - If the user has data and wants a learned graph or learned CPDs, route to
learning-structure-and-parameters, then back tomodeling-and-factorsonly for model-family construction details. - If the user asks for
P(Y | X=x), posterior marginals, MAP, or sampling under evidence, route toinference-sampling-and-simulation. If they ask fordo(X=x), ATE, adjustment, frontdoor, instruments, or treatment effects, route tocausal-identification-and-effects. - If a workflow begins by loading
bnlearn/alarm, a dataset name, or a.bif/.uai/.xmlbiffile, route first todata-io-and-evaluation, then to the workflow that consumes the loaded object. - Prefer canonical packages for new code:
pgmpy.causal_discovery,pgmpy.parameter_estimator,pgmpy.structure_score,pgmpy.ci_tests,pgmpy.metrics,pgmpy.datasets, andpgmpy.example_models. Treatpgmpy.estimatorsas a legacy compatibility surface unless the task is explicitly maintaining backwards compatibility. - Do not treat optional torch/Pyro functional models, LLM-assisted discovery, plotting backends, or remote HuggingFace-backed assets as verified unless the user environment explicitly has the needed extras, credentials, network/cache, and hardware.
Common package facts
- Core CPU workflows use NetworkX, NumPy, SciPy, pandas, scikit-learn, statsmodels, tqdm, pyparsing, joblib, opt_einsum, scikit-base, and HuggingFace Hub helpers.
BayesianNetworkandMarkovNetworkare deprecated aliases forDiscreteBayesianNetworkandDiscreteMarkovNetwork.- Most user-facing algorithms expose sklearn-like constructors and
fit(...); fitted discovery results are typically available ascausal_graph_andadjacency_matrix_. - Model validation is not optional. Run
check_model()before inference, simulation, serialization, or causal queries on parameterized models. - Use
show_progress=Falsein automated examples/tests unless progress bars are explicitly useful.
Safe validation
For a quick installed-package check:
python scripts/check_pgmpy_environment.py --json
For workflow-specific checks, use the nearest bundled script:
modeling-and-factors/scripts/check_modeling_smoke.pylearning-structure-and-parameters/scripts/learn_structure_smoke.pyinference-sampling-and-simulation/scripts/inference_smoke.pycausal-identification-and-effects/scripts/causal_effect_smoke.pydata-io-and-evaluation/scripts/data_io_smoke.pyextending-pgmpy/scripts/extension_template_check.py
These scripts are deterministic, no-network by default, and do not require the original repository checkout except extension_template_check.py, which is intentionally a checkout-maintenance helper and requires --repo when run away from the checkout.
04 同仓库更多 Skills
passnet-triton-opt
Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.
passnet-solve
END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.
passnet-skill
PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.
passnet-pattern-fusion
Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.
passnet-orchestrate
Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.
passnet-feedback
Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).