fameio 1.8__py3-none-any.whl → 1.8.2__py3-none-any.whl

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.
@@ -1,643 +1,660 @@
1
- Metadata-Version: 2.1
2
- Name: fameio
3
- Version: 1.8
4
- Summary: Python scripts for operation of FAME models
5
- Home-page: https://gitlab.com/fame-framework/fame-io/
6
- Author: Felix Nitsch, Christoph Schimeczek, Ulrich Frey, Marc Deissenroth-Uhrig, Benjamin Fuchs, A. Achraf El Ghazi
7
- Author-email: fame@dlr.de
8
- License: Apache License 2.0
9
- Keywords: FAME,agent-based modelling
10
- Platform: UNKNOWN
11
- Classifier: Programming Language :: Python :: 3
12
- Classifier: License :: OSI Approved :: Apache Software License
13
- Classifier: Operating System :: OS Independent
14
- Requires-Python: >=3.8
15
- Description-Content-Type: text/markdown
16
- License-File: LICENSE.txt
17
- Requires-Dist: pandas
18
- Requires-Dist: fameprotobuf (<1.3,>=1.2)
19
- Requires-Dist: pyyaml
20
- Provides-Extra: dev
21
- Requires-Dist: pytest ; extra == 'dev'
22
- Requires-Dist: mockito ; extra == 'dev'
23
- Requires-Dist: pre-commit ; extra == 'dev'
24
-
25
- <!-- SPDX-FileCopyrightText: 2023 German Aerospace Center <fame@dlr.de>
26
-
27
- SPDX-License-Identifier: Apache-2.0 -->
28
- [![PyPI version](https://badge.fury.io/py/fameio.svg)](https://badge.fury.io/py/fameio)
29
- [![JOSS](https://joss.theoj.org/papers/10.21105/joss.04958/status.svg)](https://doi.org/10.21105/joss.04958)
30
- [![Zenodo](https://zenodo.org/badge/DOI/10.5281/zenodo.4314337.svg)](https://doi.org/10.5281/zenodo.4314337)
31
- [![PyPI license](https://img.shields.io/pypi/l/fameio.svg)](https://badge.fury.io/py/fameio)
32
- [![pipeline status](https://gitlab.com/fame-framework/fame-io/badges/main/pipeline.svg)](https://gitlab.com/fame-framework/fame-io/commits/main)
33
- [![coverage report](https://gitlab.com/fame-framework/fame-io/badges/main/coverage.svg)](https://gitlab.com/fame-framework/fame-io/-/commits/main)
34
- [![REUSE status](https://api.reuse.software/badge/gitlab.com/fame-framework/fame-io)](https://api.reuse.software/info/gitlab.com/fame-framework/fame-io)
35
-
36
- # FAME-Io
37
- Python scripts for FAME models, generation of protobuf input files and conversion of protobuf output files.
38
- Please visit the [FAME-Wiki](https://gitlab.com/fame-framework/wiki/-/wikis/home) to get an explanation of FAME and its components.
39
- The package is also formerly known as [FAME-Py](https://doi.org/10.5281/zenodo.4314338).
40
-
41
- # Installation
42
-
43
- pip install fameio
44
-
45
-
46
- You may also use `pipx`. For detailed information please refer to the official `pipx` [documentation](https://github.com/pypa/pipx).
47
-
48
- pipx install fameio
49
-
50
-
51
- # Usage
52
- FAME-Io currently offers two main scripts "makeFameRunConfig" and "convertFameResults".
53
- Both are automatically installed with the package.
54
- The first one creates a protobuf file for FAME applications using YAML definition files and .csv files.
55
- The latter one reads output files from FAME applications in protobuf format and converts them to .csv files.
56
-
57
- ## Make a FAME run configuration
58
- Digests configuration files in YAML format, combines them with .csv data files and creates a single input file for FAME applications in protobuf format.
59
- Call structure:
60
-
61
- makeFameRunConfig -f <path/to/scenario.yaml>
62
-
63
- You may also specify any of the following arguments:
64
-
65
- | Command | Action |
66
- |----------------------|-----------------------------------------------------------------------------------------------------------------|
67
- | `-l` or `--log` | Sets the logging level. Default is `info`. Options are `debug`, `info`, `warning`, `warn`, `error`, `critical`. |
68
- | `-lf` or `--logfile` | Sets the logging file. Default is `None`. If `None` is provided, all logs get only printed to the console. |
69
- | `-o` or `--output` | Sets the path of the compiled protobuf output file. Default is `config.pb`. |
70
-
71
- This could look as follows:
72
-
73
- makeFameRunConfig -f <path/to/scenario.yaml> -l debug -lf <path/to/scenario.log> -o <path/to/config.pb>
74
-
75
-
76
- You may also call the configuration builder from any Python script with
77
-
78
- ```python
79
- from fameio.scripts.make_config import run as make_config
80
-
81
- make_config("path/to/scenario.yaml")
82
- ```
83
-
84
- Similar to the console call you may also specify custom run config arguments and add it in a dictionary to the function call.
85
-
86
- ```python
87
- from fameio.scripts.make_config import run as make_config
88
- from fameio.source.cli import Options
89
-
90
- run_config = {Options.LOG_LEVEL: "info",
91
- Options.OUTPUT: "output.pb",
92
- Options.LOG_FILE: "scenario.log",
93
- }
94
-
95
- make_config("path/to/scenario.yaml", run_config)
96
- ```
97
-
98
-
99
- ### Scenario YAML
100
- The "scenario.yaml" file contains all configuration options for a FAME-based simulation.
101
- It consists of the sections `Schema`, `GeneralProperties`, `Agents` and `Contracts`, all of them described below.
102
-
103
- #### Schema
104
- The Schema is used to validate the inputs of the "scenario.yaml".
105
- Since the Schema should be valid across multiple scenarios, it is recommended to defined it in a separate file and include the file here.
106
-
107
- Currently, the schema specifies:
108
- * which type of Agents can be created
109
- * what type of input attributes an Agent uses
110
- * what type of Products an Agent can send in Contracts.
111
-
112
- The Schema consists of the sections `Header` and `AgentTypes`.
113
-
114
- ##### Header
115
- Scientific applications often evolve, and so do their required input parameters.
116
- Therefore, the header specifies information what FAME-based application the schema is corresponding to.
117
- In this way a schema.yaml is tied to a specific version an application, ensuring a match between the inputs required by the application, and those provided by the files created with FAME-Io.
118
-
119
- ```yaml
120
- Header:
121
- Project: MyProjectName
122
- RepoUrl: https://mygithosting.com/myProject
123
- CommitHash: abc123
124
- ```
125
-
126
- * `Project` name of your project / FAME-based application
127
- * `RepoUrl` URL of your project
128
- * `CommitHash` hash of the commit / version of your project
129
-
130
- ##### AgentTypes
131
- Here, each type of agent that can be created in your FAME-based application is listed, its attributes and its available Products for Contracts.
132
- The structure of this section
133
-
134
- ```yaml
135
- AgentTypes:
136
- MyAgentType:
137
- Attributes:
138
- MyAttribute:
139
- ...
140
- MyOtherAttribute:
141
- ...
142
- Products: [ 'Product1', 'Product2', 'Product3' ]
143
- MyOtherAgentWithoutProductsOrAttributes:
144
- ```
145
-
146
- * `MyAgentType` Java's simple class name of the Agent type
147
- * `Attributes` indicates that beginning of the attribute definition section for this Agent type
148
- * `MyAttribute` Name of an attribute as specified in the corresponding Java source code of this Agent type (annotated with "@Input")
149
- * `MyOtherAttribute` Name of another attribute derived from Java source code
150
- * `Products` list of Products that this Agent can send in Contracts; derived from Java source code of this Agent type (annotated with "@Product")
151
- * `MyOtherAgentWithoutProductsOrAttributes` an Agent type that requires neither Attributes nor Products
152
-
153
- Both Attributes and Products are optional - there could be useful Agents that require neither of them.
154
- In the above example attribute definition was not shown (indicated by `...`).
155
- The next example provides details on how to define an attribute:
156
-
157
- ```yaml
158
- MySimpleAttribute:
159
- AttributeType: enum
160
- Mandatory: true
161
- List: false
162
- Values: [ 'AllowedValue1', 'AllowedValue2' ]
163
- Default: 'AllowedValue1'
164
- Help: 'My help text'
165
-
166
- MyComplexAttribute:
167
- AttributeType: block
168
- NestedAttributes:
169
- InnerAttributeA:
170
- AttributeType: integer
171
- InnerAttributeB:
172
- AttributeType: double
173
- ```
174
-
175
- * `MySimpleAttribute`, `MyDoubleList`, `MyComplexAttribute` Names of the attributes as specified in the Java enum annotated with "@Input"
176
- * `AttributeType` (required) data type of the attribute; see options in table below
177
- * `Mandatory` (optional - true by default) if true: the attribute is required for this agent and validation will fail if the attribute is missing in the scenario **and** no default is provided
178
- * `List` (optional - false by default)
179
- * `AttributeType: time_series` cannot be true
180
- * `AttributeType: block`
181
- * if true: any nested element in the scenario must be part of a list element and thus can appear multiple times
182
- * if false: any nested element in the scenario can only appear once
183
- * any other AttributeType: the attribute is interpreted as list, i.e. multiple values can be assigned to this attribute in the scenario
184
- * `NestedAttributes` (required only if `AttributeType: block`, otherwise disallowed) starts an inner Attribute definition block - defined Attributes are sub-elements of `MyComplexAttribute`
185
- * `Values` (optional - None by default): if present defines a list of allowed values for this attribute
186
- * `Default` (optional - None by default): if present defines a default value to be used in case the scenario does not specify it
187
- * `Help` (optional - None by default): if present defines a help text to you attribute
188
-
189
- | AttributeType | value |
190
- |-----------------|-------------------------------------------------------------------------------------------------------------------------|
191
- | `integer` | a 32-bit integer value |
192
- | `double` | a 64-bit floating-point value (integers also allowed) |
193
- | `long` | a 64-bit integer value |
194
- | `time_stamp` | either a FAME time stamp string or 64-bit integer value |
195
- | `string` | any string |
196
- | `enum` | any string, however, usually tied to a set of allowed `Values` |
197
- | `time_series` | either a path to a .csv-file or a single 64-bit floating-point value; does not support `List: true` |
198
- | `block` | this attribute has no value of its own but hosts a group of nested Attributes; implies `NestedAttributes` to be defined |
199
-
200
- #### GeneralProperties
201
- Specifies FAME-specific properties of the simulation. Structure:
202
-
203
- ```yaml
204
- GeneralProperties:
205
- RunId: 1
206
- Simulation:
207
- StartTime: 2011-12-31_23:58:00
208
- StopTime: 2012-12-30_23:58:00
209
- RandomSeed: 1
210
- Output:
211
- Interval: 100
212
- Process: 0
213
- ```
214
-
215
- Parameters:
216
- * `RunId` an ID that can be given to the simulation; use at your discretion
217
- * `StartTime` time stamp in the format YYYY-MM-DD_hh:mm:ss; first moment of the simulation.
218
- * `StopTime` time stamp in the format YYYY-MM-DD_hh:mm:ss; last moment of the simulation - i.e. simulation terminates after passing that time stamp
219
- * `RandomSeed` seed to initialise random number generation; each value leads to a unique series of random numbers.
220
- * `Interval` number of simulation ticks in between write-to-disk events; may be used for performance optimisations;
221
- * `Process` id of process that performs write-to-disk operations; leave at 0 to be compatible with single-processes;
222
-
223
- #### Agents
224
- Specifies all Agents to be created in the simulation in a list. Each Agent has its own entry.
225
- Structure:
226
- ```yaml
227
- Agents:
228
- - Type: MyAgentWithInputs
229
- Id: 1
230
- Attributes:
231
- MyEnum: SAME_SHARES
232
- MyInteger: 2
233
- MyDouble: 4.2
234
- MyTimeSeries: "./path/to/time_series.csv"
235
-
236
- - Type: MyAgentWithoutInputs
237
- Id: 2
238
- ```
239
-
240
- Agent Parameters:
241
- * `Type` Mandatory; Java's simple class name of the agent to be created
242
- * `Id` Mandatory; simulation-unique id of this agent; if two agents have the same ID, the configuration process will stop.
243
- * `Attributes` Optional; if the agent has any attributes, specify them here in the format "AttributeName: value"; please see attribute table above
244
-
245
- The specified `Attributes` for each agent must match the specified `Attributes` options in the linked Schema (see above).
246
- For better structure and readability of the `scenario.yaml`, `Attributes` may also be specified in a nested way as demonstrated below.
247
-
248
- ```yaml
249
- Agents:
250
- - Type: MyAgentWithInputs
251
- Id: 1
252
- Attributes:
253
- Parent:
254
- MyEnum: SAME_SHARES
255
- MyInteger: 2
256
- Parent2:
257
- MyDouble: 4.2
258
- Child:
259
- MyTimeSeries: "./path/to/time_series.csv"
260
- ```
261
-
262
- In case Attributes are defined with `List: true` option, lists are assigned to an Attribute or Group:
263
-
264
- ```yaml
265
- Attributes:
266
- MyDoubleList: [5.2, 4.5, 7, 9.9]
267
- MyListGroup:
268
- - IntValueA: 5
269
- IntValueB: 42
270
- - IntValueA: 7
271
- IntValueB: 100
272
- ```
273
-
274
- Here, `MyDoubleList` and `MyListGroup` need to specify `List: true` in the corresponding Schema.
275
- The shorter `[]`-notation was used to assign a list of floating-point values to `MyDoubleList`.
276
- Nested items `IntValueA` and `IntValueB` of `MyListGroup` are assigned within a list, allowing the specification of these nested items several times.
277
-
278
- #### Contracts
279
- Specifies all Contracts, i.e. repetitive bilateral transactions in between agents.
280
- Contracts are given as a list.
281
- We recommend moving Contracts to separate files and to use the `!include` command to integrate them in the scenario.
282
-
283
- ```yaml
284
- Contracts:
285
- - SenderId: 1
286
- ReceiverId: 2
287
- ProductName: ProductOfAgent_1
288
- FirstDeliveryTime: -25
289
- DeliveryIntervalInSteps: 3600
290
-
291
- - SenderId: 2
292
- ReceiverId: 1
293
- ProductName: ProductOfAgent_2
294
- FirstDeliveryTime: -22
295
- DeliveryIntervalInSteps: 3600
296
- Attributes:
297
- ProductAppendix: value
298
- TimeOffset: 42
299
- ```
300
-
301
- Contract Parameters:
302
- * `SenderId` unique ID of agent sending the product
303
- * `ReceiverId` unique ID of agent receiving the product
304
- * `ProductName` name of the product to be sent
305
- * `FirstDeliveryTime` first time of delivery in the format "seconds after the January 1st 2000, 00:00:00"
306
- * `DeliveryIntervalInSteps` delay time in between deliveries in seconds
307
- * `Attributes` can be set to include additional information as `int`, `float`, `enum` or `dict` data types
308
-
309
- ##### Definition of Multiple Similar Contracts
310
- Often, scenarios contain multiple agents of similar type that also have similar chains of contracts.
311
- Therefore, FAME-Io supports a compact definition of multiple similar contracts.
312
- `SenderId` and `ReceiverId` can both be lists and support One-to-N, N-to-One and N-to-N relations like in the following example:
313
-
314
- ```yaml
315
- Contracts:
316
- # effectively 3 similar contracts (0 -> 11), (0 -> 12), (0 -> 13)
317
- # with otherwise identical ProductName, FirstDeliveryTime & DeliveryIntervalInSteps
318
- - SenderId: 0
319
- ReceiverId: [11, 12, 13]
320
- ProductName: MyOtherProduct
321
- FirstDeliveryTime: 100
322
- DeliveryIntervalInSteps: 3600
323
-
324
- # effectively 3 similar contracts (1 -> 10), (2 -> 10), (3 -> 10)
325
- # with otherwise identical ProductName, FirstDeliveryTime & DeliveryIntervalInSteps
326
- - SenderId: [1, 2, 3]
327
- ReceiverId: 10
328
- ProductName: MyProduct
329
- FirstDeliveryTime: 100
330
- DeliveryIntervalInSteps: 3600
331
-
332
- # effectively 3 similar contracts (1 -> 11), (2 -> 12), (3 -> 13)
333
- # with otherwise identical ProductName, FirstDeliveryTime & DeliveryIntervalInSteps
334
- - SenderId: [1, 2, 3]
335
- ReceiverId: [11, 12, 13]
336
- ProductName: MyThirdProduct
337
- FirstDeliveryTime: 100
338
- DeliveryIntervalInSteps: 3600
339
- ```
340
-
341
- Combined with YAML anchors complex contract chains can be easily reduced to a minimum of required configuration.
342
- The following example is equivalent to the previous one and allows a quick extension of contracts to a new couple of agents e.g. (4;14):
343
-
344
- ```yaml
345
- Groups:
346
- - &agentList1: [1,2,3]
347
- - &agentList2: [11,12,13]
348
-
349
- Contracts:
350
- - SenderId: 0
351
- ReceiverId: *agentList2
352
- ProductName: MyOtherProduct
353
- FirstDeliveryTime: 100
354
- DeliveryIntervalInSteps: 3600
355
-
356
- - SenderId: *agentList1
357
- ReceiverId: 10
358
- ProductName: MyProduct
359
- FirstDeliveryTime: 100
360
- DeliveryIntervalInSteps: 3600
361
-
362
- - SenderId: *agentList1
363
- ReceiverId: *agentList2
364
- ProductName: MyThirdProduct
365
- FirstDeliveryTime: 100
366
- DeliveryIntervalInSteps: 3600
367
- ```
368
-
369
- ### CSV files
370
- TIME_SERIES inputs are not directly fed into the Scenario YAML file.
371
- Instead, TIME_SERIES reference a .csv file that can be stored some place else.
372
- These .csv files follow a specific structure:
373
- * They must contain exactly two columns.
374
- * The first column must be a time stamp in form `YYYY-MM-DD_hh:mm:ss`
375
- * The second column must be a numerical value (either integer or floating-point)
376
- * The separator of the two columns is a semicolon
377
-
378
- Exemplary content of a valid .csv file:
379
-
380
- 2012-01-01_00:00:00;400
381
- 2013-01-01_00:00:00;720.5
382
- 2014-01-01_00:00:00;650
383
- 2015-01-01_00:00:00;99.27772
384
- 2016-01-01_00:00:00;42
385
- 2017-01-01_00:00:00;0.1
386
-
387
- Please refer also to the detailed article about `TimeStamps` in the [FAME-Wiki](https://gitlab.com/fame-framework/wiki/-/wikis/TimeStamp).
388
-
389
- ### Split and join multiple YAML files
390
- The user may include other YAML files into a YAML file to divide the content across files as convenient.
391
- We explicitly recommend using this feature for the `Schema` and `Contracts` sections.
392
- Otherwise, the scenario.yaml may become crowded.
393
-
394
- #### Command: !Include
395
- To hint YAML to load the content of another file use `!include "path/relative/to/including/yaml/file.yml"`.
396
- You can concatenate !include commands and can use !include in the included file as well.
397
- The path to the included file is always relative to the file using the !include command.
398
- So with the following file structure
399
-
400
- ###### file-structure
401
- ```
402
- a.yaml
403
- folder/b.yaml
404
- folder/c.yaml
405
- folder/deeper_folder/d.yaml
406
- ```
407
- the following !include commands work
408
-
409
- ###### in a.yaml
410
- ```
411
- ToBe: !include "folder/b.yaml"
412
- OrNot: !include "folder/deeper_folder/d.yaml"
413
- ```
414
-
415
- ###### in b.yaml
416
- ```
417
- ThatIs: !include "c.yaml"
418
- TheQuestion: !include "deeper_folder/d.yaml"
419
- ```
420
-
421
- Provided that
422
- ###### in c.yaml
423
- ```
424
- Or: maybe
425
- ```
426
- ###### d.yaml
427
- ```
428
- not: "?"
429
- ```
430
- the resulting file would look like this:
431
-
432
- ###### THe Joined file a.yaml
433
- ```
434
- ToBe:
435
- ThatIs:
436
- Or: maybe
437
- TheQuestion:
438
- not: "?"
439
- OrNot:
440
- not: "?"
441
- ```
442
-
443
- You may also specify absolute file paths if preferred by starting with a "/".
444
-
445
- When specifying only a file path, the complete content of the file is assigned to the given key.
446
- You always need a key to assign the !include command to.
447
- However, you cannot combine the value returned from !include with other values in the same key.
448
- Thus, the following combinations do not work:
449
- ###### caveats.yml
450
- ```
451
- !include "file.yaml" # no key assigned
452
-
453
- Key:
454
- Some: OtherItem
455
- !include "file.yaml" # cannot join with other named items
456
-
457
- List:
458
- - an: entry
459
- !include "file.yaml" # cannot directly join with list items, even if !include returns a list
460
- ```
461
-
462
- #### Integrate specific nodes of YAML files
463
- Instead of including *all* content in the included file, you may also pick a specific node within that file.
464
- For this use `!include [<relative/path/to/file.yaml>, Path:To:Field:In:Yaml]`.
465
- Here, `:` is used in the node-specifying string to select a sequence of nodes to follow - with custom depth.
466
- Consider the following two files:
467
-
468
- ###### file_to_be_included.yaml
469
- ```yaml
470
- Set1:
471
- Subset1:
472
- Key: Value
473
- Set2:
474
- OtherKey: OtherValue
475
- ```
476
-
477
- ###### including_file.yaml
478
- ```yaml
479
- - Type: MyAgentWithInputs
480
- Id: 1
481
- Attributes: !include_node [file_to_be_included.yaml, Set1:Subset1]
482
- ```
483
-
484
- Compiling "including_file.yaml" results in
485
-
486
- ###### resulting_file.yaml
487
- ```yaml
488
- - Type: MyAgentWithInputs
489
- Id: 1
490
- Attributes:
491
- Key: Value
492
- ```
493
-
494
- #### Load multiple files
495
- Using wildcards in the given path (e.g. "path/to/many/*.yaml") will lead to loading multiple files and assigning their content to the same key.
496
- You can make use of this feature with or without specifying a node selector.
497
- However, the elements to be joined across multiple files must be lists.
498
- These lists are then concatenated into a single list and then assigned to the key in the file calling !include.
499
- This feature is especially useful for Contracts: You can split the Contracts list into several files and place them in a separate folder.
500
- Then use !include to re-integrate them into your configuration. An example:
501
- ###### my_contract1.yaml
502
- ```
503
- Contracts:
504
- - ContractA
505
- - ContractB
506
- ```
507
- ###### my_contract2.yaml
508
- ```
509
- Contracts:
510
- - ContractC
511
- - ContractD
512
- - ContractE
513
- ```
514
- ###### including_file.yaml
515
- ```
516
- Contracts: [!include "my_contract*.yaml", "Contracts"]
517
- ```
518
-
519
- results in
520
- ###### result.yaml
521
- ```
522
- Contracts:
523
- - ContractA
524
- - ContractB
525
- - ContractC
526
- - ContractD
527
- - ContractE
528
- ```
529
-
530
- #### Ignoring files
531
- Files that have their name start with "IGNORE_" are not included with the !include command.
532
- You will see a debug output to notify you that the file was ignored.
533
- Use this to temporarily take files out ouf your configuration without deleting or moving them.
534
-
535
- ## Read FAME results
536
- Takes an output file in protobuf format of FAME-based applications and converts it into files in .csv format.
537
- An individual file for each type of Agent is created in a folder named after the protobuf input file.
538
- Call structure:
539
-
540
- convertFameResults -f <./path/to/protobuf_file.pb>
541
-
542
- You may also specify any of the following arguments:
543
-
544
- | Command | Action |
545
- |--------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
546
- | `-l` or `--log` <option> | Sets the logging level. Default is `info`. Options are `debug`, `info`, `warning`, `warn`, `error`, `critical`. |
547
- | `-lf` or `--logfile` <file> | Sets the logging file. Default is `None`. If `None` is provided, all logs get only printed to the console. |
548
- | `-a` or `--agents` <list-of-agents> | If specified, only a subset of agents is extracted from the protobuf file. Default is to extract all agents. |
549
- | `-o` or `--output` | Sets the path to where the generated output files are written to. If not specified, the folder's name is derived from the input file's name. Folder will be created if it does not exist. |
550
- | `-se` or `--single-export` | Enables export of individual agents to individual files, when present. If not present (the default) one file per `AgentType` is created. |
551
- | `-m` or `--memory-saving` | When specified, reduces memory usage profile at the cost of runtime. Use only when necessary. |
552
- | `-cc` or `--complex-column` <option> | Defines how to deal with complex indexed output columns (if any). `IGNORE` ignores complex columns. `MERGE` squashes all data from complex columns in one big string entry. `SPLIT` creates a separate file for each complex indexed output column. |
553
- | `-t` or `--time` <option> | Option to define conversion of time steps to given format (default=`UTC`) by `-t/--time {UTC, INT, FAME}` |
554
-
555
- Additionally, you may merge TimeSteps of a certain range of steps in the output files to
556
- i) associate multiple time steps with a common logical time in your simulation
557
- ii) reduce number of lines in output files
558
-
559
- For this, add the option `merge-times` and specify the arguments as follows:
560
-
561
- | Command | Action |
562
- |---------------------------|------------------------------------------------------------------------------------------|
563
- | `-fp` or `--focal-point` | TimeStep on which `steps-before` earlier and `steps-after` later TimeSteps are merged on |
564
- | `-sb` or `--steps-before` | Range of TimeSteps before the `focal-point` they get merged to |
565
- | `-sa` or `--steps-after` | Range of TimeSteps after the `focal-point` they get merged to |
566
-
567
- This could look as follows:
568
-
569
- convertFameResults -f <./path/to/protobuf_file.pb> -l debug -lf <path/to/output.log> -a AgentType1 AgentType2 -o myCsvFolder -m -cc SPLIT merge-times -fp 0 -sb 1799 -sa 1800
570
-
571
- Make sure that in the range of time steps you specify for merging there is only one value per column in the merged time range.
572
- If multiple values per column are merged values will get concatenated and might yield unexpected results.
573
-
574
- You may also call the conversion script from any Python script with:
575
-
576
- ```python
577
- from fameio.scripts.convert_results import run as convert_results
578
-
579
- convert_results("./path/to/protobuf_file.pb")
580
- ```
581
-
582
- Similar to the console call you may also specify custom run config arguments and add it in a dictionary to the function call.
583
-
584
- ```python
585
- from fameio.scripts.convert_results import run as convert_results
586
- from fameio.source.cli import Options
587
-
588
- run_config = {Options.LOG_LEVEL: "info",
589
- Options.LOG_FILE: "scenario.log",
590
- Options.OUTPUT: "Output",
591
- Options.AGENT_LIST: ['AgentType1', 'AgentType2'],
592
- Options.MEMORY_SAVING: False,
593
- Options.SINGLE_AGENT_EXPORT: False,
594
- Options.RESOLVE_COMPLEX_FIELD: "SPLIT",
595
- Options.TIME: "INT",
596
- Options.TIME_MERGING: {},
597
- }
598
-
599
- convert_results("./path/to/protobuf_file.pb", run_config)
600
- ```
601
-
602
- ## Cite FAME-Io
603
- If you use FAME-Io for academic work, please cite as follows.
604
-
605
- Bibtex entry:
606
- ```
607
- @article{fameio2023joss,
608
- author = {Felix Nitsch and Christoph Schimeczek and Ulrich Frey and Benjamin Fuchs},
609
- title = {FAME-Io: Configuration tools for complex agent-based simulations},
610
- journal = {Journal of Open Source Software},
611
- year = {2023},
612
- doi = {doi: https://doi.org/10.21105/joss.04958}
613
- }
614
- ```
615
-
616
- ## Contribute
617
- Please read the Contributors License Agreement `cla.md`, sign it and send it to [`fame@dlr.de`](mailto:fame@dlr.de) before contributing.
618
-
619
- ## Testing changes locally
620
-
621
- Once some changes have been performed on the local git clone, use the following command to override your local installation with your modified copy in order to test the result:
622
-
623
- ```bash
624
- python3 setup.py bdist_wheel && pip3 install --force-reinstall --no-dependencies ./dist/*.whl
625
- ```
626
-
627
- ## Code style
628
-
629
- We use the code formatting library [`black`](https://pypi.org/project/black/).
630
- The maximum line length is defined as 120 characters.
631
- Therefore, before committing, run `black --line-length 120 .`
632
-
633
- ## Pre-Commit hooks
634
-
635
- FAME-Io uses several pre-commit hooks to ensure high code quality.
636
- To use them, install `dev` packages and then initialise pre-commit in FAME-Io's base folder:
637
-
638
- ```
639
- pip install fameio[dev]
640
- pre-commit install -t pre-commit -t pre-push
641
- ```
642
-
643
-
1
+ Metadata-Version: 2.1
2
+ Name: fameio
3
+ Version: 1.8.2
4
+ Summary: Python scripts for operation of FAME models
5
+ Home-page: https://gitlab.com/fame-framework/fame-io/
6
+ Author: Felix Nitsch, Christoph Schimeczek, Ulrich Frey, Marc Deissenroth-Uhrig, Benjamin Fuchs, A. Achraf El Ghazi
7
+ Author-email: fame@dlr.de
8
+ License: Apache License 2.0
9
+ Keywords: FAME,agent-based modelling
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: License :: OSI Approved :: Apache Software License
12
+ Classifier: Operating System :: OS Independent
13
+ Requires-Python: >=3.8
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE.txt
16
+ Requires-Dist: pandas
17
+ Requires-Dist: fameprotobuf <1.3,>=1.2
18
+ Requires-Dist: pyyaml
19
+ Provides-Extra: dev
20
+ Requires-Dist: pytest ; extra == 'dev'
21
+ Requires-Dist: mockito ; extra == 'dev'
22
+ Requires-Dist: pre-commit ; extra == 'dev'
23
+
24
+ <!-- SPDX-FileCopyrightText: 2023 German Aerospace Center <fame@dlr.de>
25
+
26
+ SPDX-License-Identifier: Apache-2.0 -->
27
+ [![PyPI version](https://badge.fury.io/py/fameio.svg)](https://badge.fury.io/py/fameio)
28
+ [![JOSS](https://joss.theoj.org/papers/10.21105/joss.04958/status.svg)](https://doi.org/10.21105/joss.04958)
29
+ [![Zenodo](https://zenodo.org/badge/DOI/10.5281/zenodo.4314337.svg)](https://doi.org/10.5281/zenodo.4314337)
30
+ [![PyPI license](https://img.shields.io/pypi/l/fameio.svg)](https://badge.fury.io/py/fameio)
31
+ [![pipeline status](https://gitlab.com/fame-framework/fame-io/badges/main/pipeline.svg)](https://gitlab.com/fame-framework/fame-io/commits/main)
32
+ [![coverage report](https://gitlab.com/fame-framework/fame-io/badges/main/coverage.svg)](https://gitlab.com/fame-framework/fame-io/-/commits/main)
33
+ [![REUSE status](https://api.reuse.software/badge/gitlab.com/fame-framework/fame-io)](https://api.reuse.software/info/gitlab.com/fame-framework/fame-io)
34
+
35
+ # FAME-Io
36
+ Python scripts for FAME models, generation of protobuf input files and conversion of protobuf output files.
37
+ Please visit the [FAME-Wiki](https://gitlab.com/fame-framework/wiki/-/wikis/home) to get an explanation of FAME and its components.
38
+ The package is also formerly known as [FAME-Py](https://doi.org/10.5281/zenodo.4314338).
39
+
40
+ # Installation
41
+
42
+ We recommend installing `fameio` using PyPI:
43
+
44
+ pip install fameio
45
+
46
+ You may also use `pipx`. For detailed information please refer to the official `pipx` [documentation](https://github.com/pypa/pipx).
47
+
48
+ pipx install fameio
49
+
50
+ `fameio` is currently developed and tested for Python 3.8 or higher.
51
+ See the `setup.py` for a complete listing of dependencies.
52
+
53
+ # Usage
54
+
55
+ FAME-Io currently offers two main scripts `makeFameRunConfig` and `convertFameResults`.
56
+ Both are automatically installed with the package.
57
+ The first one creates a protobuf file for FAME applications using YAML definition files and CSV files.
58
+ The latter one reads output files from FAME applications in protobuf format and converts them to CSV files.
59
+
60
+ You may use the [example data](https://gitlab.com/dlr-ve/esy/amiris/examples) provided for the [AMIRIS](https://gitlab.com/dlr-ve/esy/amiris/amiris) model which can be used to simulate electricity markets in [Germany](https://gitlab.com/dlr-ve/esy/amiris/examples/-/tree/main/Germany2019), [Austria](https://gitlab.com/dlr-ve/esy/amiris/examples/-/tree/main/Austria2019), and a simple [proof-of-concept model](https://gitlab.com/dlr-ve/esy/amiris/examples/-/tree/main/Simple).
61
+
62
+ ## Make a FAME run configuration
63
+ Digests configuration files in YAML format, combines them with CSV data files and creates a single input file for FAME applications in protobuf format.
64
+ Call structure:
65
+
66
+ makeFameRunConfig -f <path/to/scenario.yaml>
67
+
68
+ You may also specify any of the following arguments:
69
+
70
+ | Command | Action |
71
+ |----------------------|-----------------------------------------------------------------------------------------------------------------|
72
+ | `-l` or `--log` | Sets the logging level. Default is `info`. Options are `debug`, `info`, `warning`, `warn`, `error`, `critical`. |
73
+ | `-lf` or `--logfile` | Sets the logging file. Default is `None`. If `None` is provided, all logs get only printed to the console. |
74
+ | `-o` or `--output` | Sets the path of the compiled protobuf output file. Default is `config.pb`. |
75
+
76
+ This could look as follows:
77
+
78
+ makeFameRunConfig -f <path/to/scenario.yaml> -l debug -lf <path/to/scenario.log> -o <path/to/config.pb>
79
+
80
+
81
+ You may also call the configuration builder from any Python script with
82
+
83
+ ```python
84
+ from fameio.scripts.make_config import run as make_config
85
+
86
+ make_config("path/to/scenario.yaml")
87
+ ```
88
+
89
+ Similar to the console call you may also specify custom run config arguments and add it in a dictionary to the function call.
90
+
91
+ ```python
92
+ from fameio.scripts.make_config import run as make_config
93
+ from fameio.source.cli import Options
94
+
95
+ run_config = {Options.LOG_LEVEL: "info",
96
+ Options.OUTPUT: "output.pb",
97
+ Options.LOG_FILE: "scenario.log",
98
+ }
99
+
100
+ make_config("path/to/scenario.yaml", run_config)
101
+ ```
102
+
103
+ ### Scenario YAML
104
+ The "scenario.yaml" file contains all configuration options for a FAME-based simulation.
105
+ It consists of the sections `Schema`, `GeneralProperties`, `Agents` and `Contracts`, all of them described below.
106
+
107
+ #### Schema
108
+ The Schema is used to validate the inputs of the "scenario.yaml".
109
+ Since the Schema should be valid across multiple scenarios, it is recommended to defined it in a separate file and include the file here.
110
+
111
+ Currently, the schema specifies:
112
+ * which type of Agents can be created
113
+ * what type of input attributes an Agent uses
114
+ * what type of Products an Agent can send in Contracts.
115
+
116
+ The Schema consists of the sections `Header` and `AgentTypes`.
117
+
118
+ ##### Header
119
+ Scientific applications often evolve, and so do their required input parameters.
120
+ Therefore, the header specifies information what FAME-based application the schema is corresponding to.
121
+ In this way a schema.yaml is tied to a specific version an application, ensuring a match between the inputs required by the application, and those provided by the files created with FAME-Io.
122
+
123
+ ```yaml
124
+ Header:
125
+ Project: MyProjectName
126
+ RepoUrl: https://mygithosting.com/myProject
127
+ CommitHash: abc123
128
+ ```
129
+
130
+ * `Project` name of your project / FAME-based application
131
+ * `RepoUrl` URL of your project
132
+ * `CommitHash` hash of the commit / version of your project
133
+
134
+ ##### AgentTypes
135
+ Here, each type of agent that can be created in your FAME-based application is listed, its attributes and its available Products for Contracts.
136
+ The structure of this section
137
+
138
+ ```yaml
139
+ AgentTypes:
140
+ MyAgentType:
141
+ Attributes:
142
+ MyAttribute:
143
+ ...
144
+ MyOtherAttribute:
145
+ ...
146
+ Products: [ 'Product1', 'Product2', 'Product3' ]
147
+ MyOtherAgentWithoutProductsOrAttributes:
148
+ ```
149
+
150
+ * `MyAgentType` Java's simple class name of the Agent type
151
+ * `Attributes` indicates that beginning of the attribute definition section for this Agent type
152
+ * `MyAttribute` Name of an attribute as specified in the corresponding Java source code of this Agent type (annotated with "@Input")
153
+ * `MyOtherAttribute` Name of another attribute derived from Java source code
154
+ * `Products` list of Products that this Agent can send in Contracts; derived from Java source code of this Agent type (annotated with "@Product")
155
+ * `MyOtherAgentWithoutProductsOrAttributes` an Agent type that requires neither Attributes nor Products
156
+
157
+ Both Attributes and Products are optional - there could be useful Agents that require neither of them.
158
+ In the above example attribute definition was not shown (indicated by `...`).
159
+ The next example provides details on how to define an attribute:
160
+
161
+ ```yaml
162
+ MySimpleAttribute:
163
+ AttributeType: enum
164
+ Mandatory: true
165
+ List: false
166
+ Values: [ 'AllowedValue1', 'AllowedValue2' ]
167
+ Default: 'AllowedValue1'
168
+ Help: 'My help text'
169
+
170
+ MyComplexAttribute:
171
+ AttributeType: block
172
+ NestedAttributes:
173
+ InnerAttributeA:
174
+ AttributeType: integer
175
+ InnerAttributeB:
176
+ AttributeType: double
177
+ ```
178
+
179
+ * `MySimpleAttribute`, `MyDoubleList`, `MyComplexAttribute` Names of the attributes as specified in the Java enum annotated with "@Input"
180
+ * `AttributeType` (required) data type of the attribute; see options in table below
181
+ * `Mandatory` (optional - true by default) if true: the attribute is required for this agent and validation will fail if the attribute is missing in the scenario **and** no default is provided
182
+ * `List` (optional - false by default)
183
+ * `AttributeType: time_series` cannot be true
184
+ * `AttributeType: block`
185
+ * if true: any nested element in the scenario must be part of a list element and thus can appear multiple times
186
+ * if false: any nested element in the scenario can only appear once
187
+ * any other AttributeType: the attribute is interpreted as list, i.e. multiple values can be assigned to this attribute in the scenario
188
+ * `NestedAttributes` (required only if `AttributeType: block`, otherwise disallowed) starts an inner Attribute definition block - defined Attributes are sub-elements of `MyComplexAttribute`
189
+ * `Values` (optional - None by default): if present defines a list of allowed values for this attribute
190
+ * `Default` (optional - None by default): if present defines a default value to be used in case the scenario does not specify it
191
+ * `Help` (optional - None by default): if present defines a help text to you attribute
192
+
193
+ | AttributeType | value |
194
+ |-----------------|-------------------------------------------------------------------------------------------------------------------------|
195
+ | `integer` | a 32-bit integer value |
196
+ | `double` | a 64-bit floating-point value (integers also allowed) |
197
+ | `long` | a 64-bit integer value |
198
+ | `time_stamp` | either a FAME time stamp string or 64-bit integer value |
199
+ | `string` | any string |
200
+ | `enum` | any string, however, usually tied to a set of allowed `Values` |
201
+ | `time_series` | either a path to a .csv-file or a single 64-bit floating-point value; does not support `List: true` |
202
+ | `block` | this attribute has no value of its own but hosts a group of nested Attributes; implies `NestedAttributes` to be defined |
203
+
204
+ #### GeneralProperties
205
+ Specifies FAME-specific properties of the simulation. Structure:
206
+
207
+ ```yaml
208
+ GeneralProperties:
209
+ RunId: 1
210
+ Simulation:
211
+ StartTime: 2011-12-31_23:58:00
212
+ StopTime: 2012-12-30_23:58:00
213
+ RandomSeed: 1
214
+ Output:
215
+ Interval: 100
216
+ Process: 0
217
+ ```
218
+
219
+ Parameters:
220
+ * `RunId` an ID that can be given to the simulation; use at your discretion
221
+ * `StartTime` time stamp in the format YYYY-MM-DD_hh:mm:ss; first moment of the simulation.
222
+ * `StopTime` time stamp in the format YYYY-MM-DD_hh:mm:ss; last moment of the simulation - i.e. simulation terminates after passing that time stamp
223
+ * `RandomSeed` seed to initialise random number generation; each value leads to a unique series of random numbers.
224
+ * `Interval` number of simulation ticks in between write-to-disk events; may be used for performance optimisations;
225
+ * `Process` id of process that performs write-to-disk operations; leave at 0 to be compatible with single-processes;
226
+
227
+ #### Agents
228
+ Specifies all Agents to be created in the simulation in a list. Each Agent has its own entry.
229
+ Structure:
230
+ ```yaml
231
+ Agents:
232
+ - Type: MyAgentWithInputs
233
+ Id: 1
234
+ Attributes:
235
+ MyEnum: SAME_SHARES
236
+ MyInteger: 2
237
+ MyDouble: 4.2
238
+ MyTimeSeries: "./path/to/time_series.csv"
239
+
240
+ - Type: MyAgentWithoutInputs
241
+ Id: 2
242
+ ```
243
+
244
+ Agent Parameters:
245
+ * `Type` Mandatory; Java's simple class name of the agent to be created
246
+ * `Id` Mandatory; simulation-unique id of this agent; if two agents have the same ID, the configuration process will stop.
247
+ * `Attributes` Optional; if the agent has any attributes, specify them here in the format "AttributeName: value"; please see attribute table above
248
+
249
+ The specified `Attributes` for each agent must match the specified `Attributes` options in the linked Schema (see above).
250
+ For better structure and readability of the `scenario.yaml`, `Attributes` may also be specified in a nested way as demonstrated below.
251
+
252
+ ```yaml
253
+ Agents:
254
+ - Type: MyAgentWithInputs
255
+ Id: 1
256
+ Attributes:
257
+ Parent:
258
+ MyEnum: SAME_SHARES
259
+ MyInteger: 2
260
+ Parent2:
261
+ MyDouble: 4.2
262
+ Child:
263
+ MyTimeSeries: "./path/to/time_series.csv"
264
+ ```
265
+
266
+ In case Attributes are defined with `List: true` option, lists are assigned to an Attribute or Group:
267
+
268
+ ```yaml
269
+ Attributes:
270
+ MyDoubleList: [5.2, 4.5, 7, 9.9]
271
+ MyListGroup:
272
+ - IntValueA: 5
273
+ IntValueB: 42
274
+ - IntValueA: 7
275
+ IntValueB: 100
276
+ ```
277
+
278
+ Here, `MyDoubleList` and `MyListGroup` need to specify `List: true` in the corresponding Schema.
279
+ The shorter `[]`-notation was used to assign a list of floating-point values to `MyDoubleList`.
280
+ Nested items `IntValueA` and `IntValueB` of `MyListGroup` are assigned within a list, allowing the specification of these nested items several times.
281
+
282
+ #### Contracts
283
+ Specifies all Contracts, i.e. repetitive bilateral transactions in between agents.
284
+ Contracts are given as a list.
285
+ We recommend moving Contracts to separate files and to use the `!include` command to integrate them in the scenario.
286
+
287
+ ```yaml
288
+ Contracts:
289
+ - SenderId: 1
290
+ ReceiverId: 2
291
+ ProductName: ProductOfAgent_1
292
+ FirstDeliveryTime: -25
293
+ DeliveryIntervalInSteps: 3600
294
+
295
+ - SenderId: 2
296
+ ReceiverId: 1
297
+ ProductName: ProductOfAgent_2
298
+ FirstDeliveryTime: -22
299
+ DeliveryIntervalInSteps: 3600
300
+ Attributes:
301
+ ProductAppendix: value
302
+ TimeOffset: 42
303
+ ```
304
+
305
+ Contract Parameters:
306
+ * `SenderId` unique ID of agent sending the product
307
+ * `ReceiverId` unique ID of agent receiving the product
308
+ * `ProductName` name of the product to be sent
309
+ * `FirstDeliveryTime` first time of delivery in the format "seconds after the January 1st 2000, 00:00:00"
310
+ * `DeliveryIntervalInSteps` delay time in between deliveries in seconds
311
+ * `Attributes` can be set to include additional information as `int`, `float`, `enum` or `dict` data types
312
+
313
+ ##### Definition of Multiple Similar Contracts
314
+ Often, scenarios contain multiple agents of similar type that also have similar chains of contracts.
315
+ Therefore, FAME-Io supports a compact definition of multiple similar contracts.
316
+ `SenderId` and `ReceiverId` can both be lists and support One-to-N, N-to-One and N-to-N relations like in the following example:
317
+
318
+ ```yaml
319
+ Contracts:
320
+ # effectively 3 similar contracts (0 -> 11), (0 -> 12), (0 -> 13)
321
+ # with otherwise identical ProductName, FirstDeliveryTime & DeliveryIntervalInSteps
322
+ - SenderId: 0
323
+ ReceiverId: [11, 12, 13]
324
+ ProductName: MyOtherProduct
325
+ FirstDeliveryTime: 100
326
+ DeliveryIntervalInSteps: 3600
327
+
328
+ # effectively 3 similar contracts (1 -> 10), (2 -> 10), (3 -> 10)
329
+ # with otherwise identical ProductName, FirstDeliveryTime & DeliveryIntervalInSteps
330
+ - SenderId: [1, 2, 3]
331
+ ReceiverId: 10
332
+ ProductName: MyProduct
333
+ FirstDeliveryTime: 100
334
+ DeliveryIntervalInSteps: 3600
335
+
336
+ # effectively 3 similar contracts (1 -> 11), (2 -> 12), (3 -> 13)
337
+ # with otherwise identical ProductName, FirstDeliveryTime & DeliveryIntervalInSteps
338
+ - SenderId: [1, 2, 3]
339
+ ReceiverId: [11, 12, 13]
340
+ ProductName: MyThirdProduct
341
+ FirstDeliveryTime: 100
342
+ DeliveryIntervalInSteps: 3600
343
+ ```
344
+
345
+ Combined with YAML anchors complex contract chains can be easily reduced to a minimum of required configuration.
346
+ The following example is equivalent to the previous one and allows a quick extension of contracts to a new couple of agents e.g. (4;14):
347
+
348
+ ```yaml
349
+ Groups:
350
+ - &agentList1: [1,2,3]
351
+ - &agentList2: [11,12,13]
352
+
353
+ Contracts:
354
+ - SenderId: 0
355
+ ReceiverId: *agentList2
356
+ ProductName: MyOtherProduct
357
+ FirstDeliveryTime: 100
358
+ DeliveryIntervalInSteps: 3600
359
+
360
+ - SenderId: *agentList1
361
+ ReceiverId: 10
362
+ ProductName: MyProduct
363
+ FirstDeliveryTime: 100
364
+ DeliveryIntervalInSteps: 3600
365
+
366
+ - SenderId: *agentList1
367
+ ReceiverId: *agentList2
368
+ ProductName: MyThirdProduct
369
+ FirstDeliveryTime: 100
370
+ DeliveryIntervalInSteps: 3600
371
+ ```
372
+
373
+ ### CSV files
374
+ TIME_SERIES inputs are not directly fed into the Scenario YAML file.
375
+ Instead, TIME_SERIES reference a CSV file that can be stored some place else.
376
+ These CSV files follow a specific structure:
377
+ * They must contain exactly two columns.
378
+ * The first column must be a time stamp in form `YYYY-MM-DD_hh:mm:ss`
379
+ * The second column must be a numerical value (either integer or floating-point)
380
+ * The separator of the two columns is a semicolon
381
+
382
+ Exemplary content of a valid CSV file:
383
+
384
+ 2012-01-01_00:00:00;400
385
+ 2013-01-01_00:00:00;720.5
386
+ 2014-01-01_00:00:00;650
387
+ 2015-01-01_00:00:00;99.27772
388
+ 2016-01-01_00:00:00;42
389
+ 2017-01-01_00:00:00;0.1
390
+
391
+ Please refer also to the detailed article about `TimeStamps` in the [FAME-Wiki](https://gitlab.com/fame-framework/wiki/-/wikis/TimeStamp).
392
+
393
+ ### Split and join multiple YAML files
394
+ The user may include other YAML files into a YAML file to divide the content across files as convenient.
395
+ We explicitly recommend using this feature for the `Schema` and `Contracts` sections.
396
+ Otherwise, the scenario.yaml may become crowded.
397
+
398
+ #### Command: !Include
399
+ To hint YAML to load the content of another file use `!include "path/relative/to/including/yaml/file.yml"`.
400
+ You can concatenate !include commands and can use !include in the included file as well.
401
+ The path to the included file is always relative to the file using the !include command.
402
+ So with the following file structure
403
+
404
+ ###### file-structure
405
+ ```
406
+ a.yaml
407
+ folder/b.yaml
408
+ folder/c.yaml
409
+ folder/deeper_folder/d.yaml
410
+ ```
411
+ the following !include commands work
412
+
413
+ ###### in a.yaml
414
+ ```
415
+ ToBe: !include "folder/b.yaml"
416
+ OrNot: !include "folder/deeper_folder/d.yaml"
417
+ ```
418
+
419
+ ###### in b.yaml
420
+ ```
421
+ ThatIs: !include "c.yaml"
422
+ TheQuestion: !include "deeper_folder/d.yaml"
423
+ ```
424
+
425
+ Provided that
426
+ ###### in c.yaml
427
+ ```
428
+ Or: maybe
429
+ ```
430
+ ###### d.yaml
431
+ ```
432
+ not: "?"
433
+ ```
434
+ the resulting file would look like this:
435
+
436
+ ###### THe Joined file a.yaml
437
+ ```
438
+ ToBe:
439
+ ThatIs:
440
+ Or: maybe
441
+ TheQuestion:
442
+ not: "?"
443
+ OrNot:
444
+ not: "?"
445
+ ```
446
+
447
+ You may also specify absolute file paths if preferred by starting with a "/".
448
+
449
+ When specifying only a file path, the complete content of the file is assigned to the given key.
450
+ You always need a key to assign the !include command to.
451
+ However, you cannot combine the value returned from !include with other values in the same key.
452
+ Thus, the following combinations do not work:
453
+ ###### caveats.yml
454
+ ```
455
+ !include "file.yaml" # no key assigned
456
+
457
+ Key:
458
+ Some: OtherItem
459
+ !include "file.yaml" # cannot join with other named items
460
+
461
+ List:
462
+ - an: entry
463
+ !include "file.yaml" # cannot directly join with list items, even if !include returns a list
464
+ ```
465
+
466
+ #### Integrate specific nodes of YAML files
467
+ Instead of including *all* content in the included file, you may also pick a specific node within that file.
468
+ For this use `!include [<relative/path/to/file.yaml>, Path:To:Field:In:Yaml]`.
469
+ Here, `:` is used in the node-specifying string to select a sequence of nodes to follow - with custom depth.
470
+ Consider the following two files:
471
+
472
+ ###### file_to_be_included.yaml
473
+ ```yaml
474
+ Set1:
475
+ Subset1:
476
+ Key: Value
477
+ Set2:
478
+ OtherKey: OtherValue
479
+ ```
480
+
481
+ ###### including_file.yaml
482
+ ```yaml
483
+ - Type: MyAgentWithInputs
484
+ Id: 1
485
+ Attributes: !include_node [file_to_be_included.yaml, Set1:Subset1]
486
+ ```
487
+
488
+ Compiling "including_file.yaml" results in
489
+
490
+ ###### resulting_file.yaml
491
+ ```yaml
492
+ - Type: MyAgentWithInputs
493
+ Id: 1
494
+ Attributes:
495
+ Key: Value
496
+ ```
497
+
498
+ #### Load multiple files
499
+ Using wildcards in the given path (e.g. "path/to/many/*.yaml") will lead to loading multiple files and assigning their content to the same key.
500
+ You can make use of this feature with or without specifying a node selector.
501
+ However, the elements to be joined across multiple files must be lists.
502
+ These lists are then concatenated into a single list and then assigned to the key in the file calling !include.
503
+ This feature is especially useful for Contracts: You can split the Contracts list into several files and place them in a separate folder.
504
+ Then use !include to re-integrate them into your configuration. An example:
505
+ ###### my_contract1.yaml
506
+ ```
507
+ Contracts:
508
+ - ContractA
509
+ - ContractB
510
+ ```
511
+ ###### my_contract2.yaml
512
+ ```
513
+ Contracts:
514
+ - ContractC
515
+ - ContractD
516
+ - ContractE
517
+ ```
518
+ ###### including_file.yaml
519
+ ```
520
+ Contracts: [!include "my_contract*.yaml", "Contracts"]
521
+ ```
522
+
523
+ results in
524
+ ###### result.yaml
525
+ ```
526
+ Contracts:
527
+ - ContractA
528
+ - ContractB
529
+ - ContractC
530
+ - ContractD
531
+ - ContractE
532
+ ```
533
+
534
+ #### Ignoring files
535
+ Files that have their name start with "IGNORE_" are not included with the !include command.
536
+ You will see a debug output to notify you that the file was ignored.
537
+ Use this to temporarily take files out ouf your configuration without deleting or moving them.
538
+
539
+ ## Read FAME results
540
+ Takes an output file in protobuf format of FAME-based applications and converts it into files in CSV format.
541
+ An individual file for each type of Agent is created in a folder named after the protobuf input file.
542
+ Call structure:
543
+
544
+ convertFameResults -f <./path/to/protobuf_file.pb>
545
+
546
+ You may also specify any of the following arguments:
547
+
548
+ | Command | Action |
549
+ |--------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
550
+ | `-l` or `--log` <option> | Sets the logging level. Default is `info`. Options are `debug`, `info`, `warning`, `warn`, `error`, `critical`. |
551
+ | `-lf` or `--logfile` <file> | Sets the logging file. Default is `None`. If `None` is provided, all logs get only printed to the console. |
552
+ | `-a` or `--agents` <list-of-agents> | If specified, only a subset of agents is extracted from the protobuf file. Default is to extract all agents. |
553
+ | `-o` or `--output` | Sets the path to where the generated output files are written to. If not specified, the folder's name is derived from the input file's name. Folder will be created if it does not exist. |
554
+ | `-se` or `--single-export` | Enables export of individual agents to individual files, when present. If not present (the default) one file per `AgentType` is created. |
555
+ | `-m` or `--memory-saving` | When specified, reduces memory usage profile at the cost of runtime. Use only when necessary. |
556
+ | `-cc` or `--complex-column` <option> | Defines how to deal with complex indexed output columns (if any). `IGNORE` ignores complex columns. `MERGE` squashes all data from complex columns in one big string entry. `SPLIT` creates a separate file for each complex indexed output column. |
557
+ | `-t` or `--time` <option> | Option to define conversion of time steps to given format (default=`UTC`) by `-t/--time {UTC, INT, FAME}` |
558
+
559
+ Additionally, you may merge TimeSteps of a certain range of steps in the output files to
560
+ i) associate multiple time steps with a common logical time in your simulation
561
+ ii) reduce number of lines in output files
562
+
563
+ For this, add the option `merge-times` and specify the arguments as follows:
564
+
565
+ | Command | Action |
566
+ |---------------------------|------------------------------------------------------------------------------------------|
567
+ | `-fp` or `--focal-point` | TimeStep on which `steps-before` earlier and `steps-after` later TimeSteps are merged on |
568
+ | `-sb` or `--steps-before` | Range of TimeSteps before the `focal-point` they get merged to |
569
+ | `-sa` or `--steps-after` | Range of TimeSteps after the `focal-point` they get merged to |
570
+
571
+ This could look as follows:
572
+
573
+ convertFameResults -f <./path/to/protobuf_file.pb> -l debug -lf <path/to/output.log> -a AgentType1 AgentType2 -o myCsvFolder -m -cc SPLIT merge-times -fp 0 -sb 1799 -sa 1800
574
+
575
+ Make sure that in the range of time steps you specify for merging there is only one value per column in the merged time range.
576
+ If multiple values per column are merged values will get concatenated and might yield unexpected results.
577
+
578
+ You may also call the conversion script from any Python script with:
579
+
580
+ ```python
581
+ from fameio.scripts.convert_results import run as convert_results
582
+
583
+ convert_results("./path/to/protobuf_file.pb")
584
+ ```
585
+
586
+ Similar to the console call you may also specify custom run config arguments and add it in a dictionary to the function call.
587
+
588
+ ```python
589
+ from fameio.scripts.convert_results import run as convert_results
590
+ from fameio.source.cli import Options
591
+
592
+ run_config = {Options.LOG_LEVEL: "info",
593
+ Options.LOG_FILE: "scenario.log",
594
+ Options.OUTPUT: "Output",
595
+ Options.AGENT_LIST: ['AgentType1', 'AgentType2'],
596
+ Options.MEMORY_SAVING: False,
597
+ Options.SINGLE_AGENT_EXPORT: False,
598
+ Options.RESOLVE_COMPLEX_FIELD: "SPLIT",
599
+ Options.TIME: "INT",
600
+ Options.TIME_MERGING: {},
601
+ }
602
+
603
+ convert_results("./path/to/protobuf_file.pb", run_config)
604
+ ```
605
+
606
+ ## Cite FAME-Io
607
+ If you use FAME-Io for academic work, please cite as follows.
608
+
609
+ Bibtex entry:
610
+ ```
611
+ @article{fameio2023joss,
612
+ author = {Felix Nitsch and Christoph Schimeczek and Ulrich Frey and Benjamin Fuchs},
613
+ title = {FAME-Io: Configuration tools for complex agent-based simulations},
614
+ journal = {Journal of Open Source Software},
615
+ year = {2023},
616
+ doi = {doi: https://doi.org/10.21105/joss.04958}
617
+ }
618
+ ```
619
+
620
+ ## Available Support
621
+ This is a purely scientific project by (at the moment) one research group.
622
+ Thus, there is no paid technical support available.
623
+ However, we will give our best to answer your questions and provide support.
624
+
625
+ If you experience any trouble with FAME-Io, you may contact the developers via [fame@dlr.de](mailto:fame@dlr.de).
626
+ Please report bugs and make feature requests by filing issues following the provided templates (see also [Contribute](#Contribute)).
627
+ For substantial enhancements, we recommend that you contact us via [fame@dlr.de](mailto:fame@dlr.de) for working together on the code in common projects or towards common publications and thus further develop FAME-Io.
628
+
629
+ # Contribute
630
+ Please read the Contributors License Agreement `cla.md`, sign it and send it to [`fame@dlr.de`](mailto:fame@dlr.de) before contributing.
631
+
632
+ You will also find templates for [bug reports](https://gitlab.com/fame-framework/fame-io/-/blob/main/.gitlab/issue_templates/bug_report.md),
633
+ [feature requests](https://gitlab.com/fame-framework/fame-io/-/blob/main/.gitlab/issue_templates/feature_request.md), and
634
+ [pull requests](https://gitlab.com/fame-framework/fame-io/-/blob/main/.gitlab/issue_templates/pull_request.md).
635
+
636
+ We kindly ask you to read the Contributors License Agreement `cla.md`, sign it, and send it to [`fame@dlr.de`](mailto:fame@dlr.de) before contributing. Please see our [conventions of contribution](https://gitlab.com/fame-framework/wiki/-/wikis/developers/contribute/Conventions) which are described in the Wiki.
637
+
638
+ ## Testing changes locally
639
+
640
+ Once some changes have been performed on the local git clone, use the following command to override your local installation with your modified copy in order to test the result:
641
+
642
+ ```bash
643
+ python3 setup.py bdist_wheel && pip3 install --force-reinstall --no-dependencies ./dist/*.whl
644
+ ```
645
+
646
+ ## Code style
647
+
648
+ We use the code formatting library [`black`](https://pypi.org/project/black/).
649
+ The maximum line length is defined as 120 characters.
650
+ Therefore, before committing, run `black --line-length 120 .`
651
+
652
+ ## Pre-Commit hooks
653
+
654
+ FAME-Io uses several pre-commit hooks to ensure high code quality.
655
+ To use them, install `dev` packages and then initialise pre-commit in FAME-Io's base folder:
656
+
657
+ ```
658
+ pip install fameio[dev]
659
+ pre-commit install -t pre-commit -t pre-push
660
+ ```