Skip to content

Commit 1aad1c1

Browse files
committed
Merge pull request 'refactor/named-states' (!15) from refactor/named-states into dev
Reviewed-on: https://git.sciprog.center/kscience/controls-kt/pulls/15
2 parents 7627a50 + 1d2b95c commit 1aad1c1

File tree

102 files changed

+2032
-1290
lines changed

Some content is hidden

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

102 files changed

+2032
-1290
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
- New interface `WithLifeCycle`. Change Port API to adhere to it.
1515

1616
### Changed
17+
- Add optional names to model states and submodels
18+
- `StateContainer` renamed to `Constructor`
19+
- Separate StateContainer and MutableStateContainer
20+
- `DeviceState` renamed to `ValueState`
1721
- Update logic of `DeviceState` to properly address subscriptions.
1822
- `getProperty` renamed to `getCachedProperty` for `CachingDevice`
1923
- Milo migrated to stable version
@@ -23,7 +27,7 @@
2327
- `DeviceHub` now works with `Name` instead of `NameToken`. Tree-like structure is made using `Path`. Device messages no longer have access to sub-devices.
2428
- Add some utility methods to ports. Synchronous port response could be now consumed as `Source`.
2529
- `DeviceLifecycleState` is replaced by `LifecycleState`.
26-
- Time is now mandatory first field of all device messages
30+
- Time is now the mandatory first field of all device messages
2731

2832

2933
### Deprecated

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Example view of a demo:
4747
### [controls-constructor](controls-constructor)
4848
> A low-code constructor for composite devices simulation
4949
>
50-
> **Maturity**: PROTOTYPE
50+
> **Maturity**: EXPERIMENTAL
5151
5252
### [controls-core](controls-core)
5353
> Core interfaces for building a device server

