Skip to content

Commit c01bbde

Browse files
authored
Merge pull request #89 from skrakau/report_params
Report nf-co2footprint parameters
2 parents 172c7bf + a43f35a commit c01bbde

File tree

4 files changed

+132
-30
lines changed

4 files changed

+132
-30
lines changed

plugins/nf-co2footprint/src/main/nextflow/co2footprint/CO2FootprintConfig.groovy

+68-25
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,16 @@ import groovy.util.logging.Slf4j
2727
@PackageScope
2828
class CO2FootprintConfig {
2929

30-
final private String traceFile
31-
final private String summaryFile
32-
final private String reportFile
33-
final private String location
34-
final private Double ci // CI: carbon intensity
35-
final private Double pue // PUE: power usage effectiveness efficiency, coefficient of the data centre
36-
final private Double powerdrawMem // Power draw of memory [W per GB]
37-
final private Boolean ignoreCpuModel
38-
final private Double powerdrawCpuDefault
30+
private String traceFile = CO2FootprintFactory.CO2FootprintTextFileObserver.DEF_TRACE_FILE_NAME
31+
private String summaryFile = CO2FootprintFactory.CO2FootprintTextFileObserver.DEF_SUMMARY_FILE_NAME
32+
private String reportFile = CO2FootprintFactory.CO2FootprintReportObserver.DEF_REPORT_FILE_NAME
33+
private String location = null
34+
private Double ci = 475 // CI: carbon intensity
35+
private Double pue = 1.67 // PUE: power usage effectiveness efficiency, coefficient of the data centre
36+
private Double powerdrawMem = 0.3725 // Power draw of memory [W per GB]
37+
private Boolean ignoreCpuModel = false
38+
private Double powerdrawCpuDefault = 12.0
39+
private String customCpuTdpFile = null
3940

4041
// Retrieve CI value from file containing CI values for different locations
4142
protected Double retrieveCi(String location) {
@@ -51,8 +52,9 @@ class CO2FootprintConfig {
5152
}
5253
}
5354
dataReader.close()
54-
if (localCi == 0.0)
55+
if (localCi == 0.0) {
5556
throw new IllegalArgumentException("Invalid 'location' parameter: $location. Could not be found in 'CI_aggregated.v2.2.csv'.")
57+
}
5658

5759
return localCi
5860
}
@@ -74,36 +76,77 @@ class CO2FootprintConfig {
7476

7577
CO2FootprintConfig(Map map, Map<String, Double> cpuData){
7678
def config = map ?: Collections.emptyMap()
77-
traceFile = config.traceFile ?: CO2FootprintFactory.CO2FootprintTextFileObserver.DEF_TRACE_FILE_NAME
78-
summaryFile = config.summaryFile ?: CO2FootprintFactory.CO2FootprintTextFileObserver.DEF_SUMMARY_FILE_NAME
79-
reportFile = config.reportFile ?: CO2FootprintFactory.CO2FootprintReportObserver.DEF_REPORT_FILE_NAME
80-
ignoreCpuModel = config.ignoreCpuModel ?: false
81-
82-
ci = 475
83-
if (config.ci && config.location)
79+
if (config.traceFile) {
80+
traceFile = config.traceFile
81+
}
82+
if (config.summaryFile) {
83+
summaryFile = config.summaryFile
84+
}
85+
if (config.reportFile) {
86+
reportFile = config.reportFile
87+
}
88+
if (config.ignoreCpuModel) {
89+
ignoreCpuModel = config.ignoreCpuModel
90+
}
91+
if (config.ci && config.location) {
8492
throw new IllegalArgumentException("Invalid combination of 'ci' and 'location' parameters specified for the CO2Footprint plugin. Please specify either 'ci' or 'location'!")
85-
if (config.ci)
93+
}
94+
if (config.ci) {
8695
ci = config.ci
96+
}
8797
if (config.location) {
8898
ci = retrieveCi(config.location)
8999
location = config.location
90100
}
91-
92-
pue = config.pue ?: 1.67
93-
powerdrawMem = config.powerdrawMem ?: 0.3725
94-
powerdrawCpuDefault = config.powerdrawCpuDefault ?: 12.0
101+
if (config.pue) {
102+
pue = config.pue
103+
}
104+
if (config.powerdrawMem) {
105+
powerdrawMem = config.powerdrawMem
106+
}
107+
if (config.powerdrawCpuDefault) {
108+
powerdrawCpuDefault = config.powerdrawCpuDefault
109+
}
95110
cpuData['default'] = powerdrawCpuDefault
96111

97-
if (config.customCpuTdpFile)
112+
if (config.customCpuTdpFile) {
113+
customCpuTdpFile = config.customCpuTdpFile
98114
loadCustomCpuTdpData(cpuData, config.customCpuTdpFile)
115+
}
99116
}
100117

101118
String getTraceFile() { traceFile }
102119
String getSummaryFile() { summaryFile }
103120
String getReportFile() { reportFile }
104121
Boolean getIgnoreCpuModel() { ignoreCpuModel }
105122
String getLocation() { location }
106-
Double getCI() { ci }
107-
Double getPUE() { pue }
123+
Double getCi() { ci }
124+
Double getPue() { pue }
108125
Double getPowerdrawMem() { powerdrawMem }
126+
Double getPowerdrawCpuDefault() { powerdrawCpuDefault }
127+
String getCustomCpuTdpFile() { customCpuTdpFile }
128+
129+
// Different functions to collect options for reporting, grouped by purpose
130+
SortedMap<String, Object> collectInputFileOptions() {
131+
Map<String, Object> newMap = [:]
132+
newMap["customCpuTdpFile"] = customCpuTdpFile
133+
return newMap.sort()
134+
}
135+
SortedMap<String, Object> collectOutputFileOptions() {
136+
Map<String, Object> newMap = [:]
137+
newMap["traceFile"] = traceFile
138+
newMap["summaryFile"] = summaryFile
139+
newMap["reportFile"] = reportFile
140+
return newMap.sort()
141+
}
142+
SortedMap<String, Object> collectCO2CalcOptions() {
143+
Map<String, Object> newMap = [:]
144+
newMap["location"] = location
145+
newMap["ci"] = ci // Might be indirectly determined for location parameter
146+
newMap["pue"] = pue
147+
newMap["powerdrawMem"] = powerdrawMem
148+
newMap["powerdrawCpuDefault"] = powerdrawCpuDefault
149+
newMap["ignoreCpuModel"] = ignoreCpuModel
150+
return newMap.sort()
151+
}
109152
}

