Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report nf-co2footprint parameters #89

Merged
merged 12 commits into from
Mar 19, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
}
Expand All @@ -74,36 +76,77 @@ class CO2FootprintConfig {

CO2FootprintConfig(Map map, Map<String, Double> 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 }
String getSummaryFile() { summaryFile }
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<String, Object> collectInputFileOptions() {
Map<String, Object> newMap = [:]
newMap["customCpuTdpFile"] = customCpuTdpFile
return newMap.sort()
}
SortedMap<String, Object> collectOutputFileOptions() {
Map<String, Object> newMap = [:]
newMap["traceFile"] = traceFile
newMap["summaryFile"] = summaryFile
newMap["reportFile"] = reportFile
return newMap.sort()
}
SortedMap<String, Object> collectCO2CalcOptions() {
Map<String, Object> 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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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; i<fields.size(); i++ ) {
if(i) result << ','
String name = fields[i]
String value = all_options[name].toString()
result << "{" << QUOTE << "option" << QUOTE << ":" << QUOTE << name << QUOTE << ","
result << QUOTE << "value" << QUOTE << ":" << QUOTE << value << QUOTE << "}"
}
result << "]"

return result.toString()
}

/**
* Render the total co2 footprint values for html report
*
Expand Down Expand Up @@ -777,7 +805,8 @@ class CO2FootprintFactory implements TraceObserverFactory {
readTemplate('nextflow/trace/assets/moment.min.js'),
readTemplate('nextflow/trace/assets/plotly.min.js'),
readTemplate('assets/CO2FootprintReportTemplate.js')
]
],
options : renderOptionsJson()
]
//log.info "${tpl_fields['payload']}"
final tpl = readTemplate('CO2FootprintReportTemplate.html')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,16 @@ <h2 id="tasks" style="padding-top: 80px;">Tasks</h2>
</div>
</div>

<div class="container">
<div id="table-container">
<h2 id="options" style="padding-top: 80px;">Options</h2>
<p>This table shows the nf-co2footprint plugin options that were used to calculate the CO<sub>2</sub>e footprint measures.</p>
</div>
<div class="container-fluid">
<table class="table small table-striped" id="options_table"></table>
</div>
</div>

<footer>
<div class="container-fluid">
Generated by <a href="https://www.nextflow.io" target="_blank">Nextflow</a>, version ${workflow.nextflow.version}
Expand All @@ -272,6 +282,7 @@ <h2 id="tasks" style="padding-top: 80px;">Tasks</h2>

// Nextflow report data
window.data = $payload;
window.options = $options;

</script>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ $(function() {

// Default filter highlight
$(".buttons-colvisGroup:contains('All')").click();
}
}

if( window.data.trace==null ) {
// nascondere
Expand All @@ -316,5 +316,24 @@ $(function() {
make_tasks_table();
}

// Create options table
function make_options_table(){
// reset
if ( $.fn.dataTable.isDataTable( '#options_table' ) ) {
$('#options_table').DataTable().destroy();
}

var table = $('#options_table').DataTable({
data: window.options,
columns: [
{ title: "Option", data: "option" },
{ title: "Value", data: "value" }
],
"deferRender": true,
"lengthMenu": [[25, 50, 100, -1], [25, 50, 100, "All"]],
});
}

});
// Make the table on page load
make_options_table();
});
Loading