amisc.system
The System
object is a framework for multidisciplinary models. It manages multiple single discipline component
models and the connections between them. It provides a top-level interface for constructing and evaluating surrogates.
Features:
- Manages multidisciplinary models in a graph data structure, supports feedforward and feedback connections
- Feedback connections are solved with a fixed-point iteration (FPI) nonlinear solver with anderson acceleration
- Top-level interface for training and using surrogates of each component model
- Adaptive experimental design for choosing training data efficiently
- Convenient testing, plotting, and performance metrics provided to assess quality of surrogates
- Detailed logging and traceback information
- Supports parallel or vectorized execution of component models
- Abstract and flexible interfacing with component models
- Easy serialization and deserialization to/from YAML files
- Supports approximating field quantities via compression
Includes:
TrainHistory
— a history of training iterations for the system surrogateSystem
— the top-level object for managing multidisciplinary models
System(*args, components=None, root_dir=None, **kwargs)
Bases: BaseModel
, Serializable
Multidisciplinary (MD) surrogate framework top-level class. Construct a System
from a list of
Component
models.
A System
object can saved/loaded from .yml
files using the !System
yaml tag.
ATTRIBUTE | DESCRIPTION |
---|---|
name |
the name of the system
TYPE:
|
components |
list of |
train_history |
history of training iterations for the system surrogate (filled in during training)
TYPE:
|
_root_dir |
root directory where all surrogate build products are saved to file
TYPE:
|
_logger |
logger object for the system
TYPE:
|
Construct a System
object from a list of Component
models in *args
or components
. If
a root_dir
is provided, then a new directory will be created under root_dir
with the name
amisc_{timestamp}
. This directory will be used to save all build products and log files.
PARAMETER | DESCRIPTION |
---|---|
components |
list of
DEFAULT:
|
root_dir |
root directory where all surrogate build products are saved to file (optional)
DEFAULT:
|
Source code in src/amisc/system.py
refine_level: int
property
The total number of training iterations.
root_dir
property
writable
Return the root directory of the surrogate (if available), otherwise None
.
add_output()
Add an output variable retroactively to a component surrogate. User should provide a callable that takes a save path and extracts the model output data for given training point/location.
Source code in src/amisc/system.py
clear()
coupling_variables()
Collect all coupling variables from each component in the System
and combine them into a
single VariableList
object.
RETURNS | DESCRIPTION |
---|---|
VariableList
|
A |
Source code in src/amisc/system.py
deserialize(serialized_data)
classmethod
fit(targets=None, num_refine=100, max_iter=20, max_tol=0.001, runtime_hr=1.0, save_interval=0, estimate_bounds=False, update_bounds=True, test_set=None, start_test_check=None, plot_interval=1, executor=None)
Train the system surrogate adaptively by iterative refinement until an end condition is met.
PARAMETER | DESCRIPTION |
---|---|
targets |
list of system output variables to focus refinement on, use all outputs if not specified
TYPE:
|
num_refine |
number of input samples to compute error indicators on
TYPE:
|
max_iter |
the maximum number of refinement steps to take
TYPE:
|
max_tol |
the max allowable value in relative L2 error to achieve
TYPE:
|
runtime_hr |
the threshold wall clock time (hr) at which to stop further refinement (will go until all models finish the current iteration)
TYPE:
|
save_interval |
number of refinement steps between each progress save, none if 0;
TYPE:
|
estimate_bounds |
whether to estimate bounds for the coupling variables; will only try to estimate from the
TYPE:
|
update_bounds |
whether to continuously update coupling variable bounds during refinement
TYPE:
|
test_set |
TYPE:
|
start_test_check |
the iteration to start checking the test set error (defaults to twice the number of components); surrogate evaluation isn't useful during initialization so you should at least allow one iteration per component before checking test set error
TYPE:
|
plot_interval |
how often to plot the error indicator and test set error (defaults to every iteration); will only plot and save to file if a root directory is set
TYPE:
|
executor |
a
TYPE:
|
Source code in src/amisc/system.py
596 597 598 599 600 601 602 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 |
|
get_allocation(idx=None)
Get a breakdown of cost allocation up to a certain iteration number during training (starting at 1).
PARAMETER | DESCRIPTION |
---|---|
idx |
the iteration number to get allocation results for (defaults to last refinement step)
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
|
Source code in src/amisc/system.py
get_component(comp_name)
Return the Component
object for this component.
PARAMETER | DESCRIPTION |
---|---|
comp_name |
name of the component to return
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Component
|
the |
RAISES | DESCRIPTION |
---|---|
KeyError
|
if the component does not exist |
Source code in src/amisc/system.py
graph()
Build a directed graph of the system components based on their input-output relationships.
Source code in src/amisc/system.py
inputs()
Collect all inputs from each component in the System
and combine them into a
single VariableList
object, excluding variables that are also outputs of
any component.
RETURNS | DESCRIPTION |
---|---|
VariableList
|
A |
Source code in src/amisc/system.py
insert_components(components)
Insert new components into the system.
load_from_file(filename, root_dir=None, loader=None)
staticmethod
Load surrogate from file. Defaults to yaml loading. Tries to infer amisc
directory structure.
PARAMETER | DESCRIPTION |
---|---|
filename |
the name of the load file
TYPE:
|
root_dir |
set this as the surrogate's root directory (will try to load from
TYPE:
|
loader |
the encoder to use (defaults to the
DEFAULT:
|
Source code in src/amisc/system.py
outputs()
Collect all outputs from each component in the System
and combine them into a
single VariableList
object.
RETURNS | DESCRIPTION |
---|---|
VariableList
|
A |
Source code in src/amisc/system.py
plot_allocation(cmap='Blues', text_bar_width=0.06, arrow_bar_width=0.02)
Plot bar charts showing cost allocation during training.
Beta feature
This has pretty good default settings, but it might look terrible for your use. Mostly provided here as a template for making cost allocation bar charts. Please feel free to copy and edit in your own code.
PARAMETER | DESCRIPTION |
---|---|
cmap |
the colormap string identifier for
TYPE:
|
text_bar_width |
the minimum total cost fraction above which a bar will print centered model fidelity text
TYPE:
|
arrow_bar_width |
the minimum total cost fraction above which a bar will try to print text with an arrow; below this amount, the bar is too skinny and won't print any text
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
|
Source code in src/amisc/system.py
plot_slice(inputs=None, outputs=None, num_steps=20, show_surr=True, show_model=None, model_dir=None, executor=None, nominal=None, random_walk=False, from_file=None, subplot_size_in=3.0)
Helper function to plot 1d slices of the surrogate and/or model outputs over the inputs. A single
"slice" works by smoothly stepping from the lower bound of an input to its upper bound, while holding all other
inputs constant at their nominal values (or smoothly varying them if random_walk=True
).
This function is useful for visualizing the behavior of the system surrogate and/or model(s) over a
single input variable at a time.
PARAMETER | DESCRIPTION |
---|---|
inputs |
list of input variables to take 1d slices of (defaults to first 3 in
TYPE:
|
outputs |
list of model output variables to plot 1d slices of (defaults to first 3 in
TYPE:
|
num_steps |
the number of points to take in the 1d slice for each input variable; this amounts to a total of
TYPE:
|
show_surr |
whether to show the surrogate prediction
TYPE:
|
show_model |
also plot model predictions,
TYPE:
|
model_dir |
base directory to save model outputs (if specified)
TYPE:
|
executor |
a
TYPE:
|
nominal |
TYPE:
|
random_walk |
whether to slice in a random d-dimensional direction instead of holding all non-slice variables const at
TYPE:
|
from_file |
path to a
TYPE:
|
subplot_size_in |
side length size of each square subplot in inches
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
|
Source code in src/amisc/system.py
1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 |
|
predict(x, max_fpi_iter=100, anderson_mem=10, fpi_tol=1e-10, use_model=None, model_dir=None, verbose=False, index_set='test', misc_coeff=None, normalized_inputs=True, incremental=False, targets=None, executor=None, var_shape=None)
Evaluate the system surrogate at inputs x
. Return y = system(x)
.
Computing the true model with feedback loops
You can use this function to predict outputs for your MD system using the full-order models rather than the
surrogate, by specifying use_model
. This is convenient because the System
manages all the
coupled information flow between models automatically. However, it is highly recommended to not use
the full model if your system contains feedback loops. The FPI nonlinear solver would be infeasible using
anything more computationally demanding than the surrogate.
PARAMETER | DESCRIPTION |
---|---|
x |
TYPE:
|
max_fpi_iter |
the limit on convergence for the fixed-point iteration routine
TYPE:
|
anderson_mem |
hyperparameter for tuning the convergence of FPI with anderson acceleration
TYPE:
|
fpi_tol |
tolerance limit for convergence of fixed-point iteration
TYPE:
|
use_model |
'best'=highest-fidelity, 'worst'=lowest-fidelity, tuple=specific fidelity, None=surrogate, specify a
TYPE:
|
model_dir |
directory to save model outputs if
TYPE:
|
verbose |
whether to print out iteration progress during execution
TYPE:
|
index_set |
TYPE:
|
misc_coeff |
TYPE:
|
normalized_inputs |
true if the passed inputs are compressed/normalized for surrogate evaluation (default), such as inputs returned by
TYPE:
|
incremental |
whether to add
TYPE:
|
targets |
list of output variables to return, defaults to returning all system outputs
TYPE:
|
executor |
a
TYPE:
|
var_shape |
(Optional)
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Dataset
|
|
Source code in src/amisc/system.py
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 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 |
|
refine(targets=None, num_refine=100, update_bounds=True, executor=None)
Perform a single adaptive refinement step on the system surrogate.
PARAMETER | DESCRIPTION |
---|---|
targets |
list of system output variables to focus refinement on, use all outputs if not specified
TYPE:
|
num_refine |
number of input samples to compute error indicators on
TYPE:
|
update_bounds |
whether to continuously update coupling variable bounds during refinement
TYPE:
|
executor |
a
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
TrainIteration
|
|
Source code in src/amisc/system.py
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 |
|
remove_component(component)
Remove a component from the system.
sample_inputs(size, comp='System', use_pdf=False, nominal=None, constants=None)
Return samples of the inputs according to provided options. Will return samples in the
normalized/compressed space of the surrogate. See to_model_dataset
to
convert the samples to be usable by the true model directly.
PARAMETER | DESCRIPTION |
---|---|
size |
tuple or integer specifying shape or number of samples to obtain
TYPE:
|
comp |
which component to sample inputs for (defaults to full system exogenous inputs)
TYPE:
|
use_pdf |
whether to sample from each variable's pdf, defaults to random samples over input domain instead
TYPE:
|
nominal |
TYPE:
|
constants |
set of param types to hold constant while sampling (i.e. calibration, design, etc.), can also put a
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Dataset
|
|
Source code in src/amisc/system.py
save_to_file(filename, save_dir=None, dumper=None)
Save surrogate to file. Defaults to root/surrogates/filename.yml
with the default yaml encoder.
PARAMETER | DESCRIPTION |
---|---|
filename |
the name of the save file
TYPE:
|
save_dir |
the directory to save the file to (defaults to
TYPE:
|
dumper |
the encoder to use (defaults to the
DEFAULT:
|
Source code in src/amisc/system.py
serialize(keep_components=False, serialize_args=None, serialize_kwargs=None)
Convert to a dict
with only standard Python types for fields.
PARAMETER | DESCRIPTION |
---|---|
keep_components |
whether to serialize the components as well (defaults to False)
DEFAULT:
|
serialize_args |
DEFAULT:
|
serialize_kwargs |
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
dict
|
a |
Source code in src/amisc/system.py
set_logger(log_file=None, stdout=None, logger=None, level=logging.INFO)
Set a new logging.Logger
object.
PARAMETER | DESCRIPTION |
---|---|
log_file |
log to this file if str or Path (defaults to whatever is currently set or empty); set
TYPE:
|
stdout |
whether to connect the logger to console (defaults to whatever is currently set or
TYPE:
|
logger |
the logging object to use (this will override the
TYPE:
|
level |
the logging level to set the logger to (defaults to
TYPE:
|
Source code in src/amisc/system.py
simulate_fit()
Loop back through training history and simulate each iteration. Will yield the internal data structures
of each Component
surrogate after each iteration of training (without needing to call fit()
or any
of the underlying models). This might be useful, for example, for computing the surrogate predictions on
a new test set or viewing cumulative training costs.
Example
Say you have a new test set: (new_xtest, new_ytest)
, and you want to compute the accuracy of the
surrogate fit at each iteration of the training history:
RETURNS | DESCRIPTION |
---|---|
a generator of the active index sets, candidate index sets, and MISC coefficients of each component model at each iteration of the training history |
Source code in src/amisc/system.py
swap_component(old_component, new_component)
Replace an old component with a new component.
Source code in src/amisc/system.py
test_set_performance(xtest, ytest, index_set='train')
Compute the relative L2 error on a test set for the given target output variables.
PARAMETER | DESCRIPTION |
---|---|
xtest |
TYPE:
|
ytest |
TYPE:
|
index_set |
index set to use for prediction (defaults to 'train')
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
Dataset
|
|
Source code in src/amisc/system.py
timestamp()
staticmethod
Return a UTC timestamp string in the isoformat YYYY-MM-DDTHH.MM.SS
.
TrainHistory(data=None)
Bases: UserList
, Serializable
Stores the training history of a system surrogate as a list of TrainIteration
objects.
Source code in src/amisc/system.py
deserialize(serialized_data)
classmethod
serialize()
Return a list of each result in the history serialized to a dict
.