diff --git a/plugins/nf-co2footprint/src/main/nextflow/co2footprint/CO2FootprintConfig.groovy b/plugins/nf-co2footprint/src/main/nextflow/co2footprint/CO2FootprintConfig.groovy index 8c540ad..8fd38a0 100644 --- a/plugins/nf-co2footprint/src/main/nextflow/co2footprint/CO2FootprintConfig.groovy +++ b/plugins/nf-co2footprint/src/main/nextflow/co2footprint/CO2FootprintConfig.groovy @@ -27,15 +27,16 @@ import groovy.util.logging.Slf4j @PackageScope class CO2FootprintConfig { - final private String traceFile - final private String summaryFile - final private String reportFile - final private String location - final private Double ci // CI: carbon intensity - final private Double pue // PUE: power usage effectiveness efficiency, coefficient of the data centre - final private Double powerdrawMem // Power draw of memory [W per GB] - final private Boolean ignoreCpuModel - final private Double powerdrawCpuDefault + private String traceFile = CO2FootprintFactory.CO2FootprintTextFileObserver.DEF_TRACE_FILE_NAME + private String summaryFile = CO2FootprintFactory.CO2FootprintTextFileObserver.DEF_SUMMARY_FILE_NAME + private String reportFile = CO2FootprintFactory.CO2FootprintReportObserver.DEF_REPORT_FILE_NAME + private String location = null + private Double ci = 475 // CI: carbon intensity + private Double pue = 1.67 // PUE: power usage effectiveness efficiency, coefficient of the data centre + private Double powerdrawMem = 0.3725 // Power draw of memory [W per GB] + private Boolean ignoreCpuModel = false + private Double powerdrawCpuDefault = 12.0 + private String customCpuTdpFile = null // Retrieve CI value from file containing CI values for different locations protected Double retrieveCi(String location) { @@ -51,8 +52,9 @@ class CO2FootprintConfig { } } dataReader.close() - if (localCi == 0.0) + if (localCi == 0.0) { throw new IllegalArgumentException("Invalid 'location' parameter: $location. Could not be found in 'CI_aggregated.v2.2.csv'.") + } return localCi } @@ -74,28 +76,43 @@ class CO2FootprintConfig { CO2FootprintConfig(Map map, Map cpuData){ def config = map ?: Collections.emptyMap() - traceFile = config.traceFile ?: CO2FootprintFactory.CO2FootprintTextFileObserver.DEF_TRACE_FILE_NAME - summaryFile = config.summaryFile ?: CO2FootprintFactory.CO2FootprintTextFileObserver.DEF_SUMMARY_FILE_NAME - reportFile = config.reportFile ?: CO2FootprintFactory.CO2FootprintReportObserver.DEF_REPORT_FILE_NAME - ignoreCpuModel = config.ignoreCpuModel ?: false - - ci = 475 - if (config.ci && config.location) + if (config.traceFile) { + traceFile = config.traceFile + } + if (config.summaryFile) { + summaryFile = config.summaryFile + } + if (config.reportFile) { + reportFile = config.reportFile + } + if (config.ignoreCpuModel) { + ignoreCpuModel = config.ignoreCpuModel + } + if (config.ci && config.location) { throw new IllegalArgumentException("Invalid combination of 'ci' and 'location' parameters specified for the CO2Footprint plugin. Please specify either 'ci' or 'location'!") - if (config.ci) + } + if (config.ci) { ci = config.ci + } if (config.location) { ci = retrieveCi(config.location) location = config.location } - - pue = config.pue ?: 1.67 - powerdrawMem = config.powerdrawMem ?: 0.3725 - powerdrawCpuDefault = config.powerdrawCpuDefault ?: 12.0 + if (config.pue) { + pue = config.pue + } + if (config.powerdrawMem) { + powerdrawMem = config.powerdrawMem + } + if (config.powerdrawCpuDefault) { + powerdrawCpuDefault = config.powerdrawCpuDefault + } cpuData['default'] = powerdrawCpuDefault - if (config.customCpuTdpFile) + if (config.customCpuTdpFile) { + customCpuTdpFile = config.customCpuTdpFile loadCustomCpuTdpData(cpuData, config.customCpuTdpFile) + } } String getTraceFile() { traceFile } @@ -103,7 +120,33 @@ class CO2FootprintConfig { String getReportFile() { reportFile } Boolean getIgnoreCpuModel() { ignoreCpuModel } String getLocation() { location } - Double getCI() { ci } - Double getPUE() { pue } + Double getCi() { ci } + Double getPue() { pue } Double getPowerdrawMem() { powerdrawMem } + Double getPowerdrawCpuDefault() { powerdrawCpuDefault } + String getCustomCpuTdpFile() { customCpuTdpFile } + + // Different functions to collect options for reporting, grouped by purpose + SortedMap collectInputFileOptions() { + Map newMap = [:] + newMap["customCpuTdpFile"] = customCpuTdpFile + return newMap.sort() + } + SortedMap collectOutputFileOptions() { + Map newMap = [:] + newMap["traceFile"] = traceFile + newMap["summaryFile"] = summaryFile + newMap["reportFile"] = reportFile + return newMap.sort() + } + SortedMap collectCO2CalcOptions() { + Map newMap = [:] + newMap["location"] = location + newMap["ci"] = ci // Might be indirectly determined for location parameter + newMap["pue"] = pue + newMap["powerdrawMem"] = powerdrawMem + newMap["powerdrawCpuDefault"] = powerdrawCpuDefault + newMap["ignoreCpuModel"] = ignoreCpuModel + return newMap.sort() + } } diff --git a/plugins/nf-co2footprint/src/main/nextflow/co2footprint/CO2FootprintFactory.groovy b/plugins/nf-co2footprint/src/main/nextflow/co2footprint/CO2FootprintFactory.groovy index 28d6afa..f204869 100644 --- a/plugins/nf-co2footprint/src/main/nextflow/co2footprint/CO2FootprintFactory.groovy +++ b/plugins/nf-co2footprint/src/main/nextflow/co2footprint/CO2FootprintFactory.groovy @@ -198,9 +198,9 @@ class CO2FootprintFactory implements TraceObserverFactory { * Remaining factors */ // PUE: efficiency coefficient of the data centre - Double pue = config.getPUE() + Double pue = config.getPue() // CI: carbon intensity [gCO2e kWh−1] - def ci = config.getCI() + def ci = config.getCi() /** * Calculate energy consumption [kWh] @@ -363,6 +363,11 @@ class CO2FootprintFactory implements TraceObserverFactory { 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") co2eSummaryFile.println() co2eSummaryFile.println("nf-co2footprint plugin version: ${version}") + co2eSummaryFile.println() + co2eSummaryFile.println("nf-co2footprint options") + config.collectInputFileOptions().each { co2eSummaryFile.println("${it.key}: ${it.value}") } + config.collectOutputFileOptions().each { co2eSummaryFile.println("${it.key}: ${it.value}") } + config.collectCO2CalcOptions().each { co2eSummaryFile.println("${it.key}: ${it.value}") } co2eSummaryFile.flush() co2eSummaryFile.close() @@ -737,6 +742,29 @@ class CO2FootprintFactory implements TraceObserverFactory { "{ \"trace\":${renderTasksJson()}, \"summary\":${renderSummaryJson()} }" } + /** + * @return The options json payload + */ + protected String renderOptionsJson() { + final all_options = config.collectInputFileOptions() + config.collectOutputFileOptions() + config.collectCO2CalcOptions() + def result = new StringBuilder() + result << "[" + def fields = all_options.keySet() as List + + // Render JSON + final QUOTE = '"' + for( int i=0; iTasks +
+
+

Options

+

This table shows the nf-co2footprint plugin options that were used to calculate the CO2e footprint measures.

+
+
+
+
+
+