plugins/nf-co2footprint/src/main/nextflow/co2footprint/CO2FootprintFactory.groovy

+32-3
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,9 @@ class CO2FootprintFactory implements TraceObserverFactory {
198198
* Remaining factors
199199
*/
200200
// PUE: efficiency coefficient of the data centre
201-
Double pue = config.getPUE()
201+
Double pue = config.getPue()
202202
// CI: carbon intensity [gCO2e kWh−1]
203-
def ci = config.getCI()
203+
def ci = config.getCi()
204204

205205
/**
206206
* Calculate energy consumption [kWh]
@@ -363,6 +363,11 @@ class CO2FootprintFactory implements TraceObserverFactory {
363363
co2eSummaryFile.println("Lannelongue, L., Grealey, J., Inouye, M., Green Algorithms: Quantifying the Carbon Footprint of Computation. Adv. Sci. 2021, 2100707. https://doi.org/10.1002/advs.202100707")
364364
co2eSummaryFile.println()
365365
co2eSummaryFile.println("nf-co2footprint plugin version: ${version}")
366+
co2eSummaryFile.println()
367+
co2eSummaryFile.println("nf-co2footprint options")
368+
config.collectInputFileOptions().each { co2eSummaryFile.println("${it.key}: ${it.value}") }
369+
config.collectOutputFileOptions().each { co2eSummaryFile.println("${it.key}: ${it.value}") }
370+
config.collectCO2CalcOptions().each { co2eSummaryFile.println("${it.key}: ${it.value}") }
366371
co2eSummaryFile.flush()
367372
co2eSummaryFile.close()
368373

@@ -737,6 +742,29 @@ class CO2FootprintFactory implements TraceObserverFactory {
737742
"{ \"trace\":${renderTasksJson()}, \"summary\":${renderSummaryJson()} }"
738743
}
739744

745+
/**
746+
* @return The options json payload
747+
*/
748+
protected String renderOptionsJson() {
749+
final all_options = config.collectInputFileOptions() + config.collectOutputFileOptions() + config.collectCO2CalcOptions()
750+
def result = new StringBuilder()
751+
result << "["
752+
def fields = all_options.keySet() as List
753+
754+
// Render JSON
755+
final QUOTE = '"'
756+
for( int i=0; i<fields.size(); i++ ) {
757+
if(i) result << ','
758+
String name = fields[i]
759+
String value = all_options[name].toString()
760+
result << "{" << QUOTE << "option" << QUOTE << ":" << QUOTE << name << QUOTE << ","
761+
result << QUOTE << "value" << QUOTE << ":" << QUOTE << value << QUOTE << "}"
762+
}
763+
result << "]"
764+
765+
return result.toString()
766+
}
767+
740768
/**
741769
* Render the total co2 footprint values for html report
742770
*
@@ -777,7 +805,8 @@ class CO2FootprintFactory implements TraceObserverFactory {
777805
readTemplate('nextflow/trace/assets/moment.min.js'),
778806
readTemplate('nextflow/trace/assets/plotly.min.js'),
779807
readTemplate('assets/CO2FootprintReportTemplate.js')
780-
]
808+
],
809+
options : renderOptionsJson()
781810
]
782811
//log.info "${tpl_fields['payload']}"
783812
final tpl = readTemplate('CO2FootprintReportTemplate.html')

plugins/nf-co2footprint/src/resources/CO2FootprintReportTemplate.html

+11
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,16 @@ <h2 id="tasks" style="padding-top: 80px;">Tasks</h2>
261261
</div>
262262
</div>
263263

264+
<div class="container">
265+
<div id="table-container">
266+
<h2 id="options" style="padding-top: 80px;">Options</h2>
267+
<p>This table shows the nf-co2footprint plugin options that were used to calculate the CO<sub>2</sub>e footprint measures.</p>
268+
</div>
269+
<div class="container-fluid">
270+
<table class="table small table-striped" id="options_table"></table>
271+
</div>
272+
</div>
273+
264274
<footer>
265275
<div class="container-fluid">
266276
Generated by <a href="https://www.nextflow.io" target="_blank">Nextflow</a>, version ${workflow.nextflow.version}
@@ -272,6 +282,7 @@ <h2 id="tasks" style="padding-top: 80px;">Tasks</h2>
272282

273283
// Nextflow report data
274284
window.data = $payload;
285+
window.options = $options;
275286

276287
</script>
277288

plugins/nf-co2footprint/src/resources/assets/CO2FootprintReportTemplate.js

+21-2
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ $(function() {
300300

301301
// Default filter highlight
302302
$(".buttons-colvisGroup:contains('All')").click();
303-
}
303+
}
304304

305305
if( window.data.trace==null ) {
306306
// nascondere
@@ -316,5 +316,24 @@ $(function() {
316316
make_tasks_table();
317317
}
318318

319+
// Create options table
320+
function make_options_table(){
321+
// reset
322+
if ( $.fn.dataTable.isDataTable( '#options_table' ) ) {
323+
$('#options_table').DataTable().destroy();
324+
}
325+
326+
var table = $('#options_table').DataTable({
327+
data: window.options,
328+
columns: [
329+
{ title: "Option", data: "option" },
330+
{ title: "Value", data: "value" }
331+
],
332+
"deferRender": true,
333+
"lengthMenu": [[25, 50, 100, -1], [25, 50, 100, "All"]],
334+
});
335+
}
319336

320-
});
337+
// Make the table on page load
338+
make_options_table();
339+
});

0 commit comments

Comments
 (0)