-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmdo_intro.tex
1676 lines (1425 loc) · 95.9 KB
/
mdo_intro.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
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
587
588
589
590
591
592
593
594
595
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
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
\documentclass[11pt]{article}
\usepackage[breakable]{tcolorbox}
\usepackage{parskip} % Stop auto-indenting (to mimic markdown behaviour)
% Basic figure setup, for now with no caption control since it's done
% automatically by Pandoc (which extracts ![](path) syntax from Markdown).
\usepackage{graphicx}
% Maintain compatibility with old templates. Remove in nbconvert 6.0
\let\Oldincludegraphics\includegraphics
% Ensure that by default, figures have no caption (until we provide a
% proper Figure object with a Caption API and a way to capture that
% in the conversion process - todo).
\usepackage{caption}
\DeclareCaptionFormat{nocaption}{}
\captionsetup{format=nocaption,aboveskip=0pt,belowskip=0pt}
\usepackage{float}
\floatplacement{figure}{H} % forces figures to be placed at the correct location
\usepackage{xcolor} % Allow colors to be defined
\usepackage{enumerate} % Needed for markdown enumerations to work
\usepackage{geometry} % Used to adjust the document margins
\usepackage{amsmath} % Equations
\usepackage{amssymb} % Equations
\usepackage{textcomp} % defines textquotesingle
% Hack from http://tex.stackexchange.com/a/47451/13684:
\AtBeginDocument{%
\def\PYZsq{\textquotesingle}% Upright quotes in Pygmentized code
}
\usepackage{upquote} % Upright quotes for verbatim code
\usepackage{eurosym} % defines \euro
\usepackage{iftex}
\ifPDFTeX
\usepackage[T1]{fontenc}
\IfFileExists{alphabeta.sty}{
\usepackage{alphabeta}
}{
\usepackage[mathletters]{ucs}
\usepackage[utf8x]{inputenc}
}
\else
\usepackage{fontspec}
\usepackage{unicode-math}
\fi
\usepackage{fancyvrb} % verbatim replacement that allows latex
\usepackage{grffile} % extends the file name processing of package graphics
% to support a larger range
\makeatletter % fix for old versions of grffile with XeLaTeX
\@ifpackagelater{grffile}{2019/11/01}
{
% Do nothing on new versions
}
{
\def\Gread@@xetex#1{%
\IfFileExists{"\Gin@base".bb}%
{\Gread@eps{\Gin@base.bb}}%
{\Gread@@xetex@aux#1}%
}
}
\makeatother
\usepackage[Export]{adjustbox} % Used to constrain images to a maximum size
\adjustboxset{max size={0.9\linewidth}{0.9\paperheight}}
% The hyperref package gives us a pdf with properly built
% internal navigation ('pdf bookmarks' for the table of contents,
% internal cross-reference links, web links for URLs, etc.)
\usepackage{hyperref}
% The default LaTeX title has an obnoxious amount of whitespace. By default,
% titling removes some of it. It also provides customization options.
\usepackage{titling}
\usepackage{longtable} % longtable support required by pandoc >1.10
\usepackage{booktabs} % table support for pandoc > 1.12.2
\usepackage{array} % table support for pandoc >= 2.11.3
\usepackage{calc} % table minipage width calculation for pandoc >= 2.11.1
\usepackage[inline]{enumitem} % IRkernel/repr support (it uses the enumerate* environment)
\usepackage[normalem]{ulem} % ulem is needed to support strikethroughs (\sout)
% normalem makes italics be italics, not underlines
\usepackage{mathrsfs}
% Colors for the hyperref package
\definecolor{urlcolor}{rgb}{0,.145,.698}
\definecolor{linkcolor}{rgb}{.71,0.21,0.01}
\definecolor{citecolor}{rgb}{.12,.54,.11}
% ANSI colors
\definecolor{ansi-black}{HTML}{3E424D}
\definecolor{ansi-black-intense}{HTML}{282C36}
\definecolor{ansi-red}{HTML}{E75C58}
\definecolor{ansi-red-intense}{HTML}{B22B31}
\definecolor{ansi-green}{HTML}{00A250}
\definecolor{ansi-green-intense}{HTML}{007427}
\definecolor{ansi-yellow}{HTML}{DDB62B}
\definecolor{ansi-yellow-intense}{HTML}{B27D12}
\definecolor{ansi-blue}{HTML}{208FFB}
\definecolor{ansi-blue-intense}{HTML}{0065CA}
\definecolor{ansi-magenta}{HTML}{D160C4}
\definecolor{ansi-magenta-intense}{HTML}{A03196}
\definecolor{ansi-cyan}{HTML}{60C6C8}
\definecolor{ansi-cyan-intense}{HTML}{258F8F}
\definecolor{ansi-white}{HTML}{C5C1B4}
\definecolor{ansi-white-intense}{HTML}{A1A6B2}
\definecolor{ansi-default-inverse-fg}{HTML}{FFFFFF}
\definecolor{ansi-default-inverse-bg}{HTML}{000000}
% common color for the border for error outputs.
\definecolor{outerrorbackground}{HTML}{FFDFDF}
% commands and environments needed by pandoc snippets
% extracted from the output of `pandoc -s`
\providecommand{\tightlist}{%
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}}
% Add ',fontsize=\small' for more characters per line
\newenvironment{Shaded}{}{}
\newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{\textbf{{#1}}}}
\newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.56,0.13,0.00}{{#1}}}
\newcommand{\DecValTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{{#1}}}
\newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{{#1}}}
\newcommand{\FloatTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{{#1}}}
\newcommand{\CharTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}}
\newcommand{\StringTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}}
\newcommand{\CommentTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textit{{#1}}}}
\newcommand{\OtherTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{{#1}}}
\newcommand{\AlertTok}[1]{\textcolor[rgb]{1.00,0.00,0.00}{\textbf{{#1}}}}
\newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.02,0.16,0.49}{{#1}}}
\newcommand{\RegionMarkerTok}[1]{{#1}}
\newcommand{\ErrorTok}[1]{\textcolor[rgb]{1.00,0.00,0.00}{\textbf{{#1}}}}
\newcommand{\NormalTok}[1]{{#1}}
% Additional commands for more recent versions of Pandoc
\newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.53,0.00,0.00}{{#1}}}
\newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}}
\newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}}
\newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.73,0.40,0.53}{{#1}}}
\newcommand{\ImportTok}[1]{{#1}}
\newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.73,0.13,0.13}{\textit{{#1}}}}
\newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{{#1}}}}}
\newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{{#1}}}}}
\newcommand{\VariableTok}[1]{\textcolor[rgb]{0.10,0.09,0.49}{{#1}}}
\newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{\textbf{{#1}}}}
\newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.40,0.40,0.40}{{#1}}}
\newcommand{\BuiltInTok}[1]{{#1}}
\newcommand{\ExtensionTok}[1]{{#1}}
\newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.74,0.48,0.00}{{#1}}}
\newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.49,0.56,0.16}{{#1}}}
\newcommand{\InformationTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{{#1}}}}}
\newcommand{\WarningTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{{#1}}}}}
% Define a nice break command that doesn't care if a line doesn't already
% exist.
\def\br{\hspace*{\fill} \\* }
% Math Jax compatibility definitions
\def\gt{>}
\def\lt{<}
\let\Oldtex\TeX
\let\Oldlatex\LaTeX
\renewcommand{\TeX}{\textrm{\Oldtex}}
\renewcommand{\LaTeX}{\textrm{\Oldlatex}}
% Document parameters
% Document title
\title{mdo\_intro}
% Pygments definitions
\makeatletter
\def\PY@reset{\let\PY@it=\relax \let\PY@bf=\relax%
\let\PY@ul=\relax \let\PY@tc=\relax%
\let\PY@bc=\relax \let\PY@ff=\relax}
\def\PY@tok#1{\csname PY@tok@#1\endcsname}
\def\PY@toks#1+{\ifx\relax#1\empty\else%
\PY@tok{#1}\expandafter\PY@toks\fi}
\def\PY@do#1{\PY@bc{\PY@tc{\PY@ul{%
\PY@it{\PY@bf{\PY@ff{#1}}}}}}}
\def\PY#1#2{\PY@reset\PY@toks#1+\relax+\PY@do{#2}}
\@namedef{PY@tok@w}{\def\PY@tc##1{\textcolor[rgb]{0.73,0.73,0.73}{##1}}}
\@namedef{PY@tok@c}{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}}
\@namedef{PY@tok@cp}{\def\PY@tc##1{\textcolor[rgb]{0.74,0.48,0.00}{##1}}}
\@namedef{PY@tok@k}{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
\@namedef{PY@tok@kp}{\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
\@namedef{PY@tok@kt}{\def\PY@tc##1{\textcolor[rgb]{0.69,0.00,0.25}{##1}}}
\@namedef{PY@tok@o}{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
\@namedef{PY@tok@ow}{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.67,0.13,1.00}{##1}}}
\@namedef{PY@tok@nb}{\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
\@namedef{PY@tok@nf}{\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}}
\@namedef{PY@tok@nc}{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}}
\@namedef{PY@tok@nn}{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}}
\@namedef{PY@tok@ne}{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.82,0.25,0.23}{##1}}}
\@namedef{PY@tok@nv}{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}}
\@namedef{PY@tok@no}{\def\PY@tc##1{\textcolor[rgb]{0.53,0.00,0.00}{##1}}}
\@namedef{PY@tok@nl}{\def\PY@tc##1{\textcolor[rgb]{0.63,0.63,0.00}{##1}}}
\@namedef{PY@tok@ni}{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.60,0.60,0.60}{##1}}}
\@namedef{PY@tok@na}{\def\PY@tc##1{\textcolor[rgb]{0.49,0.56,0.16}{##1}}}
\@namedef{PY@tok@nt}{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
\@namedef{PY@tok@nd}{\def\PY@tc##1{\textcolor[rgb]{0.67,0.13,1.00}{##1}}}
\@namedef{PY@tok@s}{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
\@namedef{PY@tok@sd}{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
\@namedef{PY@tok@si}{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.73,0.40,0.53}{##1}}}
\@namedef{PY@tok@se}{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.73,0.40,0.13}{##1}}}
\@namedef{PY@tok@sr}{\def\PY@tc##1{\textcolor[rgb]{0.73,0.40,0.53}{##1}}}
\@namedef{PY@tok@ss}{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}}
\@namedef{PY@tok@sx}{\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
\@namedef{PY@tok@m}{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
\@namedef{PY@tok@gh}{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,0.50}{##1}}}
\@namedef{PY@tok@gu}{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.50,0.00,0.50}{##1}}}
\@namedef{PY@tok@gd}{\def\PY@tc##1{\textcolor[rgb]{0.63,0.00,0.00}{##1}}}
\@namedef{PY@tok@gi}{\def\PY@tc##1{\textcolor[rgb]{0.00,0.63,0.00}{##1}}}
\@namedef{PY@tok@gr}{\def\PY@tc##1{\textcolor[rgb]{1.00,0.00,0.00}{##1}}}
\@namedef{PY@tok@ge}{\let\PY@it=\textit}
\@namedef{PY@tok@gs}{\let\PY@bf=\textbf}
\@namedef{PY@tok@gp}{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,0.50}{##1}}}
\@namedef{PY@tok@go}{\def\PY@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}}
\@namedef{PY@tok@gt}{\def\PY@tc##1{\textcolor[rgb]{0.00,0.27,0.87}{##1}}}
\@namedef{PY@tok@err}{\def\PY@bc##1{{\setlength{\fboxsep}{\string -\fboxrule}\fcolorbox[rgb]{1.00,0.00,0.00}{1,1,1}{\strut ##1}}}}
\@namedef{PY@tok@kc}{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
\@namedef{PY@tok@kd}{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
\@namedef{PY@tok@kn}{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
\@namedef{PY@tok@kr}{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
\@namedef{PY@tok@bp}{\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
\@namedef{PY@tok@fm}{\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}}
\@namedef{PY@tok@vc}{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}}
\@namedef{PY@tok@vg}{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}}
\@namedef{PY@tok@vi}{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}}
\@namedef{PY@tok@vm}{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}}
\@namedef{PY@tok@sa}{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
\@namedef{PY@tok@sb}{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
\@namedef{PY@tok@sc}{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
\@namedef{PY@tok@dl}{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
\@namedef{PY@tok@s2}{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
\@namedef{PY@tok@sh}{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
\@namedef{PY@tok@s1}{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
\@namedef{PY@tok@mb}{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
\@namedef{PY@tok@mf}{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
\@namedef{PY@tok@mh}{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
\@namedef{PY@tok@mi}{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
\@namedef{PY@tok@il}{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
\@namedef{PY@tok@mo}{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
\@namedef{PY@tok@ch}{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}}
\@namedef{PY@tok@cm}{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}}
\@namedef{PY@tok@cpf}{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}}
\@namedef{PY@tok@c1}{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}}
\@namedef{PY@tok@cs}{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}}
\def\PYZbs{\char`\\}
\def\PYZus{\char`\_}
\def\PYZob{\char`\{}
\def\PYZcb{\char`\}}
\def\PYZca{\char`\^}
\def\PYZam{\char`\&}
\def\PYZlt{\char`\<}
\def\PYZgt{\char`\>}
\def\PYZsh{\char`\#}
\def\PYZpc{\char`\%}
\def\PYZdl{\char`\$}
\def\PYZhy{\char`\-}
\def\PYZsq{\char`\'}
\def\PYZdq{\char`\"}
\def\PYZti{\char`\~}
% for compatibility with earlier versions
\def\PYZat{@}
\def\PYZlb{[}
\def\PYZrb{]}
\makeatother
% For linebreaks inside Verbatim environment from package fancyvrb.
\makeatletter
\newbox\Wrappedcontinuationbox
\newbox\Wrappedvisiblespacebox
\newcommand*\Wrappedvisiblespace {\textcolor{red}{\textvisiblespace}}
\newcommand*\Wrappedcontinuationsymbol {\textcolor{red}{\llap{\tiny$\m@th\hookrightarrow$}}}
\newcommand*\Wrappedcontinuationindent {3ex }
\newcommand*\Wrappedafterbreak {\kern\Wrappedcontinuationindent\copy\Wrappedcontinuationbox}
% Take advantage of the already applied Pygments mark-up to insert
% potential linebreaks for TeX processing.
% {, <, #, %, $, ' and ": go to next line.
% _, }, ^, &, >, - and ~: stay at end of broken line.
% Use of \textquotesingle for straight quote.
\newcommand*\Wrappedbreaksatspecials {%
\def\PYGZus{\discretionary{\char`\_}{\Wrappedafterbreak}{\char`\_}}%
\def\PYGZob{\discretionary{}{\Wrappedafterbreak\char`\{}{\char`\{}}%
\def\PYGZcb{\discretionary{\char`\}}{\Wrappedafterbreak}{\char`\}}}%
\def\PYGZca{\discretionary{\char`\^}{\Wrappedafterbreak}{\char`\^}}%
\def\PYGZam{\discretionary{\char`\&}{\Wrappedafterbreak}{\char`\&}}%
\def\PYGZlt{\discretionary{}{\Wrappedafterbreak\char`\<}{\char`\<}}%
\def\PYGZgt{\discretionary{\char`\>}{\Wrappedafterbreak}{\char`\>}}%
\def\PYGZsh{\discretionary{}{\Wrappedafterbreak\char`\#}{\char`\#}}%
\def\PYGZpc{\discretionary{}{\Wrappedafterbreak\char`\%}{\char`\%}}%
\def\PYGZdl{\discretionary{}{\Wrappedafterbreak\char`\$}{\char`\$}}%
\def\PYGZhy{\discretionary{\char`\-}{\Wrappedafterbreak}{\char`\-}}%
\def\PYGZsq{\discretionary{}{\Wrappedafterbreak\textquotesingle}{\textquotesingle}}%
\def\PYGZdq{\discretionary{}{\Wrappedafterbreak\char`\"}{\char`\"}}%
\def\PYGZti{\discretionary{\char`\~}{\Wrappedafterbreak}{\char`\~}}%
}
% Some characters . , ; ? ! / are not pygmentized.
% This macro makes them "active" and they will insert potential linebreaks
\newcommand*\Wrappedbreaksatpunct {%
\lccode`\~`\.\lowercase{\def~}{\discretionary{\hbox{\char`\.}}{\Wrappedafterbreak}{\hbox{\char`\.}}}%
\lccode`\~`\,\lowercase{\def~}{\discretionary{\hbox{\char`\,}}{\Wrappedafterbreak}{\hbox{\char`\,}}}%
\lccode`\~`\;\lowercase{\def~}{\discretionary{\hbox{\char`\;}}{\Wrappedafterbreak}{\hbox{\char`\;}}}%
\lccode`\~`\:\lowercase{\def~}{\discretionary{\hbox{\char`\:}}{\Wrappedafterbreak}{\hbox{\char`\:}}}%
\lccode`\~`\?\lowercase{\def~}{\discretionary{\hbox{\char`\?}}{\Wrappedafterbreak}{\hbox{\char`\?}}}%
\lccode`\~`\!\lowercase{\def~}{\discretionary{\hbox{\char`\!}}{\Wrappedafterbreak}{\hbox{\char`\!}}}%
\lccode`\~`\/\lowercase{\def~}{\discretionary{\hbox{\char`\/}}{\Wrappedafterbreak}{\hbox{\char`\/}}}%
\catcode`\.\active
\catcode`\,\active
\catcode`\;\active
\catcode`\:\active
\catcode`\?\active
\catcode`\!\active
\catcode`\/\active
\lccode`\~`\~
}
\makeatother
\let\OriginalVerbatim=\Verbatim
\makeatletter
\renewcommand{\Verbatim}[1][1]{%
%\parskip\z@skip
\sbox\Wrappedcontinuationbox {\Wrappedcontinuationsymbol}%
\sbox\Wrappedvisiblespacebox {\FV@SetupFont\Wrappedvisiblespace}%
\def\FancyVerbFormatLine ##1{\hsize\linewidth
\vtop{\raggedright\hyphenpenalty\z@\exhyphenpenalty\z@
\doublehyphendemerits\z@\finalhyphendemerits\z@
\strut ##1\strut}%
}%
% If the linebreak is at a space, the latter will be displayed as visible
% space at end of first line, and a continuation symbol starts next line.
% Stretch/shrink are however usually zero for typewriter font.
\def\FV@Space {%
\nobreak\hskip\z@ plus\fontdimen3\font minus\fontdimen4\font
\discretionary{\copy\Wrappedvisiblespacebox}{\Wrappedafterbreak}
{\kern\fontdimen2\font}%
}%
% Allow breaks at special characters using \PYG... macros.
\Wrappedbreaksatspecials
% Breaks at punctuation characters . , ; ? ! and / need catcode=\active
\OriginalVerbatim[#1,codes*=\Wrappedbreaksatpunct]%
}
\makeatother
% Exact colors from NB
\definecolor{incolor}{HTML}{303F9F}
\definecolor{outcolor}{HTML}{D84315}
\definecolor{cellborder}{HTML}{CFCFCF}
\definecolor{cellbackground}{HTML}{F7F7F7}
% prompt
\makeatletter
\newcommand{\boxspacing}{\kern\kvtcb@left@rule\kern\kvtcb@boxsep}
\makeatother
\newcommand{\prompt}[4]{
{\ttfamily\llap{{\color{#2}[#3]:\hspace{3pt}#4}}\vspace{-\baselineskip}}
}
% Prevent overflowing lines due to hard-to-break entities
\sloppy
% Setup hyperref package
\hypersetup{
breaklinks=true, % so long urls are correctly broken across lines
colorlinks=true,
urlcolor=urlcolor,
linkcolor=linkcolor,
citecolor=citecolor,
}
% Slightly bigger margins than the latex defaults
\geometry{verbose,tmargin=1in,bmargin=1in,lmargin=1in,rmargin=1in}
\begin{document}
\maketitle
\begin{tcolorbox}[breakable, size=fbox, boxrule=1pt, pad at break*=1mm,colback=cellbackground, colframe=cellborder]
\prompt{In}{incolor}{1}{\boxspacing}
\begin{Verbatim}[commandchars=\\\{\}]
\PY{k+kn}{import} \PY{n+nn}{numpy} \PY{k}{as} \PY{n+nn}{np}
\end{Verbatim}
\end{tcolorbox}
\hypertarget{intro-to-multidisciplinary-analysis-mda}{%
\section{Intro to multidisciplinary analysis
(MDA)}\label{intro-to-multidisciplinary-analysis-mda}}
The motivation for multidisciplinary design optimization (MDO) comes
from the large number of multidisciplinary analyses (MDAs) that are
common in engineering. The most famous MDA in engineering is the
aero-structural analysis problem. We will illustrate using the example
of a wing subject to aero-structural loads. The aerodynamic forces
deflect the wing which changes its shape, which in turn changes the
aerodynamic behaviour of the wing.
We will look at a simplified example of a wing modeled as a cantilever
beam, made of Euler-Bernoulli beam sections, subject to aerodynamic
forces.
\hypertarget{illustrative-example-structure-fluids-interaction-problem}{%
\subsection{Illustrative example: Structure-fluids interaction
problem}\label{illustrative-example-structure-fluids-interaction-problem}}
\begin{longtable}[]{@{}c@{}}
\toprule
\endhead
\begin{minipage}[t]{0.97\columnwidth}\centering
\begin{figure}
\centering
\includegraphics[height=5cm]{images/wing_structure_fluid.pdf}
\end{figure}\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.97\columnwidth}\centering
Fig.0 Aerostructural wing model showing the aerodynamic state variables
(circulations \(\Gamma\)) on the left and structural state variables
(displacements \(\mathbf{d}_z\) and rotations \(\mathbf{d}_\theta\)) on
the right.\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.97\columnwidth}\centering
\emph{From Martins and Ning}\strut
\end{minipage}\tabularnewline
\bottomrule
\end{longtable}
\hypertarget{structural-analysis}{%
\subsubsection{Structural Analysis}\label{structural-analysis}}
Structural analysis can be performed using finite element software to
solve for the structural displacements \(\mathbf{d}\) given some
boundary conditions such as forces \(\mathbf{q}\). These forces may come
from an aerodynamic analysis and are related to the computational fluid
dynamics state variables \(\hat{\Gamma}\). In this example,
\(\hat{\Gamma}\) is the circulation vortex strength on a wing. The hat
denotes that these values are estimates of the state variables when the
analysis has converged and are called \emph{coupling variables}.
\begin{equation}
K\mathbf{d} - \mathbf{q}(\hat{\Gamma}) = \mathbf{0}
\tag{1}
\end{equation}
Solving the above equation is done by specialized finite element
software and returns a solution \({\mathbf{d}}\) that estimates the
displacements. In other words, the FEA program can be thought of as a
function \(\mathcal{U}_1(\hat{\Gamma})\) that returns the displacements
\({\mathbf{d}}\) given some aerodynamic forces
\(\mathbf{q}(\hat{\Gamma})\).
The residual for this discipline becomes
\(r_1(\hat{\mathbf{d}};\hat{\mathbf{q}}) = \hat{\mathbf{d}} - \mathcal{U}_1(\hat{\Gamma}) = \hat{\mathbf{d}} - {\mathbf{d}} = \mathbf{0}\)
and solving it returns an estimate of displacements that will cause the
analysis to converge \(\hat{\mathbf{d}}\). These estimates will be
passed back to the aerodynamic analysis.
\hypertarget{aerodynamic-analysis}{%
\subsubsection{Aerodynamic Analysis}\label{aerodynamic-analysis}}
The aerodynamic analysis involves solving the following system of
equations using computational fluid dynamics (CFD).
\begin{equation}
A(\hat{\mathbf{d}})\Gamma - \mathbf{v}(\hat{\mathbf{d}}) = \mathbf{0}
\tag{2}
\end{equation}
where \(\Gamma\) is the state vector we want to solve for representing
the circulation vortex strength. \(\mathbf{v}\) is a vector of boundary
conditions (similar to the vector of applied loads \(\mathbf{q}\) in the
structural analysis). \(A\) is the matrix of aerodynamic influence
coefficients (similar to the global stiffness matrix \(K\) from the
structural analysis). However, unlike \(K\), \(A\) depends on the shape
of the wing which in turn depends on the displacements estimated by the
structural analysis \(\hat{\mathbf{d}}\).
The residual for this discipline becomes
\(r_2(\hat{\Gamma};\hat{\mathbf{d}}) = \hat{\Gamma} - \mathcal{U}_2(\hat{\mathbf{d}}) = \hat{\Gamma} - {\Gamma} = \mathbf{0}\),
where \(\mathcal{U}_2(\hat{\mathbf{d}})\) involves solving Equation (2)
for the circulation vortex strength \(\Gamma\).
The estimated coupling variable \(\hat{\Gamma}\) is passed back to the
aerodynamic analysis. The previous analysis can be described by the
diagram below.
\begin{longtable}[]{@{}c@{}}
\toprule
\endhead
\begin{minipage}[t]{0.97\columnwidth}\centering
\begin{figure}
\centering
\includegraphics[width=0.9\textwidth]{images/MDA_diagram_aero.png}
\end{figure}\strut
\end{minipage}\tabularnewline
Fig.1 Aerostructural multidisciplinary analysis (MDA)
diagram.\tabularnewline
\bottomrule
\end{longtable}
The XDSM for the aforementioned aero-structural analysis problem is
shown below:
The XDSM for aerostructural example looks like this:
\begin{longtable}[]{@{}c@{}}
\toprule
\endhead
\begin{minipage}[t]{0.97\columnwidth}\centering
\begin{figure}
\centering
\includegraphics[height=6cm]{xdsm/aerostructural.pdf}
\end{figure}\strut
\end{minipage}\tabularnewline
Fig.2 XDSM for Aerostructural multidisciplinary analysis
(MDA).\tabularnewline
\bottomrule
\end{longtable}
\hypertarget{numerical-mda-example}{%
\subsection{Numerical MDA example}\label{numerical-mda-example}}
Consider the following coupled optimization problem
\begin{equation*}
\begin{aligned}
& \underset{\mathbf{x} = \left[u,v,w\right]^\mathrm{T}}{\text{minimize}}
& & f(u,v;a,b) = u+v+a+b\\
& \text{subject to}
& & g(w;b) = w + b -10 \leq 0\\
& & & 0 \leq u,v,w \leq 10\\
& \text{while solving}
& & r_1(a;b) = a - \left(\log(u) + \log(v) + \log(b)\right) = 0\\
& & & r_2(b;a) = b - \left(u^{-1} + w^{-1} + a^{-1}\right) = 0\\
& \text{for a given $u$, $v$, and $w$}
\end{aligned}
\tag{3}
\end{equation*}
Solving for the state variables \(a\) and \(b\) involves solving the set
of equations below. Equation (4) is an example of an MDA (just like the
aerostructural problem earlier):
\begin{equation*}
\begin{aligned}
& r_1(a;b) = a - \left(\log(u) + \log(v) + \log(b)\right) = 0\\
& r_2(b;a) = b - \left(u^{-1} + w^{-1} + a^{-1}\right) = 0\\
\end{aligned}
\tag{4}
\end{equation*}
which cannot be solved explicitly. To prove this, Let us try to find an
explicit expression for \(a\) in terms of \(b\).
\begin{tcolorbox}[breakable, size=fbox, boxrule=1pt, pad at break*=1mm,colback=cellbackground, colframe=cellborder]
\prompt{In}{incolor}{2}{\boxspacing}
\begin{Verbatim}[commandchars=\\\{\}]
\PY{k+kn}{import} \PY{n+nn}{sympy} \PY{k}{as} \PY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\PY{p}{(}\PY{n}{b}\PY{p}{)}
\PY{n}{r2} \PY{o}{=} \PY{n}{b} \PY{o}{\PYZhy{}} \PY{l+m+mi}{1}\PY{o}{/}\PY{n}{u} \PY{o}{\PYZhy{}} \PY{l+m+mi}{1}\PY{o}{/}\PY{n}{w} \PY{o}{\PYZhy{}} \PY{l+m+mi}{1}\PY{o}{/}\PY{n}{a}
\PY{n}{eq1} \PY{o}{=} \PY{n}{a} \PY{o}{\PYZhy{}} \PY{n}{sym}\PY{o}{.}\PY{n}{log}\PY{p}{(}\PY{n}{u}\PY{p}{)} \PY{o}{\PYZhy{}} \PY{n}{sym}\PY{o}{.}\PY{n}{log}\PY{p}{(}\PY{n}{v}\PY{p}{)} \PY{o}{\PYZhy{}} \PY{n}{sym}\PY{o}{.}\PY{n}{log}\PY{p}{(}\PY{l+m+mi}{1}\PY{o}{/}\PY{n}{u} \PY{o}{+} \PY{l+m+mi}{1}\PY{o}{/}\PY{n}{w} \PY{o}{+} \PY{l+m+mi}{1}\PY{o}{/}\PY{n}{a}\PY{p}{)}
\PY{c+c1}{\PYZsh{} sym.solve(eq1,a) \PYZsh{} trying to solve for a explicitly will result in an error!}
\end{Verbatim}
\end{tcolorbox}
Instead, we focus on solving for \(a\) and \(b\) such that the residuals
\(r_1=0\) and \(r_2=0\) iteratively using a Multidisciplinary Analysis
(MDA) for a fixed value of \(u\), \(v\), and \(w\). First let us
slightly change the notation of the governing equations:
\begin{align*}
& r_1(\hat{a};\hat{b}) = \hat{a} - \mathcal{U}_1(\hat{b}) = 0\\
& r_2(\hat{b};\hat{a}) = \hat{b} - \mathcal{U}_2(\hat{a}) = 0\\
\end{align*}
\(\mathcal{U}_1(\hat{b})\) and \(\mathcal{U}_2(\hat{a})\) are considered
the discipline solvers and could represent the FEA and CFD programs in
the aerostructural problem.
\hypertarget{the-nonlinear-block-gaussseidel-and-block-jacobi-mda-algorithms}{%
\subsection{The Nonlinear block Gauss--Seidel and block Jacobi MDA
algorithms}\label{the-nonlinear-block-gaussseidel-and-block-jacobi-mda-algorithms}}
The MDA approach we will use is called the \emph{block Gauss--Seidel
algorithm} and has an XDSM similar to that of the aerostructural
problem. 1) Starting with an initial guess for \(\hat{a}\) and
\(\hat{b}\), \(\hat{a}^{(0)}\) and \(\hat{b}^{(0)}\), respectively, 2)
we solve discipline 1 for \(\hat{a}\). 3) We feed \(\hat{a}\) into
discipline 2, 4) and then solve for \(\hat{b}\) and then go back to step
2.
We repeat the above process until
\(\hat{a}_\mathrm{new} - \hat{a}_\mathrm{old} \leq \varepsilon\), where
\(\varepsilon\) is some tolerance. We can also solve for \(\hat{a}\) and
\(\hat{b}\) simultaneously rather than serially resulting in the block
Jacobi MDA.
The XDSM for the above MDAs is shown below:
\begin{longtable}[]{@{}c@{}}
\toprule
\endhead
\begin{minipage}[t]{0.97\columnwidth}\centering
\begin{figure}
\centering
\includegraphics[width=0.7\textwidth]{xdsm/gauss.pdf}
\end{figure}
\begin{figure}
\centering
\includegraphics[width=0.7\textwidth]{xdsm/gauss.pdf}
\end{figure}
\end{minipage}\tabularnewline
Fig.3 block Gauss--Seidel and Block Jacobi MDAs.\tabularnewline
\bottomrule
\end{longtable}
This algorithm is implemented below in Python.
\begin{tcolorbox}[breakable, size=fbox, boxrule=1pt, pad at break*=1mm,colback=cellbackground, colframe=cellborder]
\prompt{In}{incolor}{3}{\boxspacing}
\begin{Verbatim}[commandchars=\\\{\}]
\PY{c+c1}{\PYZsh{} these are your coupled disciplines}
\PY{n}{U1} \PY{o}{=} \PY{k}{lambda} \PY{n}{uj}\PY{p}{:} \PY{n}{np}\PY{o}{.}\PY{n}{log}\PY{p}{(}\PY{n}{u}\PY{p}{)} \PY{o}{+} \PY{n}{np}\PY{o}{.}\PY{n}{log}\PY{p}{(}\PY{n}{v}\PY{p}{)} \PY{o}{+} \PY{n}{np}\PY{o}{.}\PY{n}{log}\PY{p}{(}\PY{n}{uj}\PY{p}{[}\PY{l+m+mi}{0}\PY{p}{]}\PY{o}{+}\P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
\PY{n}{mask}\PY{p}{[}\PY{n}{i}\PY{p}{]} \PY{o}{=} \PY{k+kc}{False} \PY{c+c1}{\PYZsh{} select all state variables except the current one (u\PYZus{}i)}
\PY{n}{uk}\PY{p}{[}\PY{n}{i}\PY{p}{]} \PY{o}{=} \PY{n}{discipline}\PY{p}{(}\PY{n}{uk}\PY{p}{[}\PY{n}{mask}\PY{p}{]}\PY{p}{)}
\PY{k}{if} \PY{n}{np}\PY{o}{.}\PY{n}{linalg}\PY{o}{.}\PY{n}{norm}\PY{p}{(}\PY{n}{uk} \PY{o}{\PYZhy{}} \PY{n}{uk\PYZus{}old}\PY{p}{)} \PY{o}{\PYZlt{}}\PY{o}{=} \PY{n}{e} \PY{o+ow}{or} \PY{n}{k} \PY{o}{\PYZgt{}} \PY{l+m+mi}{10}\PY{p}{:}
\PY{k}{break}
\PY{n}{k}\PY{o}{+}\PY{o}{=}\PY{l+m+mi}{1}
\PY{n+nb}{print}\PY{p}{(}\PY{n}{uk}\PY{p}{)}
\end{Verbatim}
\end{tcolorbox}
\begin{Verbatim}[commandchars=\\\{\}]
[ 0 1000002]
[13 2]
[ 0 1000002]
[13 2]
[ 0 1000002]
[13 2]
[ 0 1000002]
[13 2]
[ 0 1000002]
[13 2]
[ 0 1000002]
\end{Verbatim}
We can see that the previous algorithm did not converge. It started to
oscillate. We can use an alternative algorithm that is based on the
Newton-Raphson scheme to handle the coupling between the disciplines.
\hypertarget{the-reduced-space-hierarchical-newton-solver}{%
\subsection{The reduced-space hierarchical Newton
solver}\label{the-reduced-space-hierarchical-newton-solver}}
This algorithm is unequivocally also called \emph{Newton's Method}. As
with the Newton-Raphson algorithm, it requires derivative information to
find the coupling variables \(\hat{a}\) and \(\hat{b}\) at which
convergence occurs. The algorithm goes something like this:
\begin{enumerate}
\def\labelenumi{\arabic{enumi})}
\tightlist
\item
Starting with an initial guess for \(\hat{a}\) and \(\hat{b}\),
\(\hat{a}^{(0)}\) and \(\hat{b}^{(0)}\), respectively,
\item
we solve discipline 1 for \(\hat{a}\). We also find the gradient of
the discipline analysis \(\mathcal{U}(\hat{b})\) with respect to
\(\hat{b}\). In other words,
\(\dfrac{\partial\mathcal{U}_1}{\partial\hat{b}}\) (all coupling
variables except \(\hat{a}\))
\item
In parallel, we solve discipline 2 for \(\hat{b}\). We also find the
gradient with respect to \(\hat{a}\),
\(\dfrac{\partial\mathcal{U}_2}{\partial\hat{b}}\) (all coupling
variables except \(\hat{b}\))
\item
We solve the following system of equations for \(\Delta\hat{a}\) and
\(\Delta\hat{b}\): \[
\begin{bmatrix}
1 & \left.\dfrac{\partial\mathcal{U}_1}{\partial\hat{b}}\right|_{\hat{b}} \\
\left.\dfrac{\partial\mathcal{U}_2}{\partial\hat{a}}\right|_{\hat{a}} & 1 \\
\end{bmatrix}
\begin{bmatrix}
\Delta\hat{a}\\
\Delta\hat{b}\\
\end{bmatrix} = -
\begin{bmatrix}
\hat{a} - \mathcal{U}_1(\hat{b})\\
\hat{b} - \mathcal{U}_2(\hat{a})\\
\end{bmatrix}
\]
\item
we update \(\hat{a}\) and \(\hat{b}\) according to
\(\hat{a} \gets \hat{a} + \Delta\hat{a}\) and
\(\hat{a} \gets \hat{a} + \Delta\hat{a}\), respectively and go back to
step 2.
\end{enumerate}
The XDSM for the above MDA is shown below:
\begin{longtable}[]{@{}c@{}}
\toprule
\endhead
\begin{minipage}[t]{0.97\columnwidth}\centering
\begin{figure}
\centering
\includegraphics[width=0.9\textwidth]{xdsm/newton.pdf}
\end{figure}
\end{minipage}\tabularnewline
Fig.4 Reduced-space hierarchical Newton solver.\tabularnewline
\bottomrule
\end{longtable}
This algorithm is implemented below in Python.
\begin{tcolorbox}[breakable, size=fbox, boxrule=1pt, pad at break*=1mm,colback=cellbackground, colframe=cellborder]
\prompt{In}{incolor}{4}{\boxspacing}
\begin{Verbatim}[commandchars=\\\{\}]
\PY{c+c1}{\PYZsh{} these are your coupled disciplines}
\PY{n}{U1} \PY{o}{=} \PY{k}{lambda} \PY{n}{u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PY{p}{]}\PY{o}{*}\PY{n+nb}{len}\PY{p}{(}\PY{n}{disciplines}\PY{p}{)}
\PY{n}{mask}\PY{p}{[}\PY{n}{i}\PY{p}{]} \PY{o}{=} \PY{k+kc}{False} \PY{c+c1}{\PYZsh{} select all state variables but current one}
\PY{n}{U}\PY{p}{[}\PY{n}{i}\PY{p}{]} \PY{o}{=} \PY{n}{discipline}\PY{p}{(}\PY{n}{uk}\PY{p}{[}\PY{n}{mask}\PY{p}{]}\PY{p}{)} \PY{c+c1}{\PYZsh{} estimate coupling variables}
\PY{n}{drdU}\PY{p}{[}\PY{n}{i}\PY{p}{,}\PY{n}{mask}\PY{p}{]} \PY{o}{=} \PY{o}{\PYZhy{}}\PY{n}{Jacobian}\PY{p}{(}\PY{n}{uk}\PY{p}{[}\PY{n}{mask}\PY{p}{]}\PY{p}{)} \PY{c+c1}{\PYZsh{} estimate gradient of coupling variables}
\PY{n}{r} \PY{o}{=} \PY{n}{uk} \PY{o}{\PYZhy{}} \PY{n}{U} \PY{c+c1}{\PYZsh{} residuals}
\PY{k}{if} \PY{n}{np}\PY{o}{.}\PY{n}{linalg}\PY{o}{.}\PY{n}{norm}\PY{p}{(}\PY{n}{r}\PY{p}{)} \PY{o}{\PYZlt{}}\PY{o}{=} \PY{n}{e} \PY{o+ow}{or} \PY{n}{k} \PY{o}{\PYZgt{}} \PY{l+m+mi}{100}\PY{p}{:}
\PY{k}{break}
\PY{c+c1}{\PYZsh{} Newton\PYZhy{}Raphson step}
\PY{n}{du} \PY{o}{=} \PY{n}{np}\PY{o}{.}\PY{n}{linalg}\PY{o}{.}\PY{n}{inv}\PY{p}{(}\PY{n}{drdU}\PY{p}{)} \PY{o}{@} \PY{o}{\PYZhy{}}\PY{n}{r}
\PY{n}{uk} \PY{o}{=} \PY{n}{uk} \PY{o}{+} \PY{n}{du}
\PY{n}{k}\PY{o}{+}\PY{o}{=}\PY{l+m+mi}{1}
\PY{n+nb}{print}\PY{p}{(}\PY{n}{uk}\PY{p}{)}
\end{Verbatim}
\end{tcolorbox}
\begin{Verbatim}[commandchars=\\\{\}]
[3.02009699 2.00969799]
[0.96977098 2.55590709]
[1.07893819 2.91509142]
[1.07507004 2.93015913]
[1.07506292 2.93017725]
\end{Verbatim}
We found a solution for \(a\) and \(b\). You can plug those values into
your calculator and check that they satisfy the Equations in (4)
yourself!
However, we had to provide the Jacobian of the analysis functions
\(\dfrac{\partial\mathcal{U}}{\partial\hat{\mathbf{u}}}\) with respect
to the coupling variables
\(\hat{\mathbf{u}} = \begin{bmatrix} \hat{a} & \hat{b} \end{bmatrix}^\mathrm{T}\)
for the solver to converge. When \(\mathcal{U}_1\) and \(\mathcal{U}_2\)
are blackboxes (as in the aerostructural problem at the beginning of
this notebook), we seldom have access to residuals, let alone gradient
information! In other words, we sort of cheated.
\hypertarget{multidisciplinary-design-optimization}{%
\section{Multidisciplinary design
optimization}\label{multidisciplinary-design-optimization}}
Since the MDA seems to converge when using the reduced Newton solver, we
will use it to solve the optimization problem (1) at the beginning of
this notebook. Solving the optimization problem using an MDA is known as
Multidisciplinary feasible (MDF) approach.
\hypertarget{multidisciplinary-feasible-mdf-optimization}{%
\subsection{Multidisciplinary feasible (MDF)
optimization}\label{multidisciplinary-feasible-mdf-optimization}}
\begin{equation*}
\begin{aligned}
& \underset{u,v,w}{\text{minimize}}
& & f(u,v,w) = u+v+\hat{a}(u,v,w)+\hat{b}(u,v,w)\\
& \text{subject to}
& & g(u,v,w) = w + \hat{b}(u,v,w) -10 \leq 0\\
& & & 0 \leq u,v,w \leq 10\\
\end{aligned}
\tag{5}
\end{equation*}
The above optimization problem is called a Multi-disciplinary feasible
(MDF) MDO problem since it relies on a monolithic MDA. Note that we have
switched out \(a\) and \(b\) by their MDA counterparts \(\hat{a}\) and
\(\hat{b}\) which need to be solved for during every optimization loop!
We can use a blackbox optimization algorithm to solve the problem, where
the blackbox in this case is the MDA we developed in the previous
section. We define the blackbox below.
\begin{tcolorbox}[breakable, size=fbox, boxrule=1pt, pad at break*=1mm,colback=cellbackground, colframe=cellborder]
\prompt{In}{incolor}{5}{\boxspacing}
\begin{Verbatim}[commandchars=\\\{\}]
\PY{c+c1}{\PYZsh{} these are your coupled disciplines}
\PY{n}{U1} \PY{o}{=} \PY{k}{lambda} \PY{n}{x}\PY{p}{,}\PY{n}{uj}\PY{p}{:} \PY{n}{np}\PY{o}{.}\PY{n}{log}\PY{p}{(}\PY{n}{x}\PY{p}{[}\PY{l+m+mi}{0}\PY{p}{]}\PY{o}{+}\PY{l+m+mf}{1e\PYZhy{}6}\PY{p}{)} \PY{o}{+} \PY{n}{np}\PY{o}{.}\PY{n}{log}\PY{p}{(}\PY{n}{x}\PY{p}{[}\PY{l+m+mi}{1}\PY{p}{]}\PY{o}{+}\PY{l+m+mf}{1e\PYZhy{}6}\PY{p}{)} \PY{o}{+} \PY{n}{np}\PY{o}{.}\PY{n}{log}\PY{p}{(}\PY{n}{uj}\PY{p}{[}\PY{l+m+mi}{0}\PY{p}{]}\PY{o}{+}\PY{l+m+mf}{1e\PYZhy{}6}\PY{p}{)}
\PY{n}{U2} \PY{o}{=} \PY{k}{lambda} \PY{n}{x}\PY{p}{,}\PY{n}{uj}\PY{p}{:} \PY{l+m+mi}{1}\PY{o}{/}\PY{p}{(}\PY{n}{x}\PY{p}{[}\PY{l+m+mi}{0}\PY{p}{]}\PY{o}{+}\PY{l+m+mf}{1e\PYZhy{}6}\PY{p}{)} \PY{o}{+} \PY{l+m+mi}{1}\PY{o}{/}\PY{p}{(}\PY{n}{x}\PY{p}{[}\PY{l+m+mi}{2}\PY{p}{]}\PY{o}{+}\PY{l+m+mf}{1e\PYZhy{}6}\PY{p}{)} \PY{o}{+} \PY{l+m+mi}{1}\PY{o}{/}\PY{p}{(}\PY{n}{uj}\PY{p}{[}\PY{l+m+mi}{0}\PY{p}{]}\PY{o}{+}\PY{l+m+mf}{1e\PYZhy{}6}\PY{p}{)}
\PY{c+c1}{\PYZsh{} These are the Jacobians of your disciplines}
\PY{n}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\PY{n}{np}\PY{o}{.}\PY{n}{zeros\PYZus{}like}\PY{p}{(}\PY{n}{uk}\PY{p}{)}
\PY{n}{drdU} \PY{o}{=} \PY{n}{np}\PY{o}{.}\PY{n}{ones}\PY{p}{(}\PY{p}{(}\PY{n+nb}{len}\PY{p}{(}\PY{n}{uk}\PY{p}{)}\PY{p}{,}\PY{n+nb}{len}\PY{p}{(}\PY{n}{uk}\PY{p}{)}\PY{p}{)}\PY{p}{)}
\PY{k}{for} \PY{n}{i}\PY{p}{,}\PY{p}{(}\PY{n}{discipline}\PY{p}{,}\PY{n}{Jacobian}\PY{p}{)} \PY{o+ow}{in} \PY{n+nb}{enumerate}\PY{p}{(}\PY{n+nb}{zip}\PY{p}{(}\PY{n}{disciplines}\PY{p}{,}\PY{n}{Jacobians}\PY{p}{)}\PY{p}{)}\PY{p}{:}
\PY{n}{mask} \PY{o}{=} \PY{p}{[}\PY{k+kc}{True}\PY{p}{,}\PY{p}{]}\PY{o}{*}\PY{n+nb}{len}\PY{p}{(}\PY{n}{disciplines}\PY{p}{)}
\PY{n}{mask}\PY{p}{[}\PY{n}{i}\PY{p}{]} \PY{o}{=} \PY{k+kc}{False} \PY{c+c1}{\PYZsh{} select all state variables but current one}
\PY{n}{U}\PY{p}{[}\PY{n}{i}\PY{p}{]} \PY{o}{=} \PY{n}{discipline}\PY{p}{(}\PY{n}{x}\PY{p}{,}\PY{n}{uk}\PY{p}{[}\PY{n}{mask}\PY{p}{]}\PY{p}{)} \PY{c+c1}{\PYZsh{} estimate coupling variables}
\PY{n}{drdU}\PY{p}{[}\PY{n}{i}\PY{p}{,}\PY{n}{mask}\PY{p}{]} \PY{o}{=} \PY{o}{\PYZhy{}}\PY{n}{Jacobian}\PY{p}{(}\PY{n}{x}\PY{p}{,}\PY{n}{uk}\PY{p}{[}\PY{n}{mask}\PY{p}{]}\PY{p}{)} \PY{c+c1}{\PYZsh{} estimate gradient of coupling variables}
\PY{n}{r} \PY{o}{=} \PY{n}{uk} \PY{o}{\PYZhy{}} \PY{n}{U} \PY{c+c1}{\PYZsh{} residuals}
\PY{k}{if} \PY{n}{np}\PY{o}{.}\PY{n}{linalg}\PY{o}{.}\PY{n}{norm}\PY{p}{(}\PY{n}{r}\PY{p}{)} \PY{o}{\PYZlt{}}\PY{o}{=} \PY{n}{epsilon} \PY{o+ow}{or} \PY{n}{k} \PY{o}{\PYZgt{}} \PY{n}{k\PYZus{}max}\PY{p}{:}
\PY{k}{break}
\PY{c+c1}{\PYZsh{} Newton\PYZhy{}Raphson step}
\PY{n}{du} \PY{o}{=} \PY{n}{np}\PY{o}{.}\PY{n}{linalg}\PY{o}{.}\PY{n}{inv}\PY{p}{(}\PY{n}{drdU}\PY{p}{)} \PY{o}{@} \PY{o}{\PYZhy{}}\PY{n}{r}
\PY{n}{uk} \PY{o}{=} \PY{n}{uk} \PY{o}{+} \PY{n}{du}
\PY{n}{k}\PY{o}{+}\PY{o}{=}\PY{l+m+mi}{1}
\PY{k}{return} \PY{n}{uk}
\PY{n}{u} \PY{o}{=} \PY{l+m+mf}{0.0}
\PY{n}{v} \PY{o}{=} \PY{l+m+mf}{0.0}
\PY{n}{w} \PY{o}{=} \PY{l+m+mf}{0.0}
\PY{n}{x} \PY{o}{=} \PY{p}{[}\PY{n}{u}\PY{p}{,}\PY{n}{v}\PY{p}{,}\PY{n}{w}\PY{p}{]}
\PY{n}{state0}\PY{o}{=}\PY{n}{np}\PY{o}{.}\PY{n}{array}\PY{p}{(}\PY{p}{[}\PY{l+m+mi}{100}\PY{p}{,}\PY{l+m+mi}{100}\PY{p}{]}\PY{p}{)}
\PY{n}{disciplines} \PY{o}{=} \PY{p}{[}\PY{n}{U1}\PY{p}{,}\PY{n}{U2}\PY{p}{]}
\PY{n}{Jacobians} \PY{o}{=} \PY{p}{[}\PY{n}{dU1}\PY{p}{,}\PY{n}{dU2}\PY{p}{]}
\PY{n}{u\PYZus{}hat} \PY{o}{=} \PY{n}{my\PYZus{}MDA}\PY{p}{(}\PY{n}{x}\PY{p}{,}\PY{n}{state0}\PY{p}{,}\PY{n}{disciplines}\PY{p}{,}\PY{n}{Jacobians}\PY{p}{)}
\PY{n+nb}{print}\PY{p}{(}\PY{n}{u\PYZus{}hat}\PY{p}{)}
\end{Verbatim}
\end{tcolorbox}
\begin{Verbatim}[commandchars=\\\{\}]
[-1.31223634e+01 1.99999992e+06]
\end{Verbatim}
A blackbox that returns the objective and constraint value can now be
defined as follows:
\begin{tcolorbox}[breakable, size=fbox, boxrule=1pt, pad at break*=1mm,colback=cellbackground, colframe=cellborder]
\prompt{In}{incolor}{6}{\boxspacing}
\begin{Verbatim}[commandchars=\\\{\}]
\PY{k}{def} \PY{n+nf}{my\PYZus{}bb}\PY{p}{(}\PY{n}{x}\PY{p}{,}\PY{n}{args}\PY{p}{)}\PY{p}{:}
\PY{n}{state0} \PY{o}{=} \PY{n}{args}\PY{p}{[}\PY{l+m+mi}{0}\PY{p}{]}
\PY{n}{disciplines} \PY{o}{=} \PY{n}{args}\PY{p}{[}\PY{l+m+mi}{1}\PY{p}{]}
\PY{n}{Jacobians} \PY{o}{=} \PY{n}{args}\PY{p}{[}\PY{l+m+mi}{2}\PY{p}{]}
\PY{n}{u\PYZus{}hat} \PY{o}{=} \PY{n}{my\PYZus{}MDA}\PY{p}{(}\PY{n}{x}\PY{p}{,}\PY{n}{state0}\PY{p}{,}\PY{n}{disciplines}\PY{p}{,}\PY{n}{Jacobians}\PY{p}{)}
\PY{n}{f} \PY{o}{=} \PY{n}{x}\PY{p}{[}\PY{l+m+mi}{0}\PY{p}{]} \PY{o}{+} \PY{n}{x}\PY{p}{[}\PY{l+m+mi}{1}\PY{p}{]} \PY{o}{+} \PY{n}{u\PYZus{}hat}\PY{p}{[}\PY{l+m+mi}{0}\PY{p}{]} \PY{o}{+} \PY{n}{u\PYZus{}hat}\PY{p}{[}\PY{l+m+mi}{1}\PY{p}{]}
\PY{n}{g} \PY{o}{=} \PY{n}{x}\PY{p}{[}\PY{l+m+mi}{2}\PY{p}{]} \PY{o}{+} \PY{n}{u\PYZus{}hat}\PY{p}{[}\PY{l+m+mi}{1}\PY{p}{]} \PY{o}{\PYZhy{}} \PY{l+m+mf}{10.0}
\PY{k}{return} \PY{p}{[}\PY{n}{f}\PY{p}{,}\PY{p}{[}\PY{n}{g}\PY{p}{,}\PY{o}{\PYZhy{}}\PY{n}{u\PYZus{}hat}\PY{p}{[}\PY{l+m+mi}{0}\PY{p}{]}\PY{p}{,}\PY{o}{\PYZhy{}}\PY{n}{u\PYZus{}hat}\PY{p}{[}\PY{l+m+mi}{1}\PY{p}{]}\PY{p}{]}\PY{p}{]}
\end{Verbatim}
\end{tcolorbox}
The blackbox above is what we can feed to
\href{https://ahmed-bayoumy.github.io/OMADS/}{\texttt{OMADS}}.
\begin{tcolorbox}[breakable, size=fbox, boxrule=1pt, pad at break*=1mm,colback=cellbackground, colframe=cellborder]
\prompt{In}{incolor}{7}{\boxspacing}
\begin{Verbatim}[commandchars=\\\{\}]
\PY{k+kn}{import} \PY{n+nn}{OMADS}
\PY{c+c1}{\PYZsh{} Optimization setup}
\PY{n}{u0} \PY{o}{=} \PY{l+m+mf}{1.0}\PY{p}{;} \PY{n}{v0} \PY{o}{=} \PY{l+m+mf}{1.0}\PY{p}{;} \PY{n}{w0} \PY{o}{=} \PY{l+m+mf}{1.0}
\PY{n}{x0} \PY{o}{=} \PY{p}{[}\PY{n}{u0}\PY{p}{,}\PY{n}{v0}\PY{p}{,}\PY{n}{w0}\PY{p}{]}
\PY{n}{f}\PY{p}{,}\PY{n}{g} \PY{o}{=} \PY{n}{my\PYZus{}bb}\PY{p}{(}\PY{n}{x0}\PY{p}{,}\PY{n}{args}\PY{o}{=}\PY{p}{[}\PY{n}{state0}\PY{p}{,}\PY{n}{disciplines}\PY{p}{,}\PY{n}{Jacobians}\PY{p}{]}\PY{p}{)} \PY{c+c1}{\PYZsh{} its a good idea to test the blackbox function first at the initial guess}
\PY{n}{lb} \PY{o}{=} \PY{p}{[}\PY{l+m+mf}{0.0}\PY{p}{,} \PY{l+m+mf}{0.0}\PY{p}{,} \PY{l+m+mf}{0.0}\PY{p}{]}
\PY{n}{ub} \PY{o}{=} \PY{p}{[}\PY{l+m+mf}{10.}\PY{p}{,} \PY{l+m+mf}{10.}\PY{p}{,} \PY{l+m+mf}{10.}\PY{p}{]}
\PY{n+nb}{eval} \PY{o}{=} \PY{p}{\PYZob{}}\PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{blackbox}\PY{l+s+s2}{\PYZdq{}}\PY{p}{:} \PY{n}{my\PYZus{}bb}\PY{p}{,}
\PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{constants}\PY{l+s+s2}{\PYZdq{}}\PY{p}{:} \PY{p}{[}\PY{n}{state0}\PY{p}{,}\PY{n}{disciplines}\PY{p}{,}\PY{n}{Jacobians}\PY{p}{]}\PY{p}{\PYZcb{}} \PY{c+c1}{\PYZsh{} you can pass blackbox specific options using the ``constants`` key}
\PY{n}{param} \PY{o}{=} \PY{p}{\PYZob{}}\PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{baseline}\PY{l+s+s2}{\PYZdq{}}\PY{p}{:} \PY{n}{x0}\PY{p}{,}
\PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{lb}\PY{l+s+s2}{\PYZdq{}}\PY{p}{:} \PY{n}{lb}\PY{p}{,}
\PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{ub}\PY{l+s+s2}{\PYZdq{}}\PY{p}{:} \PY{n}{ub}\PY{p}{,}
\PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{var\PYZus{}names}\PY{l+s+s2}{\PYZdq{}}\PY{p}{:} \PY{p}{[}\PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{u}\PY{l+s+s2}{\PYZdq{}}\PY{p}{,} \PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{v}\PY{l+s+s2}{\PYZdq{}}\PY{p}{,} \PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{w}\PY{l+s+s2}{\PYZdq{}}\PY{p}{]}\PY{p}{,}
\PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{scaling}\PY{l+s+s2}{\PYZdq{}}\PY{p}{:} \PY{l+m+mf}{10.0}\PY{p}{,}
\PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{post\PYZus{}dir}\PY{l+s+s2}{\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{./post}\PY{l+s+s2}{\PYZdq{}}\PY{p}{\PYZcb{}} \PY{c+c1}{\PYZsh{} these are OMADS specific options. You can modify them as necessary}
\PY{n}{options} \PY{o}{=} \PY{p}{\PYZob{}}\PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{seed}\PY{l+s+s2}{\PYZdq{}}\PY{p}{:} \PY{l+m+mi}{0}\PY{p}{,} \PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{budget}\PY{l+s+s2}{\PYZdq{}}\PY{p}{:} \PY{l+m+mi}{100000}\PY{p}{,} \PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{tol}\PY{l+s+s2}{\PYZdq{}}\PY{p}{:} \PY{l+m+mf}{1e\PYZhy{}12}\PY{p}{,} \PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{display}\PY{l+s+s2}{\PYZdq{}}\PY{p}{:} \PY{k+kc}{False}\PY{p}{\PYZcb{}}
\PY{n}{data} \PY{o}{=} \PY{p}{\PYZob{}}\PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{evaluator}\PY{l+s+s2}{\PYZdq{}}\PY{p}{:} \PY{n+nb}{eval}\PY{p}{,} \PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{param}\PY{l+s+s2}{\PYZdq{}}\PY{p}{:} \PY{n}{param}\PY{p}{,} \PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{options}\PY{l+s+s2}{\PYZdq{}}\PY{p}{:}\PY{n}{options}\PY{p}{\PYZcb{}}
\PY{n}{out} \PY{o}{=} \PY{p}{\PYZob{}}\PY{p}{\PYZcb{}}
\PY{c+c1}{\PYZsh{} out is a dictionary that will hold output data of the final solution. The out dictionary has three keys: \PYZdq{}xmin\PYZdq{}, \PYZdq{}fmin\PYZdq{} and \PYZdq{}hmin\PYZdq{}}
\PY{n}{out} \PY{o}{=} \PY{n}{OMADS}\PY{o}{.}\PY{n}{main}\PY{p}{(}\PY{n}{data}\PY{p}{)}
\PY{n}{fopt}\PY{p}{,}\PY{n}{gopt} \PY{o}{=} \PY{n}{my\PYZus{}bb}\PY{p}{(}\PY{n}{out}\PY{p}{[}\PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{xmin}\PY{l+s+s2}{\PYZdq{}}\PY{p}{]}\PY{p}{,}\PY{n}{args}\PY{o}{=}\PY{p}{[}\PY{n}{state0}\PY{p}{,}\PY{n}{disciplines}\PY{p}{,}\PY{n}{Jacobians}\PY{p}{]}\PY{p}{)} \PY{c+c1}{\PYZsh{} evaluate blackbox at optimizer}
\PY{n}{uopt} \PY{o}{=} \PY{n}{my\PYZus{}MDA}\PY{p}{(}\PY{n}{out}\PY{p}{[}\PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{xmin}\PY{l+s+s2}{\PYZdq{}}\PY{p}{]}\PY{p}{,}\PY{n}{state0}\PY{p}{,}\PY{n}{disciplines}\PY{p}{,}\PY{n}{Jacobians}\PY{p}{)} \PY{c+c1}{\PYZsh{} evaluate MDA at optimizer}
\PY{k+kn}{import} \PY{n+nn}{json}
\PY{k}{for} \PY{n}{key}\PY{p}{,}\PY{n}{value} \PY{o+ow}{in} \PY{n}{out}\PY{o}{.}\PY{n}{items}\PY{p}{(}\PY{p}{)}\PY{p}{:}
\PY{n+nb}{print}\PY{p}{(}\PY{n}{key}\PY{p}{,}\PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{ : }\PY{l+s+s2}{\PYZdq{}}\PY{p}{,}\PY{n}{value}\PY{p}{)}
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\PYZob{}}\PY{l+s+s2}{\PYZbs{}}\PY{l+s+s2}{mathbf}\PY{l+s+si}{\PYZob{}u\PYZcb{}}\PY{l+s+s2}{\PYZcb{}(}\PY{l+s+s2}{\PYZbs{}}\PY{l+s+s2}{mathbf}\PY{l+s+si}{\PYZob{}x\PYZcb{}}\PY{l+s+s2}{\PYZca{}*)\PYZdl{} = \PYZdl{}[}\PY{l+s+si}{\PYZpc{}.4f}\PY{l+s+s2}{\PYZti{}\PYZti{}}\PY{l+s+si}{\PYZpc{}.4f}\PY{l+s+s2}{]\PYZca{}}\PY{l+s+s2}{\PYZbs{}}\PY{l+s+s2}{mathrm}\PY{l+s+si}{\PYZob{}T\PYZcb{}}\PY{l+s+s2}{\PYZdl{}}\PY{l+s+s2}{\PYZdq{}} \PY{o}{\PYZpc{}}\PY{p}{(}\PY{n}{uopt}\PY{p}{[}\PY{l+m+mi}{0}\PY{p}{]}\PY{p}{,}\PY{n}{uopt}\PY{p}{[}\PY{l+m+mi}{1}\PY{p}{]}\PY{p}{)}
\PY{n}{display}\PY{p}{(}\PY{n}{Latex}\PY{p}{(}\PY{n}{u\PYZus{}tex}\PY{p}{)}\PY{p}{)} \PY{c+c1}{\PYZsh{} constraints}
\PY{c+c1}{\PYZsh{} print(f\PYZus{}tex)}
\PY{c+c1}{\PYZsh{} print(x\PYZus{}tex)}
\PY{c+c1}{\PYZsh{} print(g\PYZus{}tex)}
\PY{c+c1}{\PYZsh{} print(u\PYZus{}tex)}
\end{Verbatim}
\end{tcolorbox}
\begin{Verbatim}[commandchars=\\\{\}]
xmin : [1.1874999999927240424, 0.74511669576168060303, 7.6562655009329319]
fmin : 5.005735228721652552
hmin : 9.996378214847634363e-19
nbb\_evals : 469
niterations : 78
nb\_success : 27
psize : 9.094947017729282379e-13
psuccess : 7.2759576141834259033e-12
pmax : 2.0
===========================
\end{Verbatim}
$f(\mathbf{x}^*) = 5.0057$
$\mathbf{x}^*$ = $[1.1875~~0.7451~~7.6563]^\mathrm{T}$
$g(\mathbf{x}^*)$ = $0.0000$