Assembly
High-level interface for loading, manipulating, and building FMU Container assemblies.
Assembly reads a description file (CSV, JSON, or SSP), constructs the corresponding AssemblyNode tree, and provides methods to build the container FMU or export the assembly to a different format.
This is the main entry point for both the fmucontainer CLI and the Python API.
Examples:
from pathlib import Path
from fmu_manipulation_toolbox.assembly import Assembly
assembly = Assembly("bouncing.csv",
fmu_directory=Path("containers/bouncing_ball"),
mt=True)
assembly.make_fmu()
Attributes:
| Name | Type | Description |
|---|---|---|
filename | Path | Path to the description file. |
fmu_directory | Path | Directory containing the source FMUs. |
debug | bool | Whether debug mode is enabled. |
root | AssemblyNode | None | Root node of the assembly tree. |
Source code in fmu_manipulation_toolbox/assembly.py
603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 | |
json_encode() ¶
make_fmu(dump_json=False, fmi_version=2, datalog=False, filename=None) ¶
Build the FMU Container from the loaded assembly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dump_json | bool | If | False |
fmi_version | int | FMI version for the container interface ( | 2 |
datalog | bool | If | False |
filename | str | None | Override the output filename. | None |
Source code in fmu_manipulation_toolbox/assembly.py
make_simulink(filename) ¶
Write the MATLAB script that builds the Simulink model of the assembly, with FMU blocks.
The script designates the FMUs in place, relative to its own folder: the script and the FMUs must keep their relative places. Run the script toto.m (function toto()) in MATLAB R2024a or newer: it builds the model and saves it as toto_model.slx next to the script. See SimulinkExporter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename | str | Path | The | required |
Returns:
| Name | Type | Description |
|---|---|---|
Path | Path | The script. |
Raises:
| Type | Description |
|---|---|
AssemblyError | If the assembly cannot be exported to Simulink. |
Source code in fmu_manipulation_toolbox/assembly.py
read() ¶
Read and parse the description file.
The format is determined by the file extension: .json, .ssp, or .csv.
Raises:
| Type | Description |
|---|---|
AssemblyError | If the file format is not supported. |
Source code in fmu_manipulation_toolbox/assembly.py
read_csv() ¶
Parse a CSV description file and populate the assembly tree.
Source code in fmu_manipulation_toolbox/assembly.py
read_json() ¶
Parse a JSON description file and populate the assembly tree.
Raises:
| Type | Description |
|---|---|
AssemblyError | If the JSON is malformed or contains invalid keywords. |
Source code in fmu_manipulation_toolbox/assembly.py
read_ssp() ¶
Parse an SSP (System Structure and Parameterization) archive, SSP 1.0 or 2.0.
Extracts the embedded FMUs, validates SystemStructure.ssd against the SSP schema (warnings only), then builds the assembly tree from it: systems, FMU components, connections, parameter values, start and stop times. What the container cannot honour is refused, or reported when it changes nothing (see SSDParser).
An assembly is written back as SSP by write_ssp.
Source code in fmu_manipulation_toolbox/assembly.py
write(filename) ¶
Export the assembly to a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename | str | Output filename. The format is determined by the extension ( | required |
Raises:
| Type | Description |
|---|---|
AssemblyError | If the format is not supported. |
Source code in fmu_manipulation_toolbox/assembly.py
write_csv(filename) ¶
Export the assembly as a CSV file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename | str | Path | Output filename, relative to | required |
Raises:
| Type | Description |
|---|---|
AssemblyError | If the assembly contains nested containers (not representable in CSV). |
Source code in fmu_manipulation_toolbox/assembly.py
write_json(filename, basenames_only=False) ¶
Export the assembly as a JSON file.
FMU paths referenced in the fmu, link, input, output, start and drop blocks are made relative to the directory of the produced JSON file, so that the assembly stays portable (e.g. if the FMUs are stored alongside the JSON file, or in a sibling directory).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename | str | Path | Output filename, relative to | required |
basenames_only | bool | If | False |
Source code in fmu_manipulation_toolbox/assembly.py
write_ssp(filename, ssp_version='2.0') ¶
Write the assembly as an SSP archive: SystemStructure.ssd and the embedded FMUs.
The routing is written resolved (the links and ports of the auto_* rules become connections) and the options of each container go in an annotation, so that the file read back gives the same container (see SSPWriter).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename | str | Path | The | required |
ssp_version | str |
| '2.0' |
Returns:
| Name | Type | Description |
|---|---|---|
Path | Path | The file written. |
Raises:
| Type | Description |
|---|---|
AssemblyError | If the assembly is empty or the version unknown. |
Source code in fmu_manipulation_toolbox/assembly.py
Represents a node in the assembly tree, defining a container and its topology.
An AssemblyNode describes how to build a single FMU Container: which FMUs it embeds, how their ports are connected (links), which ports are exposed as container inputs/outputs, and which runtime options (multi-threading, profiling, etc.) are enabled.
Nodes can be nested via add_sub_node to create hierarchical containers.
Attributes:
| Name | Type | Description |
|---|---|---|
name | str | None | Output filename for the container (e.g. |
step_size | float | None | Internal fixed time step in seconds, or |
mt | bool | Whether multithreaded mode is enabled. |
mt_threshold | float | Multithreaded mode: the embedded FMUs whose mean step takes at least this duration, in seconds, get a worker thread. |
profiling | bool | Whether profiling mode is enabled. |
sequential | bool | Whether sequential scheduling is used. |
auto_link | bool | Automatically link ports with matching names and types. |
auto_input | bool | Automatically expose unconnected input ports. |
auto_output | bool | Automatically expose unconnected output ports. |
auto_parameter | bool | Automatically expose parameters of embedded FMUs. |
auto_local | bool | Automatically expose local variables of embedded FMUs. |
ts_multiplier | bool | Add a |
reset_ports | bool | Add a |
parent | AssemblyNode | None | Parent node in a hierarchical assembly, or |
children | dict[str, AssemblyNode] | Sub-container nodes, keyed by name. |
fmu_names_list | list[str] | Ordered list of the names of the embedded FMUs. A name is also the path of the FMU file, unless |
fmu_paths | dict[str, str] | Path of the FMU file of the names that are not their own path: the instances of an FMU embedded several times (see |
input_ports | dict[Port, str] | Mapping from destination port to exposed input name. |
output_ports | dict[Port, str] | Mapping from source port to exposed output name. |
start_values | dict[Port, str] | Mapping from port to its start value. |
drop_ports | list[Port] | List of output ports to explicitly ignore. |
links | list[Connection] | List of connections between embedded FMUs. |
architecture_wires | list[ArchitectureWire] | Dependencies between embedded FMUs read from an SSP file, kept as hints for the GUI; they are neither links nor part of the JSON description. |
fmu_geometry | dict[str, tuple[float, float, float, float]] | Position of embedded FMUs read from an SSP file: |
start_time | float | None | Start time of the default experiment of the container, from the |
stop_time | float | None | Stop time of the default experiment of the container, likewise. |
Source code in fmu_manipulation_toolbox/assembly.py
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 | |
add_architecture_wire(start_fmu, end_fmu, orientation, description=None) ¶
Declare a dependency between two embedded FMUs, without naming variables (see ArchitectureWire).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_fmu | str | Name of the embedded FMU at the start of the wire. | required |
end_fmu | str | Name of the embedded FMU at the end of the wire. | required |
orientation | str |
| required |
description | str | None | Free text (Markdown) attached to the wire. | None |
Source code in fmu_manipulation_toolbox/assembly.py
add_drop_port(fmu_filename, port_name) ¶
Mark an output port to be explicitly ignored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fmu_filename | str | Filename of the embedded FMU. | required |
port_name | str | Name of the output port to drop. | required |
Source code in fmu_manipulation_toolbox/assembly.py
add_fmu(fmu_name, fmu_path=None) ¶
Declare an embedded FMU.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fmu_name | str | Name of the FMU, used by the links, inputs, outputs, start values and dropped ports (e.g. | required |
fmu_path | str | None | Path of the FMU file, when it differs from | None |
Raises:
| Type | Description |
|---|---|
AssemblyError | If |
Source code in fmu_manipulation_toolbox/assembly.py
add_input(from_port_name, to_fmu_filename, to_port_name) ¶
Expose a port of an embedded FMU as a container input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
from_port_name | str | Name of the exposed input on the container. | required |
to_fmu_filename | str | Filename of the embedded FMU. | required |
to_port_name | str | Name of the input port on the embedded FMU. | required |
Source code in fmu_manipulation_toolbox/assembly.py
add_link(from_fmu_filename, from_port_name, to_fmu_filename, to_port_name) ¶
Connect an output port of one embedded FMU to an input port of another.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
from_fmu_filename | str | Filename of the source FMU. | required |
from_port_name | str | Name of the output port on the source FMU. | required |
to_fmu_filename | str | Filename of the destination FMU. | required |
to_port_name | str | Name of the input port on the destination FMU. | required |
Source code in fmu_manipulation_toolbox/assembly.py
add_output(from_fmu_filename, from_port_name, to_port_name) ¶
Expose a port of an embedded FMU as a container output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
from_fmu_filename | str | Filename of the embedded FMU. | required |
from_port_name | str | Name of the output port on the embedded FMU. | required |
to_port_name | str | Name of the exposed output on the container. | required |
Source code in fmu_manipulation_toolbox/assembly.py
add_start_value(fmu_filename, port_name, value) ¶
Set a start value for a port of an embedded FMU.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fmu_filename | str | Filename of the embedded FMU. | required |
port_name | str | Name of the port. | required |
value | str | Start value as a string. | required |
Source code in fmu_manipulation_toolbox/assembly.py
add_sub_node(sub_node) ¶
Add a child AssemblyNode to create a hierarchical (nested) container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sub_node | AssemblyNode | The child node to add. Its name will be auto-generated if | required |
Raises:
| Type | Description |
|---|---|
AssemblyError | If the sub-node is already parented or already a child of this node. |
Source code in fmu_manipulation_toolbox/assembly.py
fmu_path(fmu_name) ¶
get_final_from(port) ¶
Resolve the ultimate source port by traversing the assembly hierarchy upward.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
port | Port | The port to trace back to its origin. | required |
Returns:
| Name | Type | Description |
|---|---|---|
Port | Port | The resolved source port (either a top-level input or an embedded FMU port). |
Raises:
| Type | Description |
|---|---|
AssemblyError | If the port is not connected upstream. |
Source code in fmu_manipulation_toolbox/assembly.py
get_final_to(port) ¶
Resolve the ultimate destination port by traversing the assembly hierarchy downward.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
port | Port | The port to trace forward to its destination. | required |
Returns:
| Name | Type | Description |
|---|---|---|
Port | Port | The resolved destination port (either a top-level output or an embedded FMU port). |
Raises:
| Type | Description |
|---|---|
AssemblyError | If the port is not connected downstream. |
Source code in fmu_manipulation_toolbox/assembly.py
get_fmu_connections(fmu_name) ¶
Get all resolved connections involving a specific embedded FMU.
Returns connections where the given FMU is either source or destination, with ports resolved through the full assembly hierarchy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fmu_name | str | Filename of the embedded FMU. | required |
Returns:
| Type | Description |
|---|---|
list[Connection] | list[Connection]: List of connections involving the specified FMU. |
Raises:
| Type | Description |
|---|---|
AssemblyError | If the FMU is not embedded in this node. |
Source code in fmu_manipulation_toolbox/assembly.py
make_fmu(fmu_directory, debug=False, description_pathname=None, fmi_version=2, datalog=False, filename=None) ¶
Build the FMU Container.
Recursively builds any child containers first, then creates the container FMU by delegating to FMUContainer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fmu_directory | Path | Directory containing the source FMUs and where the container will be generated. | required |
debug | bool | If | False |
description_pathname | Path | None | Path to the original description file to embed in the FMU. | None |
fmi_version | int | FMI version for the container interface ( | 2 |
datalog | bool | If | False |
filename | str | None | Override the output filename. Defaults to | None |
Source code in fmu_manipulation_toolbox/assembly.py
Name under which the FMU path is embedded, given the names already used at the same level.
The first instance of a file is named after the file itself. When its base name is already used (the same file, or another file with the same base name), the name is the sibling <stem>-<n><suffix> of path, with the smallest free n: /models/model.fmu gives /models/model-1.fmu. Names are compared by base name, since an embedded FMU is designated by its base name in the built container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path | str | Path of the FMU file, as it is given to | required |
used_names | Iterable[str] | Names already used. | required |
Returns:
| Name | Type | Description |
|---|---|---|
str | str |
|