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, estimate_bounds=False, update_bounds=True, test_set=None, start_test_check=None, save_interval=0, plot_interval=1, cache_interval=0, executor=None, weight_fcns='pdf')
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:
|
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 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:
|
save_interval |
number of refinement steps between each progress save, none if 0;
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:
|
cache_interval |
how often to cache component data in order to speed up future training iterations (at the cost of additional memory usage); defaults to 0 (no caching)
TYPE:
|
executor |
a
TYPE:
|
weight_fcns |
a
TYPE:
|
Source code in src/amisc/system.py
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 |
|
get_allocation()
Get a breakdown of cost allocation during training.
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, save_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 compute and plot model predictions,
TYPE:
|
save_dir |
base directory to save model outputs and plots (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
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 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 |
|
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
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 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 |
|
refine(targets=None, num_refine=100, update_bounds=True, executor=None, weight_fcns='pdf')
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:
|
weight_fcns |
weight functions for choosing new training data for each input variable; defaults to the PDFs of each variable. If None, then no weighting is applied.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
TrainIteration
|
|
Source code in src/amisc/system.py
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 |
|
remove_component(component)
Remove a component from the system.
sample_inputs(size, component='System', normalize=True, use_pdf=False, include=None, exclude=None, nominal=None)
Return samples of the inputs according to provided options. Will return samples in the
normalized/compressed space of the surrogate by default. 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:
|
component |
which component to sample inputs for (defaults to full system exogenous inputs)
TYPE:
|
normalize |
whether to normalize the samples (defaults to True)
TYPE:
|
use_pdf |
whether to sample from variable pdfs (defaults to False, which will instead sample from the variable domain bounds). If a string or list of strings is provided, then only those variables or variable categories will be sampled using their pdfs.
TYPE:
|
include |
a list of variable or variable categories to include in the sampling. Defaults to using all input variables.
TYPE:
|
exclude |
a list of variable or variable categories to exclude from the sampling. Empty by default.
TYPE:
|
nominal |
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='test')
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
.