build.gradle.kts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@ plugins {
88

99
allprojects {
1010
group = "space.kscience"
11-
version = "0.4.0-dev-8"
11+
version = "0.4.0-dev-9"
1212
repositories{
1313
google()
1414
}
15+
tasks.withType<AbstractTestTask>().configureEach {
16+
failOnNoDiscoveredTests = false
17+
}
1518
}
1619

1720
ksciencePublish {

controls-constructor/README.md

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,56 @@
1-
# Module controls-constructor
1+
# Controls-kt-constructor
2+
3+
A simplified constructor for composing and simulating devices using a state-centric, type-safe DSL. This module lets you
4+
build virtual devices and high-level models by wiring reactive states together, exposing some of them as device
5+
properties, and running deterministic or realtime simulations.
6+
7+
The code is Kotlin Multiplatform (JVM, JS, Native, Wasm JS) and is built on Controls.kt core primitives,
8+
kotlinx.coroutines, and DataForge (Context/Meta).
9+
10+
## What’s inside
11+
12+
- Core concepts
13+
- ConstructorElement: a sealed marker for elements used in a construction graph.
14+
- PropertyConstructorElement: links a device property to a DeviceState.
15+
- StateConstructorElement: registers an independent state (e.g., timer, virtual value).
16+
- ConnectionConstructorElement: documents data flow between states (reads/writes edges).
17+
- ModelConstructorElement: nests a ModelConstructor inside another container.
18+
- StateContainer: a Context-aware, CoroutineScope host that manages states and connections.
19+
- Model and ModelConstructor: build reusable simulation models with their own coroutine context and dependencies.
20+
- DeviceConstructor: a DeviceGroup that also acts as a StateContainer; exposes states as device properties.
21+
22+
- State DSL (reactive building blocks)
23+
- stateOf, registerState: create/register states; DeviceState and MutableDeviceState abstractions.
24+
- timer and onTimer: periodic timer states; helpers to trigger logic on ticks.
25+
- runSimulation: run models on the context simulation dispatcher.
26+
- mapState, flowState: transform a state via pure or flow-based transformations.
27+
- combineState: combine 2, 3, 4, or many states into a derived state; map and associative variants supported.
28+
- bindState, bindTransformedState, bindCombinedState: push-style propagation from one/many source states into a
29+
mutable target state, with automatic registration of ConnectionConstructorElement.
30+
31+
- Device integration
32+
- property/mutableProperty/virtualProperty: expose external or virtual states as device properties with Meta
33+
converters and descriptors.
34+
- registerAsProperty: register a typed DeviceSpec property backed by a state.
35+
- device(factory/device): install sub-devices in a constructor via delegates.
36+
37+
- Simulation time and utilities
38+
- DefaultTimer presets (VERY_FAST..VERY_SLOW) and arbitrary Duration-based timers.
39+
- clock extension for StateContainer; deterministic virtual-time via Controls.kt time plugin.
40+
41+
- Continuous models
42+
- Delays: DeviceState.delayedBy; delayed producer/consumer wrappers to model transport/latency.
43+
- Limits: limited producer/consumer wrappers cap requests or supplies by AmountPerSecond.
44+
- Integration: collectAmountAsync integrates flow-like PerSecond values over duration.
45+
- Units support lives in the constructor.units package and related types (Amount, PerSecond, UnitsOfMatter, etc.).
46+
47+
## Features:
248

3-
A low-code constructor for composite devices simulation
449

5-
## Usage
650

751
## Artifact:
852

9-
The Maven coordinates of this project are `space.kscience:controls-constructor:0.4.0-dev-7`.
53+
The Maven coordinates of this project are `space.kscience:controls-constructor:0.4.0-dev-8`.
1054

1155
**Gradle Kotlin DSL:**
1256
```kotlin
@@ -16,6 +60,13 @@ repositories {
1660
}
1761

1862
dependencies {
19-
implementation("space.kscience:controls-constructor:0.4.0-dev-7")
63+
implementation("space.kscience:controls-constructor:0.4.0-dev-8")
2064
}
2165
```
66+
67+
## Notes
68+
69+
- Maturity: EXPERIMENTAL (APIs may evolve).
70+
- Depends on controls-core and DataForge Context/Meta; see the root README for architecture overview.
71+
- For examples and demos, check the demo modules in the root project; this module is ideal for high-level composition
72+
and simulation on top of controls-core devices.

controls-constructor/build.gradle.kts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ description = """
77
A low-code constructor for composite devices simulation
88
""".trimIndent()
99

10-
kscience{
10+
kscience {
1111
jvm()
1212
js()
1313
native()
@@ -20,11 +20,17 @@ kscience{
2020
api(projects.simulationKt)
2121
}
2222

23-
commonTest{
23+
commonTest {
2424
implementation(spclibs.logback.classic)
2525
}
2626
}
2727

28-
readme{
29-
maturity = space.kscience.gradle.Maturity.PROTOTYPE
28+
readme {
29+
maturity = space.kscience.gradle.Maturity.EXPERIMENTAL
3030
}
31+
32+
kotlin {
33+
compilerOptions {
34+
freeCompilerArgs.add("-Xcontext-parameters")
35+
}
36+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Controls-kt-constructor
2+
3+
A simplified constructor for composing and simulating devices using a state-centric, type-safe DSL. This module lets you
4+
build virtual devices and high-level models by wiring reactive states together, exposing some of them as device
5+
properties, and running deterministic or realtime simulations.
6+
7+
The code is Kotlin Multiplatform (JVM, JS, Native, Wasm JS) and is built on Controls.kt core primitives,
8+
kotlinx.coroutines, and DataForge (Context/Meta).
9+
10+
## What’s inside
11+
12+
- Core concepts
13+
- ConstructorElement: a sealed marker for elements used in a construction graph.
14+
- PropertyConstructorElement: links a device property to a DeviceState.
15+
- StateConstructorElement: registers an independent state (e.g., timer, virtual value).
16+
- ConnectionConstructorElement: documents data flow between states (reads/writes edges).
17+
- ModelConstructorElement: nests a ModelConstructor inside another container.
18+
- StateContainer: a Context-aware, CoroutineScope host that manages states and connections.
19+
- Model and ModelConstructor: build reusable simulation models with their own coroutine context and dependencies.
20+
- DeviceConstructor: a DeviceGroup that also acts as a StateContainer; exposes states as device properties.
21+
22+
- State DSL (reactive building blocks)
23+
- stateOf, registerState: create/register states; DeviceState and MutableDeviceState abstractions.
24+
- timer and onTimer: periodic timer states; helpers to trigger logic on ticks.
25+
- runSimulation: run models on the context simulation dispatcher.
26+
- mapState, flowState: transform a state via pure or flow-based transformations.
27+
- combineState: combine 2, 3, 4, or many states into a derived state; map and associative variants supported.
28+
- bindState, bindTransformedState, bindCombinedState: push-style propagation from one/many source states into a
29+
mutable target state, with automatic registration of ConnectionConstructorElement.
30+
31+
- Device integration
32+
- property/mutableProperty/virtualProperty: expose external or virtual states as device properties with Meta
33+
converters and descriptors.
34+
- registerAsProperty: register a typed DeviceSpec property backed by a state.
35+
- device(factory/device): install sub-devices in a constructor via delegates.
36+
37+
- Simulation time and utilities
38+
- DefaultTimer presets (VERY_FAST..VERY_SLOW) and arbitrary Duration-based timers.
39+
- clock extension for StateContainer; deterministic virtual-time via Controls.kt time plugin.
40+
41+
- Continuous models
42+
- Delays: DeviceState.delayedBy; delayed producer/consumer wrappers to model transport/latency.
43+
- Limits: limited producer/consumer wrappers cap requests or supplies by AmountPerSecond.
44+
- Integration: collectAmountAsync integrates flow-like PerSecond values over duration.
45+
- Units support lives in the constructor.units package and related types (Amount, PerSecond, UnitsOfMatter, etc.).
46+
47+
## Features:
48+
49+
${features}
50+
51+
${artifact}
52+
53+
## Notes
54+
55+
- Maturity: EXPERIMENTAL (APIs may evolve).
56+
- Depends on controls-core and DataForge Context/Meta; see the root README for architecture overview.
57+
- For examples and demos, check the demo modules in the root project; this module is ideal for high-level composition
58+
and simulation on top of controls-core devices.

0 commit comments

Comments
 (0)