chore: remove deprecated flow_boundary and update docs to match new architecture

This commit is contained in:
Sepehr
2026-03-01 20:00:09 +01:00
parent 20700afce8
commit d88914a44f
105 changed files with 11222 additions and 2994 deletions

View File

@@ -1,6 +1,6 @@
# Story 9.8: SystemState Dedicated Struct
Status: ready-for-dev
Status: done
## Story
@@ -36,41 +36,41 @@ so that I have layout validation, typed access methods, and better semantics for
## Tasks / Subtasks
- [ ] Task 1: Create `SystemState` struct in `entropyk_core` (AC: 1, 3, 4)
- [ ] Create `crates/core/src/state.rs` with `SystemState` struct
- [ ] Implement `new(edge_count)`, `from_vec()`, `edge_count()`
- [ ] Implement `pressure()`, `enthalpy()` returning `Option<Pressure/Enthalpy>`
- [ ] Implement `set_pressure()`, `set_enthalpy()` accepting typed values
- [ ] Implement `as_slice()`, `as_mut_slice()`, `into_vec()`
- [ ] Implement `iter_edges()` iterator
- [x] Task 1: Create `SystemState` struct in `entropyk_core` (AC: 1, 3, 4)
- [x] Create `crates/core/src/state.rs` with `SystemState` struct
- [x] Implement `new(edge_count)`, `from_vec()`, `edge_count()`
- [x] Implement `pressure()`, `enthalpy()` returning `Option<Pressure/Enthalpy>`
- [x] Implement `set_pressure()`, `set_enthalpy()` accepting typed values
- [x] Implement `as_slice()`, `as_mut_slice()`, `into_vec()`
- [x] Implement `iter_edges()` iterator
- [ ] Task 2: Implement trait compatibility (AC: 2)
- [ ] Implement `AsRef<[f64]>` for solver compatibility
- [ ] Implement `AsMut<[f64]>` for mutable access
- [ ] Implement `From<Vec<f64>>` and `From<SystemState> for Vec<f64>`
- [ ] Implement `Default` trait
- [x] Task 2: Implement trait compatibility (AC: 2)
- [x] Implement `AsRef<[f64]>` for solver compatibility
- [x] Implement `AsMut<[f64]>` for mutable access
- [x] Implement `From<Vec<f64>>` and `From<SystemState> for Vec<f64>`
- [x] Implement `Default` trait
- [ ] Task 3: Export from `entropyk_core` (AC: 5)
- [ ] Add `state` module to `crates/core/src/lib.rs`
- [ ] Export `SystemState` from crate root
- [x] Task 3: Export from `entropyk_core` (AC: 5)
- [x] Add `state` module to `crates/core/src/lib.rs`
- [x] Export `SystemState` from crate root
- [ ] Task 4: Migrate from type alias (AC: 5)
- [ ] Remove `pub type SystemState = Vec<f64>;` from `crates/components/src/lib.rs`
- [ ] Add `use entropyk_core::SystemState;` to components crate
- [ ] Update solver crate imports if needed
- [x] Task 4: Migrate from type alias (AC: 5)
- [x] Remove `pub type SystemState = Vec<f64>;` from `crates/components/src/lib.rs`
- [x] Add `use entropyk_core::SystemState;` to components crate
- [x] Update solver crate imports if needed
- [ ] Task 5: Add unit tests (AC: 3, 4)
- [ ] Test `new()` creates correct size
- [ ] Test `pressure()`/`enthalpy()` accessors
- [ ] Test out-of-bounds returns `None`
- [ ] Test `from_vec()` with valid and invalid data
- [ ] Test `iter_edges()` iteration
- [ ] Test `From`/`Into` conversions
- [x] Task 5: Add unit tests (AC: 3, 4)
- [x] Test `new()` creates correct size
- [x] Test `pressure()`/`enthalpy()` accessors
- [x] Test out-of-bounds returns `None`
- [x] Test `from_vec()` with valid and invalid data
- [x] Test `iter_edges()` iteration
- [x] Test `From`/`Into` conversions
- [ ] Task 6: Add documentation (AC: 5)
- [ ] Add rustdoc for struct and all public methods
- [ ] Document layout: `[P_edge0, h_edge0, P_edge1, h_edge1, ...]`
- [ ] Add inline code examples
- [x] Task 6: Add documentation (AC: 5)
- [x] Add rustdoc for struct and all public methods
- [x] Document layout: `[P_edge0, h_edge0, P_edge1, h_edge1, ...]`
- [x] Add inline code examples
## Dev Notes
@@ -149,16 +149,93 @@ impl SystemState {
### Agent Model Used
(To be filled during implementation)
Claude 3.5 Sonnet (via OpenCode)
### Debug Log References
(To be filled during implementation)
N/A
### Completion Notes List
(To be filled during implementation)
1. Created `SystemState` struct in `crates/core/src/state.rs` with:
- Typed accessor methods (`pressure()`, `enthalpy()`)
- Typed setter methods (`set_pressure()`, `set_enthalpy()`)
- `From<Vec<f64>>` and `From<SystemState> for Vec<f64>` conversions
- `AsRef<[f64]>` and `AsMut<[f64]>` implementations
- `Deref<Target=[f64]>` and `DerefMut` for seamless slice compatibility
- `Index<usize>` and `IndexMut<usize>` for backward compatibility
- `to_vec()` method for cloning data
- 25 unit tests covering all functionality
2. Updated Component trait to use `&StateSlice` (type alias for `&[f64]`) instead of `&SystemState`:
- This allows both `&Vec<f64>` and `&SystemState` to work via deref coercion
- Updated all component implementations
- Updated all solver code
3. Added `StateSlice` type alias for clarity in method signatures
### File List
(To be filled during implementation)
- `crates/core/src/state.rs` (created)
- `crates/core/src/lib.rs` (modified)
- `crates/components/src/lib.rs` (modified)
- `crates/components/src/compressor.rs` (modified)
- `crates/components/src/expansion_valve.rs` (modified)
- `crates/components/src/fan.rs` (modified)
- `crates/components/src/pump.rs` (modified)
- `crates/components/src/pipe.rs` (modified)
- `crates/components/src/node.rs` (modified)
- `crates/components/src/flow_junction.rs` (modified)
- `crates/components/src/refrigerant_boundary.rs` (modified)
- `crates/components/src/python_components.rs` (modified)
- `crates/components/src/heat_exchanger/exchanger.rs` (modified)
- `crates/components/src/heat_exchanger/evaporator.rs` (modified)
- `crates/components/src/heat_exchanger/evaporator_coil.rs` (modified)
- `crates/components/src/heat_exchanger/condenser.rs` (modified)
- `crates/components/src/heat_exchanger/condenser_coil.rs` (modified)
- `crates/components/src/heat_exchanger/economizer.rs` (modified)
- `crates/solver/src/system.rs` (modified)
- `crates/solver/src/macro_component.rs` (modified)
- `crates/solver/src/initializer.rs` (modified)
- `crates/solver/src/strategies/mod.rs` (modified)
- `crates/solver/src/strategies/sequential_substitution.rs` (modified)
- `crates/solver/tests/*.rs` (modified - all test files)
- `demo/src/bin/*.rs` (modified - all demo binaries)
## Senior Developer Review (AI)
**Reviewer:** Claude 3.5 Sonnet (via OpenCode)
**Date:** 2026-02-22
**Outcome:** Changes Requested → Fixed
### Issues Found
| # | Severity | Issue | Resolution |
|---|----------|-------|------------|
| 1 | HIGH | Clippy `manual_is_multiple_of` failure (crate has `#![deny(warnings)]`) | Fixed: `data.len() % 2 == 0``data.len().is_multiple_of(2)` |
| 2 | HIGH | Missing serde support for JSON persistence (Story 7-5 dependency) | Fixed: Added `Serialize, Deserialize` derives to `SystemState` and `InvalidStateLengthError` |
| 3 | MEDIUM | Silent failure on `set_pressure`/`set_enthalpy` hides bugs | Fixed: Added `#[track_caller]` and `debug_assert!` for early detection |
| 4 | MEDIUM | No fallible constructor (`try_from_vec`) | Fixed: Added `try_from_vec()` returning `Result<Self, InvalidStateLengthError>` |
| 5 | MEDIUM | Demo binaries have uncommitted changes | Noted: Unrelated to story scope |
### Fixes Applied
1. Added `InvalidStateLengthError` type with `std::error::Error` impl
2. Added `try_from_vec()` fallible constructor
3. Added `#[track_caller]` and `debug_assert!` to `set_pressure`/`set_enthalpy`
4. Added `Serialize, Deserialize` derives (serde already in dependencies)
5. Added 7 new tests:
- `test_try_from_vec_valid`
- `test_try_from_vec_odd_length`
- `test_try_from_vec_empty`
- `test_invalid_state_length_error_display`
- `test_serde_roundtrip`
- `test_set_pressure_out_of_bounds_panics_in_debug`
- `test_set_enthalpy_out_of_bounds_panics_in_debug`
### Test Results
- `entropyk-core`: 90 tests passed
- `entropyk-components`: 379 tests passed
- `entropyk-solver`: 211 tests passed
- Clippy: 0 warnings