-
Notifications
You must be signed in to change notification settings - Fork 24
/
html_layout.py
1067 lines (919 loc) · 41.8 KB
/
html_layout.py
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
import dash
from dash import dcc
from dash import html
# import dash_bootstrap_components as dbc # TODO use when the bug with dash==2.4.0 is resolved: https://github.com/plotly/dash/issues/2064
from dash.dependencies import Input, Output, State, ClientsideFunction
import plotly.graph_objects as go
import os
def loading_wrapper(component):
return html.P(dcc.Loading(component, type='circle', color='#96BA6E'))
blank_figure = {
"layout": {
"xaxis": {
"visible": False
},
"yaxis": {
"visible": False
},
"plot_bgcolor": "#f9f9f9",
"paper_bgcolor": "#f9f9f9",
"annotations": [
{
"text": "",
"xref": "paper",
"yref": "paper",
"showarrow": False,
"font": {
"size": 28
}
}
]
}
}
def create_appLayout(
yesNo_options,
image_dir,
mapCI,
appVersions_options
):
appLayout = html.Div(
[
dcc.Store(id="versioned_data"),
dcc.Store(id="aggregate_data"),
dcc.Location(id='url_content', refresh='callback-nav'), # TODO issue https://github.com/plotly/dash/issues/1346 should be fixed in later releases
#### POP UP FOR URL + INVALID INPUTS ####
dcc.ConfirmDialog(
id='fillIn_from_url',
message='Filling in values from the URL. To edit, click reset.',
),
#### HEADER ####
html.Div(
[
html.H1("Green Algorithms"),
html.P("How green are your computations?"),
],
className='container header'
),
html.Div(
[
html.Center(
html.P([
"Check out the new ",
html.B("Green Algorithms website"),
": ",
html.A("www.green-algorithms.org",
href='https://www.green-algorithms.org',
target='_blank')
]),
),
],
className='container footer permalink preprint'
),
#### INPUT FORM ####
html.Form(
[
html.H2(
"Details about your algorithm"
),
html.Center(
html.P(["To understand how each parameter impacts your carbon footprint, "
"check out the formula below and the ",
html.A("methods article",
href='https://onlinelibrary.wiley.com/doi/10.1002/advs.202100707',
target='_blank')
]),
),
## RUN TIME
html.Div(
[
html.Label("Runtime (HH:MM)"),
html.Div(
[
dcc.Input(
type='number',
id="runTime_hour_input",
min=0,
),
dcc.Input(
type='number',
id="runTime_min_input",
min=0,
max=59,
)
],
className="box-runtime box-fields"
),
],
className='form-row short-input'
),
html.Div(
[
html.Hr(),
],
className='Hr_div'
),
## TYPE OF CORES
html.Div(
[
html.Label("Type of cores"),
html.Div(
[
dcc.Dropdown(
id="coreType_dropdown",
clearable=False,
),
],
className="box-fields"
)
],
className='form-row short-input'
),
## CPUs
html.Div(
[
html.H3(
"CPUs",
id='title_CPU'
),
html.Div(
[
html.Label("Number of cores"),
dcc.Input(
type='number',
id="numberCPUs_input",
min=0,
),
],
className='form-row short-input'
),
html.Div(
[
html.Label("Model"),
html.Div(
[
dcc.Dropdown(
id="CPUmodel_dropdown",
className='bottom-dropdown',
clearable=False,
),
],
className="box-fields"
)
],
className='form-row short-input'
),
# CPU TDP
html.Div(
[
html.Label(
'What is the Thermal Design Power (TDP) value per core of your CPU? '
'This can easily be found online (usually 10-15W per core)'),
dcc.Input(
type='number',
id="tdpCPU_input",
min=0,
)
],
className='form-row',
id='tdpCPU_div',
style=dict(display='none')
),
],
className="group-of-rows",
id="CPU_div"
),
## GPUs
html.Div(
[
html.H3(
"GPUs",
id='title_GPU'
),
html.Div(
[
html.Label("Number of GPUs"),
dcc.Input(
type='number',
id="numberGPUs_input",
min=0,
),
],
className='form-row short-input'
),
html.Div(
[
html.Label("Model"),
html.Div(
[
dcc.Dropdown(
id="GPUmodel_dropdown",
className='bottom-dropdown',
clearable=False,
),
],
className="box-fields"
)
],
className='form-row short-input'
),
# GPU TDP
html.Div(
[
html.Label(
'What is the Thermal Design Power (TDP) value per core of your GPU? '
'This can easily be found online (usually around 200W)'),
dcc.Input(
type='number',
id="tdpGPU_input",
min=0,
)
],
className='form-row',
id='tdpGPU_div',
style=dict(display='none')
),
],
className="group-of-rows",
id="GPU_div"
),
html.Div(
[
html.Hr(),
],
className='Hr_div'
),
## MEMORY
html.Div(
[
html.Label("Memory available (in GB)"),
dcc.Input(
type='number',
id="memory_input",
min=0,
),
],
className='form-row short-input',
id='div_memory'
),
html.Div(
[
html.Hr(),
],
className='Hr_div'
),
## SELECT COMPUTING PLATFORM
html.Div(
[
html.Label("Select the platform used for the computations"),
html.Div(
[
dcc.Dropdown(
id="platformType_dropdown",
clearable=False,
),
html.Div(
[
dcc.Dropdown(
id="provider_dropdown",
clearable=False,
className='bottom-dropdown'
)
],
id="provider_dropdown_div"
)
],
className="box-fields"
)
],
className='form-row'
),
## SERVER (for cloud computing)
html.Div(
[
html.Label("Select server"),
html.Div(
[
dcc.Dropdown(
id="server_continent_dropdown",
clearable=False,
),
dcc.Dropdown(
id="server_dropdown",
className='bottom-dropdown',
clearable=False,
),
],
className="box-fields"
)
],
id='server_div',
className='form-row',
style={'display': 'none'}
),
## LOCATION
html.Div(
[
html.Label("Select location"),
html.Div(
[
dcc.Dropdown(
id="location_continent_dropdown",
clearable=False,
),
html.Div(
[
dcc.Dropdown(
id="location_country_dropdown",
className='bottom-dropdown',
clearable=False,
),
],
id="location_country_dropdown_div"
),
html.Div(
[
dcc.Dropdown(
id="location_region_dropdown",
className='bottom-dropdown',
clearable=False,
),
],
id="location_region_dropdown_div"
),
],
className="box-fields"
)
],
id='location_div',
className='form-row',
style={'display': 'flex'}
),
## Core usage (CPU and GPU)
html.Div(
[
html.Label("Do you know the real usage factor of your CPU?"),
dcc.RadioItems(
id='usageCPU_radio',
options=yesNo_options,
className="radio-input",
),
dcc.Input(
min=0,
max=1,
# step=0.1,
type='number',
id="usageCPU_input",
style=dict(display='none'),
),
],
className='form-row radio-and-field',
id='usageCPU_div'
),
html.Div(
[
html.Label("Do you know the real usage factor of your GPU?"),
dcc.RadioItems(
id='usageGPU_radio',
options=yesNo_options,
className="radio-input"
# labelStyle={"display": "inline-block"},
),
dcc.Input(
min=0,
max=1,
# step=0.1,
type='number',
id="usageGPU_input",
style=dict(display='none'),
),
],
className='form-row radio-and-field',
id='usageGPU_div'
),
## PUE
html.Div(
[
html.Label("Do you know the Power Usage Efficiency (PUE) of your local data centre?"),
dcc.RadioItems(
id='pue_radio',
options=yesNo_options,
className="radio-input"
# labelStyle={"display": "inline-block"},
),
dcc.Input(
min=1,
type='number',
id="PUE_input",
style=dict(display='none'),
),
],
className='form-row radio-and-field',
id='PUEquestion_div',
style=dict(display='none'),
),
## PSF
html.Div(
[
html.Label("Do you want to use a Pragmatic Scaling Factor?"),
dcc.RadioItems(
id='PSF_radio',
options=yesNo_options,
className="radio-input"
),
dcc.Input(
min=1,
type='number',
id="PSF_input",
style=dict(display='none'),
),
],
className='form-row radio-and-field',
),
dcc.ConfirmDialog(
id='confirm_reset',
message='This will reset all the values you have entered so far! Are you sure you want to continue?',
),
html.Div(
[
html.Div(
[
html.P("Reset", id='reset_link'),
],
className='reset-button'
),
html.Div(
[
html.P("Change app version", id='oldVersion_link'),
],
className='reset-button'
),
],
className='two-buttons'
),
html.Div(
[
html.Label("App version"),
html.Div(
[
dcc.Dropdown(
id="appVersions_dropdown",
options=appVersions_options,
className='bottom-dropdown',
clearable=False,
),
],
className="box-fields"
)
],
className='form-row short-input',
id='oldVersions_div',
style=dict(display='none'),
),
html.P(
id="placeholder",
style={"display": "none"}
)
],
className='container input-form'
),
#### FIRST OUTPUTS ####
html.Div(
[
html.Div(
[
html.Div(
[
html.Img(
src=os.path.join(image_dir, 'logo_co2.svg'),
id="logo_co2",
className="style-icon",
style={
'margin-top': '-7px',
'margin-bottom': '7px'
},
),
html.Div(
[
loading_wrapper(html.Div(
id="carbonEmissions_text",
)),
html.P(
"Carbon footprint",
)
],
className='caption-icons'
)
],
className="container mini-box"
),
html.Div(
[
html.Img(
src=os.path.join(image_dir, 'logo_power_1.svg'),
id="logo_power",
className="style-icon",
style={
'margin': '0px',
'padding': '15px'
},
),
html.Div(
[
loading_wrapper(html.Div(
id="energy_text",
)),
html.P(
"Energy needed",
)
],
className='caption-icons'
)
],
className="container mini-box"
),
html.Div(
[
html.Img(
src=os.path.join(image_dir, 'logo_tree_1.svg'),
id="logo_tree",
className="style-icon",
style={
'padding': '15px'
},
),
html.Div(
[
loading_wrapper(html.Div(
id="treeMonths_text",
)),
html.P(
"Carbon sequestration"
)
],
className='caption-icons'
)
],
className="container mini-box"
),
html.Div(
[
html.Img(
src=os.path.join(image_dir, 'logo_car_3.svg'),
id="logo_car",
className="style-icon",
style={
'padding': '13px'
},
),
html.Div(
[
loading_wrapper(html.Div(
id="driving_text",
)),
html.P(
"in a passenger car",
)
],
className='caption-icons'
)
],
className="container mini-box"
),
html.Div(
[
html.Img(
src=os.path.join(image_dir, 'logo_plane_1.svg'),
id="logo_plane",
className="style-icon",
style={
'padding': '4px'
},
),
html.Div(
[
loading_wrapper(html.Div(
id="flying_text",
)),
html.P(
id="flying_label",
),
],
className='caption-icons'
)
],
className="container mini-box"
),
html.Div(
[
html.P([
html.B("Share your results "),
"with ",
html.A("this link", target='_blank', id='share_permalink'),
"!"
]),
],
className='container footer permalink'
),
],
className='super-section mini-boxes'
),
html.Div(
[
html.Div(
[
html.H2(
"Computing cores VS Memory"
),
loading_wrapper(
dcc.Graph(
id="pie_graph",
className='graph-container pie-graph',
config={'displaylogo': False},
figure=blank_figure,
)
),
],
className='one-of-two-graphs'
),
html.Div(
[
html.H2(
"How the location impacts your footprint"
),
loading_wrapper(
dcc.Graph(
id="barPlotComparison",
className='graph-container',
config={'displaylogo': False},
figure=blank_figure,
style={
'margin-top': '20px'
}
),
),
],
className='one-of-two-graphs'
)
],
className="container two-graphs-box"
),
],
className='super-section first-output'
),
#### PUBLICATION ####
html.Div(
[
html.Center(
html.P(["More details about the methodology in the ",
html.A("methods paper",
href='https://onlinelibrary.wiley.com/doi/10.1002/advs.202100707',
target='_blank'),
"."
]),
),
],
className='container footer preprint'
),
#### MAP ####
html.Div(
[
html.H2("Carbon Intensity across the world"),
html.Div(
[
loading_wrapper(
dcc.Graph(
figure=mapCI,
className='graph',
config={'displaylogo': False},
),
),
],
className='graph-container'
)
],
className="container maps",
),
#### DEFINITIONS ####
html.Div(
[
html.Div(
[
html.H2("About CO2e"),
dcc.Markdown('''
"Carbon dioxide equivalent" (CO2e) measures
the global warming potential of a mixture of greenhouse gases.
__It represents the quantity of CO2 that would have
the same impact on global warming__ as the mix of interest
and is used as a standardised unit to assess
the environmental impact of human activities.
''')
],
className='container'
),
html.Div(
[
html.H2("What is a tree-month?"),
dcc.Markdown('''
It's the amount of CO2 sequestered by a tree in a month.
__We use it to measure how long it would take to a mature tree
to absorb the CO2 emitted by an algorithm.__
We use the value of 11 kg CO2/year, which is roughly 1kg CO2/month.
'''),
],
className='container'
),
],
className='super-section definitions'
),
#### CORES COMPARISON ####
html.Div(
[
html.H2("Power draw of different processors"),
html.Div(
[
loading_wrapper(
dcc.Graph(
id="barPlotComparison_cores",
config={'displaylogo': False},
figure=blank_figure,
),
),
],
className='graph-container'
)
],
className='container core-comparison'
),
#### WHAT TO DO ####
html.Div(
[
html.H2("What can you do about it?"),
dcc.Markdown('''
The main factor impacting your footprint is the location of your servers:
the same algorithm will emit __74 times more__ CO2e
if ran in Australia compared to Switzerland.
Although it's not always the case,
many cloud providers offer the option to select a data centre.
Memory power draw is a huge source of waste,
because __the energy consumption depends on the memory available,
not the actual usage__, only requesting the needed memory
is a painless way to reduce greenhouse gas emissions.
Generally, taking the time to write optimised code that runs faster with fewer
resources saves both money and the planet.
And above all, __only run jobs that you need!__
''')
],
className='container to-do'
),
#### FORMULA ####
html.Div(
[
html.H2("The formula"),
dcc.Markdown('''
The carbon footprint is calculated by estimating the energy draw of the algorithm
and the carbon intensity of producing this energy at a given location:
`carbon footprint = energy needed * carbon intensity`
Where the energy needed is:
`runtime * (power draw for cores * usage + power draw for memory) * PUE * PSF`
The power draw for the computing cores depends on the model and number of cores,
while the memory power draw only depends on the size of memory available.
The usage factor corrects for the real core usage (default is 1, i.e. full usage).
The PUE (Power Usage Effectiveness) measures how much extra energy is needed
to operate the data centre (cooling, lighting etc.).
The PSF (Pragmatic Scaling Factor) is used to take into account multiple identical runs
(e.g. for testing or optimisation).
The Carbon Intensity depends on the location and the technologies used to produce electricity.
But note that __the "energy needed" indicated at the top of this page is independent of the location.__
''')
],
className='container formula'
),
#### HOW TO REPORT ####
html.Div(
[
html.H2("How to report it?"),
dcc.Markdown('''
It's important to track the impact
of computational research on climate change in order to stimulate greener algorithms.
For that, __we believe that the carbon footprint of a project should be reported on publications
alongside other performance metrics__.
Here is a text you can include in your paper:
'''),
dcc.Markdown(id='report_markdown'),
dcc.Markdown(
# '\[1\] see citation below',
'\[1\] Lannelongue, L., Grealey, J., Inouye, M., Green Algorithms: Quantifying the Carbon Footprint of Computation. Adv. Sci. 2021, 2100707.',
className='footnote citation-report'
),
dcc.Markdown(
'_Including the version of the tool is useful to keep track of the version of the data used._',
className='footnote-authorship'
)
],
className='container report'
),
#### DATA AND Q ####
html.Div(
[
html.Div(
[
html.H2("Data and code"),
html.Center(
html.P(["All the data and code used to run this calculator can be found on ",
html.A("GitHub",
href='https://github.com/GreenAlgorithms/green-algorithms-tool',
target='_blank')
]),
),
],
className='container footer'
),
html.Div(
[
html.H2('Questions / Suggestions?'),
html.Center(
html.P(["If you have questions or suggestions about the tool, you can ",
html.A("open an issue",
href='https://github.com/GreenAlgorithms/green-algorithms-tool/issues',
target='_blank'),
" on the GitHub or ",
html.A("email us",
href='mailto:[email protected]', ),
]),
),
],
className='container footer'
)
],
className='super-section data-questions'
),
#### ABOUT US ####
html.Div(
[
html.H2("About us"),
dcc.Markdown('''
The Green Algorithms project was jointly developed by
Loïc Lannelongue\*¹, Jason Grealey\*², and Michael Inouye³
''',
className='authors'
),
dcc.Markdown('''
(1) University of Cambridge
(2) Baker Heart and Diabetes Institute and La Trobe University