fjallstation 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ __pycache__/
2
+ *.pyc
3
+ .venv/
4
+ .pytest_cache/
5
+ dist/
6
+ /store
7
+ /rewards
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,87 @@
1
+ Metadata-Version: 2.5
2
+ Name: fjallstation
3
+ Version: 0.1.0
4
+ Summary: A data and RL environment API for LLM agents in the built environment.
5
+ Project-URL: Repository, https://github.com/zengpz/fjallstation
6
+ Author: Zeng Peng
7
+ License-Expression: Apache-2.0
8
+ License-File: LICENSE
9
+ Keywords: agents,building-energy,hvac,llm,modelica,reinforcement-learning
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Science/Research
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Topic :: Scientific/Engineering
14
+ Requires-Python: >=3.10
15
+ Requires-Dist: datasets>=4.0
16
+ Requires-Dist: numpy
17
+ Requires-Dist: pyarrow
18
+ Provides-Extra: dev
19
+ Requires-Dist: pytest; extra == 'dev'
20
+ Description-Content-Type: text/markdown
21
+
22
+ # Fjällstation
23
+
24
+ *"Fjällstation is the mountain station at the foot of Kebnekaise, where you prepare before the climb."*
25
+
26
+ A data and RL environment API for LLM agents in the built environment.
27
+
28
+ ## What you get
29
+
30
+ | Part | What it does |
31
+ |---|---|
32
+ | `fjallstation.Corpus()` | domain text for pretraining, as a Hugging Face dataset |
33
+ | `fjallstation.Instruct()` | chats for fine-tuning, as a Hugging Face dataset |
34
+ | `fjallstation.Env()` | modelling tasks in Modelica: a container to work in, and a reward |
35
+ | Task image | OpenModelica with the libraries of the tasks |
36
+ | Server | gives the tasks and the rewards |
37
+
38
+ You bring the data: one folder in a [simple format](https://github.com/zengpz/fjallstation/blob/main/docs/data.md). The same parts run on one workstation or on several machines.
39
+
40
+ ## Quick start
41
+
42
+ You need Python 3.10 or later and Docker. Tested on Linux.
43
+
44
+ ```bash
45
+ pip install fjallstation
46
+ fjallstation image # build the task image; the first build takes some minutes
47
+ fjallstation example ./store # the example store: five texts, five chats, five tasks
48
+ fjallstation server --store ./store # the server; keep it running in this terminal
49
+ ```
50
+
51
+ Then, in a second terminal in the same folder, with Python:
52
+
53
+ ```python
54
+ import fjallstation # reads ./store, or the folder in FJALLSTATION_STORE
55
+
56
+ for doc in fjallstation.Corpus():
57
+ print(doc["text"])
58
+ for row in fjallstation.Instruct():
59
+ print(row["messages"])
60
+
61
+ env = fjallstation.Env()
62
+ task = env.reset("example-heated-room") # a task and a fresh container; env.reset() gives a random task
63
+ print(task.prompt)
64
+ print(env.exec("omc --version").output) # your agent works in the container
65
+
66
+ model = """
67
+ model HeatedRoom
68
+ Real T(start = 10, fixed = true);
69
+ output Real T_room;
70
+ equation
71
+ 2e6*der(T) = 1500 - 100*T;
72
+ T_room = T;
73
+ end HeatedRoom;
74
+ """
75
+ result = env.step(model) # the container tries the model; the server gives the reward
76
+ print(result.reward, result.feedback) # 1.0 correct
77
+ ```
78
+
79
+ ## Documents
80
+
81
+ - [The data folder](https://github.com/zengpz/fjallstation/blob/main/docs/data.md): the format, the examples, and how to make tasks of your own.
82
+ - [One episode, step by step](https://github.com/zengpz/fjallstation/blob/main/docs/protocol.md): the same episode with a shell, who runs as whom, and use on several machines.
83
+ - [The reward](https://github.com/zengpz/fjallstation/blob/main/docs/scoring.md): the two parts of the reward and the rule behind them.
84
+
85
+ ## Licence
86
+
87
+ Apache 2.0, see [LICENSE](https://github.com/zengpz/fjallstation/blob/main/LICENSE). The task image installs OpenModelica and Modelica libraries; they have their own licences. Two example tasks use open datasets under CC BY 4.0; their credit is in the task text and in the data document.
@@ -0,0 +1,66 @@
1
+ # Fjällstation
2
+
3
+ *"Fjällstation is the mountain station at the foot of Kebnekaise, where you prepare before the climb."*
4
+
5
+ A data and RL environment API for LLM agents in the built environment.
6
+
7
+ ## What you get
8
+
9
+ | Part | What it does |
10
+ |---|---|
11
+ | `fjallstation.Corpus()` | domain text for pretraining, as a Hugging Face dataset |
12
+ | `fjallstation.Instruct()` | chats for fine-tuning, as a Hugging Face dataset |
13
+ | `fjallstation.Env()` | modelling tasks in Modelica: a container to work in, and a reward |
14
+ | Task image | OpenModelica with the libraries of the tasks |
15
+ | Server | gives the tasks and the rewards |
16
+
17
+ You bring the data: one folder in a [simple format](https://github.com/zengpz/fjallstation/blob/main/docs/data.md). The same parts run on one workstation or on several machines.
18
+
19
+ ## Quick start
20
+
21
+ You need Python 3.10 or later and Docker. Tested on Linux.
22
+
23
+ ```bash
24
+ pip install fjallstation
25
+ fjallstation image # build the task image; the first build takes some minutes
26
+ fjallstation example ./store # the example store: five texts, five chats, five tasks
27
+ fjallstation server --store ./store # the server; keep it running in this terminal
28
+ ```
29
+
30
+ Then, in a second terminal in the same folder, with Python:
31
+
32
+ ```python
33
+ import fjallstation # reads ./store, or the folder in FJALLSTATION_STORE
34
+
35
+ for doc in fjallstation.Corpus():
36
+ print(doc["text"])
37
+ for row in fjallstation.Instruct():
38
+ print(row["messages"])
39
+
40
+ env = fjallstation.Env()
41
+ task = env.reset("example-heated-room") # a task and a fresh container; env.reset() gives a random task
42
+ print(task.prompt)
43
+ print(env.exec("omc --version").output) # your agent works in the container
44
+
45
+ model = """
46
+ model HeatedRoom
47
+ Real T(start = 10, fixed = true);
48
+ output Real T_room;
49
+ equation
50
+ 2e6*der(T) = 1500 - 100*T;
51
+ T_room = T;
52
+ end HeatedRoom;
53
+ """
54
+ result = env.step(model) # the container tries the model; the server gives the reward
55
+ print(result.reward, result.feedback) # 1.0 correct
56
+ ```
57
+
58
+ ## Documents
59
+
60
+ - [The data folder](https://github.com/zengpz/fjallstation/blob/main/docs/data.md): the format, the examples, and how to make tasks of your own.
61
+ - [One episode, step by step](https://github.com/zengpz/fjallstation/blob/main/docs/protocol.md): the same episode with a shell, who runs as whom, and use on several machines.
62
+ - [The reward](https://github.com/zengpz/fjallstation/blob/main/docs/scoring.md): the two parts of the reward and the rule behind them.
63
+
64
+ ## Licence
65
+
66
+ Apache 2.0, see [LICENSE](https://github.com/zengpz/fjallstation/blob/main/LICENSE). The task image installs OpenModelica and Modelica libraries; they have their own licences. Two example tasks use open datasets under CC BY 4.0; their credit is in the task text and in the data document.
@@ -0,0 +1,100 @@
1
+ # The data folder
2
+
3
+ All data is in one folder, the store. `FJALLSTATION_STORE` names it for `Corpus()` and `Instruct()`; `fjallstation server --store` names it for the server. The default of both is `./store`.
4
+
5
+ ```
6
+ store/
7
+ corpus/<set>/part-*.parquet text
8
+ instruct/<set>/part-*.parquet chats
9
+ env/tasks-<name>/part-*.parquet tasks of Env
10
+ ```
11
+
12
+ A set is a folder with one or more Parquet part files. You can have many sets and any of the three parts.
13
+
14
+ ## The example store
15
+
16
+ `fjallstation example ./store` copies a small store of this form into the folder: five texts, five chats and five tasks. The files are a part of the package.
17
+
18
+ | Part | Examples | Source |
19
+ |---|---|---|
20
+ | `corpus/example` | five short lessons: heat loss of district-heating pipes, the COP of a heat pump, equations in Modelica, a CO₂ balance of an office, and one lesson in Swedish about a radiator | written by a language model and reviewed |
21
+ | `instruct/example` | five chats with one question and one answer: a heat pump, units in Modelica, a district-heating substation, the response of a room, and one chat in Swedish | written by a language model and reviewed |
22
+ | `env/tasks-example` | five tasks, see below | |
23
+
24
+ | Task id | What the agent builds | Kind |
25
+ |---|---|---|
26
+ | `example-heated-room` | a room as one heat capacity with a heater | a small task with every number in the text |
27
+ | `example-heating-curve` | supply and return temperature setpoints with blocks of the Buildings library | a task from a library model; the library files with the answer are hidden |
28
+ | `example-pid-controller` | a comparison of PID controllers of two libraries | a task from a library model |
29
+ | `example-return-pipe` | the outlet temperature of a district-heating pipe | a task from measured data, with data files and a limit of its own |
30
+ | `example-heat-pump` | the electric energy of an air-to-water heat pump | a task from measured data |
31
+
32
+ The two tasks from measured data use open datasets under CC BY 4.0. The task text ends with the credit and says what was changed.
33
+
34
+ - `example-return-pipe`: IMOS-SWIL District Heating Dataset, version 1.0.0, by K. Faghih Niresi, C. Møller Jensen, C. S. Kallesøe, R. Wisniewski and O. Fink (2026), https://doi.org/10.5281/zenodo.23127439.
35
+ - `example-heat-pump`: High-Resolution Datasets of Thermal Dynamics, Heat Pump Operation, and Grid Interaction in Three Experimental Buildings, by J. Wachter and others, Karlsruhe Institute of Technology (2026), https://doi.org/10.5281/zenodo.21157950.
36
+
37
+ ## Text: `corpus`
38
+
39
+ | Column | Content |
40
+ |---|---|
41
+ | `id` | a name for the row |
42
+ | `text` | the text |
43
+ | `source` | where the text comes from, in one word |
44
+
45
+ ## Chats: `instruct`
46
+
47
+ | Column | Content |
48
+ |---|---|
49
+ | `id` | a name for the row |
50
+ | `messages` | a list of `{"role": ..., "content": ...}` items |
51
+
52
+ ## Tasks: `env`
53
+
54
+ The server reads the sets `env/tasks` and `env/tasks-<name>`, where the name has lower-case letters, digits and hyphens. Each row is one task.
55
+
56
+ | Column | Content |
57
+ |---|---|
58
+ | `id` | the task id |
59
+ | `prompt` | the task text that the agent gets |
60
+ | `model_name` | the name that the submitted Modelica model must have |
61
+ | `spec` | the settings of the task, as JSON (see below) |
62
+ | `reference_outputs` | the reference values, as JSON: `{"time": [...], "<output>": [...], ...}` |
63
+ | `source_id` | a name for the source of the task (optional) |
64
+ | `files` | data files for the container, as JSON `{"<file name>": "<text>"}`; the agent finds them in `/work/data/` (optional) |
65
+
66
+ Other columns are allowed. The server does not read them.
67
+
68
+ The settings in `spec`:
69
+
70
+ | Key | Content |
71
+ |---|---|
72
+ | `model_name` | as above |
73
+ | `msl` | the version of the Modelica Standard Library, for example `"4.1.0"` |
74
+ | `libraries` | other libraries to load, for example `["Buildings 13.0.0"]`, or `[]` |
75
+ | `eval` | `start_time`, `stop_time`, `interval`, `tolerance` and `outputs` (the names of the required outputs) |
76
+ | `hidden_files` | library files that are removed from the container before the agent works, or `[]` |
77
+ | `hidden_classes`, `forbidden` | classes that are removed at the submission, and texts that a model must not contain (optional) |
78
+ | `limit` | the largest error of a correct output: one number, or a number for each output (optional; default 0.01) |
79
+
80
+ The reference values are compared at the fixed time steps: from `start_time` to `stop_time`, one for each `interval`. A value of `NaN` means that this time step is not compared.
81
+
82
+ The server checks each task when it starts, and it names the task and the reason when one is not right. The rules:
83
+
84
+ - A task id occurs one time only. The model name, the library names and the output names have the form of Modelica names; the times and the tolerance are numbers.
85
+ - The time from `start_time` to `stop_time` is a whole number of intervals.
86
+ - The reference values cover this time in order, and each output has one value for each time.
87
+ - A limit is a number above zero, for the task or for each output.
88
+ - A reference output is not constant, because the error is measured against its range.
89
+
90
+ ## Tasks of your own
91
+
92
+ A task needs reference values. Take them from a reference model that you simulate in the task image, or from measured data. Then write the rows as a Parquet file into a folder `env/tasks-<name>`.
93
+
94
+ ```python
95
+ from fjallstation import image
96
+
97
+ result = image.try_model(reference_code, spec) # one fresh container: load, check, simulate
98
+ result["status"] # "simulated" when the model ran to the stop time
99
+ result["values"] # the output values at the fixed time steps
100
+ ```
@@ -0,0 +1,63 @@
1
+ # One episode, step by step
2
+
3
+ `fjallstation.Env()` is a small client. It does four steps that any program can do, in any language. The container needs no network.
4
+
5
+ | Step | Who | What |
6
+ |---|---|---|
7
+ | 1 | your program | `POST /v1/tasks/sample` to the server. The answer is the task file. |
8
+ | 2 | your program | Start a container of the task image and give it the task file: `fjallstation-task start`. |
9
+ | 3 | the agent | Works in the container, in `/work`, as a normal user. |
10
+ | 4 | your program | `fjallstation-task submit` in the container tries the model and prints the result file. Send it to the address in it. The answer holds the reward. |
11
+
12
+ ## With a shell
13
+
14
+ ```bash
15
+ curl -s -X POST http://127.0.0.1:8040/v1/tasks/sample -d '{}' > task.json
16
+ docker run -d --name episode --network none --pids-limit 512 --user 1000:1000 fjallstation-env:1
17
+ docker exec -i -u 0 episode fjallstation-task start < task.json
18
+
19
+ # ... the agent works: docker exec -w /work episode bash -c "<command>" ...
20
+
21
+ docker exec -i -u 0 episode fjallstation-task submit < model.mo > result.json
22
+ docker rm -f episode
23
+ curl -s -X POST "$(python3 -c 'import json; print(json.load(open("result.json"))["address"])')" -d @result.json
24
+ ```
25
+
26
+ ## Who runs as whom
27
+
28
+ | Who | User in the container | Rights |
29
+ |---|---|---|
30
+ | the agent | 1000 | its own files in `/work` and `/tmp`; no network |
31
+ | `fjallstation-task start` and `submit` | root | the library folder and the kept task file; Python runs in isolated mode, so it reads no start-up file of the agent |
32
+ | the submitted model (compilation and simulation) | 65534 | a folder of its own; a model that runs a shell command has no rights of root or of the agent |
33
+
34
+ Stop the processes of the agent before the submission. The container is the outer boundary: an episode mounts no folder of the host. `fjallstation.Env()` gives the container limits for CPU, memory and the number of processes. It gives no limit for the disk.
35
+
36
+ `env.exec(command)` stops a command at its time limit (exit code 124) and returns the first megabyte of its output. The command keeps its own exit code. A process that stays in the background must write to a file. These limits are a guard against accidents, not against an agent that works against them.
37
+
38
+ ## The server
39
+
40
+ | Call | Body | Answer |
41
+ |---|---|---|
42
+ | `POST /v1/tasks/sample` | `{}` for a random task, or `{"task": "<task id>"}` | the task file |
43
+ | `POST /v1/results` | the result file | `{"reward", "omc_reward", "status", "task", "image"}` |
44
+ | `GET /v1/health` | | `{"status": "ok", "tasks": <count>, "image"}` |
45
+
46
+ ## The two files
47
+
48
+ The task file: `ticket`, `address`, `task`, `prompt`, `model_name`, `image`, `hidden_files`, `run` (the settings to try a model) and, for a task with data files, `files`.
49
+
50
+ The result file: `ticket`, `address`, `task`, `image`, `status`, `omc_reward`, `values` (the required outputs at the fixed time steps) and `seconds`.
51
+
52
+ - The ticket names one task instance. The server takes one result for each ticket.
53
+ - The address is where the result goes. The server writes its own address into the task file, so nothing is configured.
54
+ - The server refuses a result from another image version, because other versions can give other values.
55
+ - The reference values and the error of each output stay on the server.
56
+
57
+ ## On several machines
58
+
59
+ - Start the server with `fjallstation server --host 0.0.0.0`, and give the clients its address: `fjallstation.Env(url="http://<server>:8040")` or the variable `FJALLSTATION_SERVER`.
60
+ - Each machine that runs containers needs the task image (`fjallstation image`).
61
+ - `fjallstation.Env()` sends the result to the server address that you gave it. The address in the task file is for a program with no configuration; behind a proxy or with HTTPS it is not right.
62
+ - The server has no accounts, no encryption and no limits for requests. Use it on a machine or a network that you trust. It keeps the open tickets in memory, so a restart ends the open episodes.
63
+ - Treat a task set from another person as a program: its settings go into the script that the container runs.
@@ -0,0 +1,50 @@
1
+ # The reward
2
+
3
+ The reward has two parts. `Env.step()` returns both.
4
+
5
+ ## The OpenModelica part
6
+
7
+ It comes from the container and says how far the model got.
8
+
9
+ | The model | Status | Value |
10
+ |---|---|---|
11
+ | is empty, does not load, or uses a forbidden text | `no model`, `did not load`, `uses the source example` | 0 |
12
+ | loads, and the check fails | `check failed` | 0.1 |
13
+ | checks, and the simulation does not reach the stop time | `simulation failed`, `simulation stopped early`, `time limit` | 0.2 |
14
+ | simulates to the stop time | `simulated` | 0.3 |
15
+
16
+ The time limit for one submission is 30 minutes. `time limit` has the value 0.2 also when the limit ends the load or the check.
17
+
18
+ ## The scorer part
19
+
20
+ It comes from the server. The server compares each required output with the reference values at the fixed time steps.
21
+
22
+ - The error of an output is its NRMSE: the root mean square error divided by the range of the reference values.
23
+ - The model is correct when every output is at or below its limit. The limit is 0.01, or the value that the task names in `spec["limit"]`.
24
+ - A time step with no reference value is not compared.
25
+ - A reference output must not be constant, because its range is the measure. The server refuses such a task when it starts.
26
+
27
+ | Status | Meaning | Scorer part |
28
+ |---|---|---|
29
+ | `correct` | every output is inside its limit | 1.0 |
30
+ | `outputs differ` | an output is outside its limit | 0 |
31
+ | `output missing` | the model has no variable with a required name | 0 |
32
+ | `result not valid` | the result file does not have the right form | 0 |
33
+
34
+ ## The reward
35
+
36
+ `result.reward` is 1.0 for a correct model. For every other model it is the OpenModelica part.
37
+
38
+ ```python
39
+ result = env.step(model_code)
40
+ result.reward # 1.0, or 0, 0.1, 0.2, 0.3
41
+ result.omc # the OpenModelica part
42
+ result.scorer # the scorer part
43
+ result.feedback # the status
44
+ ```
45
+
46
+ ## What the reward is for
47
+
48
+ The container of the user simulates the model, and the server does not simulate it again. So the reward is a training signal. It is not a trusted score: a person who has the data folder has the reference values too.
49
+
50
+ The rule is in one file, `src/fjallstation/score.py`.
@@ -0,0 +1,37 @@
1
+ [project]
2
+ name = "fjallstation"
3
+ version = "0.1.0"
4
+ description = "A data and RL environment API for LLM agents in the built environment."
5
+ readme = "README.md"
6
+ requires-python = ">=3.10"
7
+ license = "Apache-2.0"
8
+ license-files = ["LICENSE"]
9
+ authors = [{ name = "Zeng Peng" }]
10
+ keywords = ["llm", "agents", "reinforcement-learning", "modelica", "hvac", "building-energy"]
11
+ classifiers = [
12
+ "Development Status :: 3 - Alpha",
13
+ "Intended Audience :: Science/Research",
14
+ "Programming Language :: Python :: 3",
15
+ "Topic :: Scientific/Engineering",
16
+ ]
17
+ dependencies = ["datasets>=4.0", "numpy", "pyarrow"]
18
+
19
+ [project.optional-dependencies]
20
+ dev = ["pytest"]
21
+
22
+ [project.scripts]
23
+ fjallstation = "fjallstation.__main__:main"
24
+
25
+ [project.urls]
26
+ Repository = "https://github.com/zengpz/fjallstation"
27
+
28
+ [build-system]
29
+ requires = ["hatchling>=1.27"]
30
+ build-backend = "hatchling.build"
31
+
32
+ [tool.hatch.build.targets.wheel]
33
+ packages = ["src/fjallstation"]
34
+
35
+ [tool.pytest.ini_options]
36
+ pythonpath = ["src"]
37
+ testpaths = ["tests"]
@@ -0,0 +1,17 @@
1
+ """fjallstation: a data and RL environment API for LLM agents in the built environment.
2
+
3
+ import fjallstation
4
+
5
+ corpus = fjallstation.Corpus() # domain text
6
+ instruct = fjallstation.Instruct() # chats
7
+ env = fjallstation.Env() # modelling tasks with a reward
8
+
9
+ The data comes from a folder that you give (`FJALLSTATION_STORE`). `Env()` needs the task image and the server
10
+ of this package: `fjallstation image` and `fjallstation server --store <folder>`.
11
+ """
12
+
13
+ from fjallstation.data import Corpus, Instruct
14
+ from fjallstation.env import Env
15
+
16
+ __all__ = ["Corpus", "Instruct", "Env"]
17
+ __version__ = "0.1.0"