Skip to content

Commit 752d524

Browse files
committed
feat: Implement SEU Gearbox validation and fix physics config
2 parents a9a2859 + 5c6d07c commit 752d524

81 files changed

Lines changed: 1096 additions & 383 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
test:
15+
name: tests (py${{ matrix.python-version }})
16+
runs-on: ubuntu-latest
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
python-version: ["3.11", "3.12", "3.13"]
21+
22+
steps:
23+
- uses: actions/checkout@v4
24+
25+
- name: Set up Python ${{ matrix.python-version }}
26+
uses: actions/setup-python@v5
27+
with:
28+
python-version: ${{ matrix.python-version }}
29+
cache: pip
30+
31+
- name: Install core dependencies
32+
run: |
33+
python -m pip install --upgrade pip
34+
pip install -e .
35+
pip install pytest
36+
37+
- name: Run unit tests
38+
run: pytest test/ -v
39+
40+
import-independence:
41+
name: import-independence (no TensorFlow)
42+
runs-on: ubuntu-latest
43+
steps:
44+
- uses: actions/checkout@v4
45+
46+
- name: Set up Python
47+
uses: actions/setup-python@v5
48+
with:
49+
python-version: "3.12"
50+
cache: pip
51+
52+
- name: Install core dependencies only
53+
run: |
54+
python -m pip install --upgrade pip
55+
pip install -e .
56+
57+
- name: Assert TensorFlow is absent
58+
run: |
59+
python - <<'PY'
60+
import importlib.util, sys
61+
if importlib.util.find_spec("tensorflow") is not None:
62+
sys.exit("TensorFlow is installed; this job must run without it.")
63+
print("confirmed: TensorFlow not installed")
64+
PY
65+
66+
- name: Import dependency-light subpackages
67+
run: |
68+
python - <<'PY'
69+
import importlib
70+
for mod in ("cnsd.causal", "cnsd.physics", "cnsd.config", "cnsd.scm"):
71+
importlib.import_module(mod)
72+
print(f"imported {mod} without TensorFlow")
73+
PY
74+
75+
install:
76+
name: editable install
77+
runs-on: ubuntu-latest
78+
steps:
79+
- uses: actions/checkout@v4
80+
81+
- name: Set up Python
82+
uses: actions/setup-python@v5
83+
with:
84+
python-version: "3.12"
85+
cache: pip
86+
87+
- name: Install package (editable, core extras)
88+
run: |
89+
python -m pip install --upgrade pip
90+
pip install -e .
91+
92+
- name: Import installed package
93+
run: python -c "import cnsd; print('cnsd installed and importable')"

.github/workflows/lint.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Lint
2+
3+
# Static checks: Ruff handles both linting and formatting in a single tool.
4+
# Fast (seconds), no project dependencies needed, runs on every push and PR.
5+
6+
on:
7+
push:
8+
branches: [main]
9+
pull_request:
10+
branches: [main]
11+
12+
concurrency:
13+
group: lint-${{ github.ref }}
14+
cancel-in-progress: true
15+
16+
jobs:
17+
ruff:
18+
name: ruff (lint + format)
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v4
22+
23+
- name: Set up Python
24+
uses: actions/setup-python@v5
25+
with:
26+
python-version: "3.12"
27+
28+
- name: Install Ruff
29+
run: pip install ruff
30+
31+
# Linting: flags unused imports, undefined names, common bugs.
32+
- name: Ruff lint
33+
run: ruff check .
34+
35+
# Formatting: verifies code matches the formatter (does not modify it).
36+
# Run `ruff format .` locally to fix before pushing.
37+
- name: Ruff format check
38+
run: ruff format --check .

100.mat

904 KB
Binary file not shown.

