Skip to content

Refactor models list#39

Closed
alirezazolanvari wants to merge 32 commits into
devfrom
refactor-models-list
Closed

Refactor models list#39
alirezazolanvari wants to merge 32 commits into
devfrom
refactor-models-list

Conversation

@alirezazolanvari
Copy link
Copy Markdown
Member

  • Centralize models registries in params.py
  • Replace abstractmethods in DrugReleaseModel using configs from models registries
  • Remove parameter dataclasses of the models
  • Set default value 1 for the Entire releasable amount (M_0/M) in the respective models
  • Reformat by black

@alirezazolanvari alirezazolanvari self-assigned this Feb 24, 2026
@alirezazolanvari alirezazolanvari added the enhancement New feature or request label Feb 24, 2026
@alirezazolanvari alirezazolanvari added this to the drux v0.4 milestone Feb 24, 2026
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Feb 24, 2026

Codecov Report

❌ Patch coverage is 90.99099% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.12%. Comparing base (0e582b3) to head (6dc9537).
⚠️ Report is 1 commits behind head on dev.

Files with missing lines Patch % Lines
drux/base_model.py 86.67% 3 Missing and 3 partials ⚠️
drux/registry.py 91.84% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev      #39      +/-   ##
==========================================
- Coverage   98.73%   94.12%   -4.60%     
==========================================
  Files           9       10       +1     
  Lines         235      187      -48     
  Branches       26       21       -5     
==========================================
- Hits          232      176      -56     
- Misses          2        7       +5     
- Partials        1        4       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@alirezazolanvari alirezazolanvari marked this pull request as ready for review February 24, 2026 17:51
@codacy-production
Copy link
Copy Markdown

codacy-production Bot commented May 14, 2026

Not up to standards ⛔

🔴 Issues 10 minor

Alerts:
⚠ 10 issues (≤ 0 issues of at least minor severity)

Results:
10 new issues

Category Results
Documentation 8 minor
CodeStyle 2 minor

View in Codacy

🟢 Metrics -3 complexity · 0 duplication

Metric Results
Complexity -3
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@alirezazolanvari
Copy link
Copy Markdown
Member Author

@sepandhaghighi, I revised the changes that were proposed in this PR. The summary of changes and the main idea/motivation behind them are presented below. It might look like more than a single PR, so feel free to let me know to split it into different PRs.

New Architecture

Motivation

Keeping registry info of all the models centralized to be able to build on it for future developments.

File Overview

File Role Key Exports
registry.py Single source of truth: equations, params, validation @equation, register_validation(), register_params(), get_model_config()
messages.py Error message constants ERROR_* string constants
base_model.py Base class + class factory DrugReleaseModel, create_model_class()
<model>.py Model entry points e.g. ZeroOrderModel, WeibullModel
__init__.py Public API surface Re-exports all model classes + version

Dependency Graph

__init__.py
 ├── registry.py ── messages.py
 ├── <model>.py ─── base_model.py
 │                   ├── registry.py
 │                   └── messages.py

Runtime Flow

User calls: ZeroOrderModel(k0=0.5)
         │
         ▼
┌─────────────────────────┐
│  <model>.py              │  create_model_class("zero_order", ...)
│  (factory call)          │  ── runs at import time, produces class
└────────┬────────────────┘
         │  __init__(**kwargs)
         ▼
┌─────────────────────────┐
│  base_model.py           │  1. Applies defaults from registry
│  (generated class)       │  2. Builds SimpleNamespace for parameters
│                          │  3. Stores _model_name, _parameters, _label
└────────┬────────────────┘
         │  .simulate(duration, time_step)
         ▼
┌─────────────────────────┐
│  base_model.py           │  1. _validate_parameters() ← validation from registry
│  DrugReleaseModel        │  2. _model_function(t)     ← equation from registry
│                          │  3. Returns release profile (np.ndarray)
└─────────────────────────┘

Before → After

Aspect Before After
Equations Inline lambda in params.py Named functions in registry.py with @equation
Validation Inline lambda + message imports in params.py register_validation() calls co-located with equations
Params metadata Separate params.py assembling MODELS_REGISTRY register_params() calls co-located with equations
Parameter storage Dynamic make_dataclass via utils.py SimpleNamespace inline in base_model.py
Model classes ~25-line hand-written class per model 1-line create_model_class() call per model
Defaults Duplicated in registry and __init__ signature Registry only (single source)
Base class ABC with no abstract methods Plain class
Files touched to add a model 5+ 2 (see below)
Total core files 8 4

Adding a New Model

All three aspects (params, equation, validation) are added in registry.py under one section:

registry.py                              <model>.py
─────────────                            ─────────────
register_params("name", {...})           from .base_model import create_model_class

@equation("name")                        NameModel = create_model_class(
def name(p, t):                              model_name="name",
    return ...                               class_name="NameModel",
                                             label="Name Model",
register_validation("name", {...})       )

Then add to __init__.py:

from .name import NameModel

Checklist

# File What to add
1 messages.py Error string constants (if new ones needed)
2 registry.py register_params() + @equation function + register_validation()
3 <model>.py Single create_model_class() call (can be done in __init__.py)
4 __init__.py Import the new model class

@alirezazolanvari
Copy link
Copy Markdown
Member Author

Requires more thought on how to implement it according to the best practices. It will be postponed to version 0.5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants