Skip to content

Commit f44523a

Browse files
committed
feat : add CONTRIBUTING.md
1 parent d9875b1 commit f44523a

1 file changed

Lines changed: 140 additions & 0 deletions

File tree

CONTRIBUTING.md

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
# Contributing to CNSD
2+
3+
Thanks for your interest in CNSD (Causal Neuro-Symbolic Diagnosis). This guide
4+
covers how to set up a development environment, the checks your change must pass,
5+
and the review conventions we follow.
6+
7+
CNSD is maintained by two people (see [MAINTAINERS.md](MAINTAINERS.md)). Changes
8+
land through pull requests reviewed by a maintainer.
9+
10+
## Development setup
11+
12+
CNSD requires **Python 3.11+**.
13+
14+
Clone the repo and install it in editable mode. The core install is
15+
deliberately lightweight — no TensorFlow, no DoWhy:
16+
17+
```bash
18+
git clone https://github.com/abhiprd2000/CNSD
19+
cd CNSD
20+
python -m pip install --upgrade pip
21+
pip install -e .
22+
```
23+
24+
Optional feature sets are installed as extras:
25+
26+
```bash
27+
pip install -e ".[perception]" # 1D CNN / S-JEPA backend (TensorFlow, Keras)
28+
pip install -e ".[counterfactual]" # Rung-3 counterfactual layer (DoWhy, pandas, networkx)
29+
pip install -e ".[all]" # everything
30+
```
31+
32+
For reproducing the validation experiments against the exact pinned environment,
33+
use `requirements.txt` instead.
34+
35+
## The core-vs-extras contract
36+
37+
A hard rule in this codebase: **the core package must import without
38+
TensorFlow.** The causal, physics, symbolic, config, SCM, dataset, and diagnosis
39+
layers all work on a core-only install. Only the perception backend (the CNN)
40+
requires the `perception` extra, and only the counterfactual layer requires
41+
`counterfactual`.
42+
43+
Concretely, this must always hold on a core-only install:
44+
45+
```python
46+
import cnsd
47+
from cnsd import Dataset, PhysicsConfig, DiagnosisReport, CNSD # all resolve, no TensorFlow
48+
import cnsd.causal, cnsd.physics, cnsd.config, cnsd.scm # import cleanly
49+
```
50+
51+
CI enforces this in a dedicated job that asserts TensorFlow is absent and then
52+
imports the dependency-light subpackages. If you add a heavy dependency to a
53+
core module, that job will fail. Keep TensorFlow/DoWhy imports lazy (inside the
54+
functions or methods that need them), not at module top level.
55+
56+
## Before you open a PR
57+
58+
Run the same checks CI runs. All three must be green.
59+
60+
**1. Lint and format (Ruff):**
61+
62+
```bash
63+
pip install ruff
64+
ruff check .
65+
ruff format --check .
66+
```
67+
68+
To auto-fix formatting before pushing: `ruff format .`
69+
70+
**2. Tests:**
71+
72+
```bash
73+
pip install pytest
74+
pytest test/ -v
75+
```
76+
77+
The test suite in `test/` is TensorFlow-free by design — it covers the physics
78+
math, the symbolic verdict logic, the causal (Rung-2) layer, the gear/spectral
79+
providers, and consensus fusion. Please keep new tests TF-free where possible;
80+
add them under `test/`.
81+
82+
**3. Import independence:** confirm the core package still imports without
83+
TensorFlow (see the contract above).
84+
85+
## Project layout
86+
87+
The library lives in `cnsd/`, organized one concern per package:
88+
89+
- `cnsd/perception` — Layer 1: 1D CNN + S-JEPA (requires `perception` extra)
90+
- `cnsd/symbolic`, `cnsd/physics` — Layer 2: physics verification and providers
91+
- `cnsd/causal`, `cnsd/scm` — Layer 3: Pearl Rung-2 intervention + refutation
92+
- `cnsd/counterfactual` — Layer 3B: Rung-3 (requires `counterfactual` extra)
93+
- `cnsd/consensus` — Layer 4: verdict + confidence → actionable status
94+
- `cnsd/datasets`, `cnsd/diagnosis` — data contract and pipeline orchestration
95+
96+
`validation/` holds the per-dataset validation runners and the multi-seed
97+
benchmark. These are **not** shipped in the installed package — they're
98+
development/research scripts. Run them as modules from the repo root, e.g.
99+
`python -m validation.multi_seed_benchmark --dataset cwru`. Dataset paths can be
100+
overridden with the `CNSD_DATA_CWRU`, `CNSD_DATA_PU`, and `CNSD_DATA_SEU`
101+
environment variables.
102+
103+
## Pull request conventions
104+
105+
- Open a PR and request review from a maintainer. Tag **both** maintainers for
106+
changes that cross package boundaries or touch the public API
107+
(`cnsd/__init__.py`, `cnsd/diagnosis/system.py`).
108+
- Keep each PR to one scoped change. Smaller PRs are reviewed faster and are
109+
easier to reason about.
110+
- Don't rewrite published history on a shared branch. Avoid force-pushing amends
111+
or replacing an open PR wholesale — it orphans review threads and breaks
112+
auditability. Add follow-up commits instead.
113+
- Write a clear description of what changed and why. If your change was proposed
114+
or shaped by someone else, credit them in the description and commit message.
115+
116+
## Reporting empirical results (integrity)
117+
118+
CNSD is a research framework, and the results it produces go into a paper. We
119+
hold contributions that touch experiments or reported numbers to a specific
120+
standard:
121+
122+
- **Report null and negative results honestly.** A saturated-regime null or a
123+
transfer that degrades is a valid, informative outcome — report it as such, at
124+
equal prominence with positive results. Do not quietly drop, reframe, or
125+
re-run experiments until they look favorable.
126+
- **No overclaiming.** State what an experiment shows, and no more. Don't imply a
127+
layer drives accuracy when it provides a causal or stability perspective; don't
128+
present a demonstration as a discovered effect.
129+
- **Results come from artifacts, not by hand.** Record experimental results as
130+
logged artifacts (e.g. JSON) produced by the run, not hand-transcribed into
131+
tables. The git commit timestamp is the authoritative date. Hand-edited result
132+
tables will be sent back in review.
133+
- **Reviewers check for this.** PRs that add or modify results are reviewed for
134+
overclaims, misframing, and data-integrity issues before merge. This is not
135+
personal — it's how the project stays trustworthy.
136+
137+
## Questions
138+
139+
Open an issue or start a discussion on GitHub. For anything about who reviews
140+
what, see [MAINTAINERS.md](MAINTAINERS.md).

0 commit comments

Comments
 (0)