CHANGELOG.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Changelog
2+
3+
All notable changes to CNSD are documented here. The format is based on
4+
[Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project
5+
adheres to semantic versioning once it reaches 1.0.
6+
7+
## [Unreleased]
8+
9+
### Added
10+
- Pluggable `PhysicsProvider` interface — the diagnosis engine is now
11+
domain-agnostic; machine classes plug in as providers.
12+
- `BearingProvider` (ball-pass-frequency physics) and `SpectralProvider` (the
13+
universal zero-knowledge fallback).
14+
- `GearProvider` and gear-mesh physics (GMF + sidebands) for gearbox diagnosis.
15+
- Configuration layer: YAML-driven physics and taxonomy, resolved into providers
16+
by `cnsd/builder.py`.
17+
- Real Pearl Rung-3 counterfactuals via DoWhy `gcm`, with a local-sensitivity
18+
fallback when DoWhy is unavailable.
19+
- Universal `Dataset` contract (`Dataset.from_arrays`) so any vibration dataset
20+
plugs in without a bespoke loader.
21+
- Validation scripts for CWRU (`validate_run.py`) and SEU gears
22+
(`validate_seu.py`), and a cross-condition robustness script.
23+
- Test suite covering the physics, symbolic, causal, consensus, and provider
24+
layers.
25+
26+
### Changed
27+
- Symbolic layer rewritten to verify predictions against physics via a provider
28+
and a configurable taxonomy (replacing a hardcoded, CWRU-specific lookup).
29+
- Causal layer scoped honestly to Pearl Rung 2 (effect of operating condition)
30+
on a corrected DAG; the counterfactual layer carries Rung 3.
31+
32+
### Notes
33+
- Pre-1.0 research software. Interfaces may change. Not intended for
34+
safety-critical deployment without independent validation.
35+
36+
## History
37+
38+
CNSD began as a five-layer causal-neuro-symbolic diagnosis prototype and was
39+
rebuilt into a domain-agnostic framework: the physics-verification layer was made
40+
real (independent characteristic-frequency checks that can override the neural
41+
prediction), the causal claims were scoped honestly, and the system was
42+
reorganized into a deployable package.
43+
44+
## Project history
45+

CODE_OF_CONDUCT.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Code of Conduct
2+
3+
## Our Pledge
4+
5+
We as members, contributors, and maintainers pledge to make participation in
6+
CNSD a harassment-free experience for everyone, regardless of age, body
7+
size, visible or invisible disability, ethnicity, sex characteristics, gender
8+
identity and expression, level of experience, education, socio-economic status,
9+
nationality, personal appearance, race, religion, or sexual identity and
10+
orientation.
11+
12+
We pledge to act and interact in ways that contribute to an open, welcoming,
13+
diverse, inclusive, and healthy community.
14+
15+
## Our Standards
16+
17+
Examples of behavior that contributes to a positive environment:
18+
19+
- Demonstrating empathy and kindness toward other people
20+
- Being respectful of differing opinions, viewpoints, and experiences
21+
- Giving and gracefully accepting constructive feedback
22+
- Accepting responsibility, apologizing to those affected by our mistakes, and
23+
learning from the experience
24+
- Focusing on what is best for the project and the community
25+
26+
Examples of unacceptable behavior:
27+
28+
- The use of sexualized language or imagery, and sexual attention or advances
29+
- Trolling, insulting or derogatory comments, and personal or political attacks
30+
- Public or private harassment
31+
- Publishing others' private information without explicit permission
32+
- Other conduct which could reasonably be considered inappropriate in a
33+
professional setting
34+
35+
## Enforcement Responsibilities
36+
37+
Project maintainers are responsible for clarifying and enforcing these standards
38+
and will take appropriate and fair corrective action in response to any behavior
39+
they deem inappropriate, threatening, offensive, or harmful.
40+
41+
## Scope
42+
43+
This Code of Conduct applies within all project spaces and also applies when an
44+
individual is officially representing the project in public spaces.
45+
46+
## Enforcement
47+
48+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
49+
reported to the maintainers listed in MAINTAINERS.md. All complaints will be
50+
reviewed and investigated promptly and fairly. Maintainers are obligated to
51+
respect the privacy and security of the reporter of any incident.
52+
53+
## Attribution
54+
55+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
56+
version 2.1, available at
57+
https://www.contributor-covenant.org/version/2/1/code_of_conduct.html.
58+
59+
[homepage]: https://www.contributor-covenant.org

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2026 Abhimanyu Prasad and Kazi Tasfin Mahmud
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

MAINTAINERS.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Maintainers
2+
3+
CNSD is developed and maintained by:
4+
5+
- **Abhimanyu Prasad** ([@abhiprd2000](https://github.com/abhiprd2000)) — lead developer
6+
- **Kazi Tasfin Mahmud** ([@TasfinMahmud](https://github.com/TasfinMahmud)) — lead developer
7+
8+
Both maintainers review and merge changes. For substantial changes, open a pull
9+
request and request review from a maintainer.
10+
11+
## Areas
12+
13+
The codebase is organized one concern per package (`cnsd/diagnosis`,
14+
`cnsd/causal`, `cnsd/counterfactual`, `cnsd/physics`, `cnsd/symbolic`,
15+
`cnsd/datasets`). Either maintainer can review any area; tag both for changes
16+
that cross package boundaries or touch the public API (`cnsd/__init__.py`,
17+
`cnsd/diagnosis/system.py`).

SECURITY.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Security Policy
2+
3+
CNSD is a research framework for machine fault diagnosis. It is not intended for
4+
safety-critical deployment without independent validation (see the limitations
5+
in the README).
6+
7+
## Reporting a vulnerability
8+
9+
If you find a security issue — for example, a way for crafted input data or a
10+
malicious config/YAML file to cause unsafe behavior — please report it privately
11+
rather than opening a public issue.
12+
13+
- Use GitHub's **private vulnerability reporting** (the "Report a vulnerability"
14+
button under the repository's *Security* tab), or
15+
- Contact a maintainer directly (see MAINTAINERS.md).
16+
17+
Please include a description, steps to reproduce, and the affected version or
18+
commit. We will acknowledge reports and address confirmed issues as promptly as
19+
we can.
20+
21+
## Supported versions
22+
23+
This is 1.0 research software. Only the latest
24+
commit on `main` is supported; fixes are not backported.
25+
26+
## Scope
27+
28+
CNSD loads user-supplied data and configuration (including YAML). Treat data and
29+
config files from untrusted sources with the same caution as any code — a
30+
configuration file can change which physics and taxonomy the system applies.
11.6 KB
Binary file not shown.

cnsd/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
intervention_effect_of_condition` does NOT require TensorFlow. Only the full
2121
CNSD system (which trains the CNN) needs the perception backend.
2222
"""
23+
2324
__version__ = '1.0.0'
2425

2526
# Lazy top-level names (PEP 562): keeps `from cnsd import CNSD` working without
@@ -37,6 +38,7 @@
3738
def __getattr__(name):
3839
if name in _LAZY:
3940
import importlib
41+
4042
module, attr = _LAZY[name]
4143
return getattr(importlib.import_module(module), attr)
4244
raise AttributeError(f"module 'cnsd' has no attribute '{name}'")

0 commit comments

Comments
 (0)