Castle Algorithm#3422
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Introduces a new CASTLE causal discovery estimator and exposes it via the pgmpy.causal_discovery package API.
Changes:
- Added a new
pgmpy/causal_discovery/castle.pymodule with configuration dataclasses and a (currently stubbed) CASTLE implementation. - Exported
CASTLEfrompgmpy/causal_discovery/__init__.py.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| pgmpy/causal_discovery/castle.py | Adds CASTLE module skeleton, torch soft-dependency check, and public CASTLE class stub. |
| pgmpy/causal_discovery/init.py | Exposes CASTLE in the package-level API (__all__). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -1,3 +1,4 @@ | |||
| from .castle import CASTLE | |||
| _check_soft_dependencies( | ||
| "torch", | ||
| msg=("CASTLE requires torch to be installed. "), | ||
| ) | ||
| torch = _safe_import("torch") | ||
| nn = torch.nn |
| edge_threshold: float | ||
|
|
||
|
|
||
| class _CASTLEModel(nn.Module): |
| def train(self, X_tensor): | ||
| """Train the CASTLE model and return the adjacency matrix.""" | ||
| # TODO: Implement the CASTLE training loop. | ||
| raise NotImplementedError("TBD") |
| raise NotImplementedError("TBD") | ||
|
|
||
|
|
||
| class CASTLE(_BaseCausalDiscovery): |
| def __init__( | ||
| self, | ||
| dag_weight: float = 1.0, | ||
| sparsity_weight: float = 5.0, | ||
| dag_penalty: float = 1.0, | ||
| optimizer: object | None = None, | ||
| batch_size: int = 32, | ||
| hidden_dim: int = 32, | ||
| edge_threshold: float = 0.3, | ||
| target_col: int | str | None = None, | ||
| max_epochs: int = 200, | ||
| min_loss_improvement: float = 1e-4, | ||
| early_stop_patience: int = 10, | ||
| scaler: object | None = None, | ||
| tensorboard_log_dir: str | None = None, | ||
| seed: int = 42, | ||
| ): | ||
| """Initialize the CASTLE estimator.""" | ||
| # TODO: Implement CASTLE parameter setup. | ||
| raise NotImplementedError("TBD") |
|
@ankurankan @DARHWOLF |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #3422 +/- ##
==========================================
+ Coverage 95.72% 95.75% +0.02%
==========================================
Files 585 587 +2
Lines 33074 33312 +238
==========================================
+ Hits 31661 31897 +236
- Misses 1413 1415 +2
|
The following checklist is mandatory
Your PR will be closed if you remove the checklist. Use of LLMs is strictly forbidden for any part of this checklist (including for improving language), and will result in a ban if we find any use of LLMs.
Your checklist for this pull request
If you have used AI/LLMs for any assistance, please answer the following questions. Please refer #2622 for an example of the level of detail we expect:
Have you reviewed our AI usage policy?
Are you able to fully explain your changes? We expect you to fully understand the algorithm and take full responsibility for any changes in this PR.
Please list the AI tool(s) used, along with the model and its version used.
GPT - 5.2 Codex
I provided the detailed api of the algorithm to it and asked to just write the skeleton of the algorithm with TBD inside the actual function which will be implemented later on
I have gone through the provided skeleton and cross checked everything with the api. Tests are TBD.
TBD
Issue number(s) that this pull request fixes
List of changes to the codebase in this pull request
pgmpy/pgmpy/castle.pypgmpy/pgmpy/__init__.pywith the castle algorithm