Skip to content

Commit ede867f

Browse files
authored
Merge pull request #373 from JosuaCarl/provenance-file
Refactor: Move to provenance file and update related tests
2 parents 5b619ed + f4a927d commit ede867f

37 files changed

Lines changed: 538 additions & 703 deletions

docs/assets/co2footprint_report_sample.html

Lines changed: 3 additions & 3 deletions
Large diffs are not rendered by default.

docs/assets/co2footprint_summary_sample.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ nf-co2footprint options:
2424
powerdrawMem: 0.3725
2525
pue: 1.3
2626
customCpuTdpFile: null
27-
dataFile: out/pipeline_info/co2footprint_data_2026-03-06_13-25-02.yaml
27+
provenanceFile: out/pipeline_info/co2footprint_data_2026-03-06_13-25-02.yaml
2828
reportFile: out/pipeline_info/co2footprint_report_2026-03-06_13-25-02.html
2929
summaryFile: out/pipeline_info/co2footprint_summary_2026-03-06_13-25-02.txt
3030
traceFile: out/pipeline_info/co2footprint_trace_2026-03-06_13-25-02.txt

docs/usage/output.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ The nf-co2footprint plugin creates three output files:
1616
- **`report`** ([sample](../assets/co2footprint_report_sample.html))
1717
The HTML report contains information about the carbon footprint of the whole pipeline run as well as plots showing the distributions of the CO₂ emissions for the different processes. The CO₂ emissions are separated into newly generated (i.e. from non-cached tasks) and total (including cached tasks). Additionally, it contains a table with the metrics for all individual tasks. The table is limited to 10000 entries by default. It finishes up with an overview plot of the carbon intensities during the workflow execution.
1818

19-
- **`dataFile`**
20-
The data file contains all trace information in a tree structure with the levels in descending order `session -> workflow -> process -> task`. Example: A workflow consists of multiple processes / has multiple `process` level children.
19+
- **`provenance`**
20+
The provenance file contains all trace information in a tree structure with the levels in descending order `session -> workflow -> process -> task`. Example: A workflow consists of multiple processes / has multiple `process` level children.
2121
The total session emission estimation includes everything from the point of plugin start to stop in a similar manner to how Nextflow defines a `TraceRecord`, but through the Java-native OSHI library.
2222

2323
!!! note "Comparison session vs. workflow"

docs/usage/parameters.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ The following parameters are currently available:
3232

3333
**Default**: `[enabled: true, file: co2footprint_report_<timestamp>.html, overwrite: true, maxTasks: 10000]`
3434

35-
- **`dataFile`**
35+
- **`provenance`**
3636
Map containing:
3737
- `enabled`: Whether to produce this file
3838
- `file`: Name of the data/machine-actionable file containing all metrics that were used during footprint calculation in a structured way.
3939
- `overwrite`: Whether to overwrite the file, if it already exists.
4040
- `emissionMetricsOnly`: Whether to only include emission metrics, such as CO₂ equivalents and electricity consumption.
4141

42-
**Default**: `[enabled: false, file: co2footprint_report_<timestamp>.html, overwrite: true, emissionMetricsOnly: false]`
42+
**Default**: `[enabled: false, file: co2footprint_report_<timestamp>.html, overwrite: true, emissionMetricsOnly: true]`
4343

4444
!!! warning "Preliminary feature"
4545
The data file is currently not in its final version. Changes in the near future are very likely.

src/main/nextflow/co2footprint/CO2FootprintConfig.groovy

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package nextflow.co2footprint
22

33
import groovy.util.logging.Slf4j
4-
import nextflow.co2footprint.Config.DataFileConfig
4+
import nextflow.co2footprint.Config.ProvenanceFileConfig
55
import nextflow.co2footprint.Config.ReportFileConfig
66
import nextflow.co2footprint.Config.SummaryFileConfig
77
import nextflow.co2footprint.Config.TraceFileConfig
@@ -70,8 +70,8 @@ class CO2FootprintConfig implements ConfigScope {
7070
final ReportFileConfig report
7171

7272
@ConfigOption(types=[Map])
73-
@Description('Configuration for the data/machine-readable file.')
74-
final DataFileConfig dataFile
73+
@Description('Configuration for the provenance data/machine-readable file.')
74+
final ProvenanceFileConfig provenance
7575

7676
@ConfigOption(types=[GString])
7777
@Description('Location GeoCode from Electricity maps.')
@@ -136,7 +136,7 @@ class CO2FootprintConfig implements ConfigScope {
136136
trace = new TraceFileConfig(getCollect('trace', configMap, usedKeys) as Map ?: [:], timestamp)
137137
summary = new SummaryFileConfig(getCollect('summary', configMap, usedKeys) as Map ?: [:], timestamp)
138138
report = new ReportFileConfig(getCollect('report', configMap, usedKeys) as Map ?: [:], timestamp)
139-
dataFile = new DataFileConfig(getCollect('dataFile', configMap, usedKeys) as Map ?: [:], timestamp)
139+
provenance = new ProvenanceFileConfig(getCollect('provenance', configMap, usedKeys) as Map ?: [:], timestamp)
140140

141141
// Location
142142
location = getCollect('location', configMap, usedKeys) as String ?: getLocationFromAWSRegion()
@@ -317,7 +317,7 @@ class CO2FootprintConfig implements ConfigScope {
317317
reportFile: report.file,
318318
summaryFile: summary.file,
319319
traceFile: trace.file,
320-
dataFile: dataFile.file
320+
provenanceFile: provenance.file
321321
].sort() as SortedMap
322322
}
323323

src/main/nextflow/co2footprint/CO2FootprintObserver.groovy

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package nextflow.co2footprint
33
import groovy.transform.PackageScope
44
import groovy.util.logging.Slf4j
55
import nextflow.Session
6-
import nextflow.co2footprint.FileCreation.DataFileCreator
6+
import nextflow.co2footprint.FileCreation.ProvenanceFileCreator
77
import nextflow.co2footprint.FileCreation.ReportFileCreator
88
import nextflow.co2footprint.FileCreation.SummaryFileCreator
99
import nextflow.co2footprint.FileCreation.TraceFileCreator
@@ -38,7 +38,7 @@ class CO2FootprintObserver implements TraceObserver {
3838
final TraceFileCreator traceFile
3939
final SummaryFileCreator summaryFile
4040
final ReportFileCreator reportFile
41-
final DataFileCreator dataFile
41+
final ProvenanceFileCreator provenanceFile
4242

4343
// Plugin configuration
4444
CO2FootprintConfig config
@@ -77,9 +77,9 @@ class CO2FootprintObserver implements TraceObserver {
7777
this.traceFile = new TraceFileCreator(config.trace)
7878
this.summaryFile = new SummaryFileCreator(config.summary)
7979
this.reportFile = new ReportFileCreator(config.report)
80-
this.dataFile = new DataFileCreator(config.dataFile)
80+
this.provenanceFile = new ProvenanceFileCreator(config.provenance)
8181

82-
if (!config.trace.enabled && !config.summary.enabled && !config.report.enabled && !config.dataFile.enabled) {
82+
if (!config.trace.enabled && !config.summary.enabled && !config.report.enabled && !config.provenance.enabled) {
8383
log.warn('No output files are enabled - to enable, set `enabled: true` in the sections `trace`, `summary` or `report`.')
8484
}
8585

@@ -164,15 +164,15 @@ class CO2FootprintObserver implements TraceObserver {
164164
reportFile.write()
165165
}
166166
if (co2RecordTree) {
167-
dataFile.create()
168-
dataFile.write(co2RecordTree)
167+
provenanceFile.create()
168+
provenanceFile.write(co2RecordTree)
169169
}
170170

171171
// Close all files (writes remaining tasks in the trace file)
172172
traceFile.close(runningTasks)
173173
summaryFile.close()
174174
reportFile.close()
175-
dataFile.close()
175+
provenanceFile.close()
176176
}
177177

178178
// ------ OBSERVER METHODS ------
@@ -221,8 +221,8 @@ class CO2FootprintObserver implements TraceObserver {
221221
workflowStats.summarize()
222222

223223
log.info(
224-
"🌱 The workflow run used ${workflowStats.co2Record.toReadable('energy')} of electricity, " +
225-
"resulting in the release of ${workflowStats.co2Record.toReadable('co2e')} of CO₂ equivalents into the atmosphere."
224+
"🌱 The workflow run used ${workflowStats.co2Record.toReadable('energy_consumption')} of electricity, " +
225+
"resulting in the release of ${workflowStats.co2Record.toReadable('CO2e')} of CO₂ equivalents into the atmosphere."
226226
)
227227
}
228228

src/main/nextflow/co2footprint/Config/DataFileConfig.groovy

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package nextflow.co2footprint.Config
2+
3+
import nextflow.co2footprint.CO2FootprintConfig
4+
import nextflow.config.spec.ConfigOption
5+
import nextflow.config.spec.ConfigScope
6+
import nextflow.config.spec.ScopeName
7+
import nextflow.script.dsl.Description
8+
9+
@ScopeName('co2footprint.provenance')
10+
@Description('The `co2footprint.provenance` scope allows you to configure the data/machine-actionable file of the `nf-co2footprint` plugin.')
11+
class ProvenanceFileConfig extends BaseFileConfig implements ConfigScope {
12+
13+
@ConfigOption
14+
@Description('Whether only emission metrics should be reported in the data file.')
15+
final boolean emissionMetricsOnly
16+
17+
ProvenanceFileConfig(Map provenanceFileConfig, String timestamp=null) {
18+
super(provenanceFileConfig, timestamp, 'data', 'yaml', false)
19+
20+
emissionMetricsOnly = provenanceFileConfig.containsKey('emissionMetricsOnly') ?
21+
CO2FootprintConfig.getCollect('emissionMetricsOnly', provenanceFileConfig, usedKeys) as boolean :
22+
true
23+
24+
CO2FootprintConfig.checkKeyUsage(provenanceFileConfig, usedKeys)
25+
}
26+
}

src/main/nextflow/co2footprint/FileCreation/DataFileCreator.groovy renamed to src/main/nextflow/co2footprint/FileCreation/ProvenanceFileCreator.groovy

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package nextflow.co2footprint.FileCreation
22

33
import groovyx.gpars.agent.Agent
4-
import nextflow.co2footprint.Config.DataFileConfig
4+
import nextflow.co2footprint.Config.ProvenanceFileConfig
55
import nextflow.co2footprint.Records.CO2RecordTree
66
import nextflow.trace.TraceHelper
77
import org.yaml.snakeyaml.Yaml
88

9-
class DataFileCreator extends BaseFileCreator {
9+
class ProvenanceFileCreator extends BaseFileCreator {
1010
// Yaml string creator
1111
Yaml yaml = new Yaml()
1212

@@ -19,9 +19,9 @@ class DataFileCreator extends BaseFileCreator {
1919
/**
2020
* Constructor for the data/machine-readable file.
2121
*
22-
* @param config A {@link DataFileConfig} that defines the created file.
22+
* @param config A {@link ProvenanceFileConfig} that defines the created file.
2323
*/
24-
DataFileCreator(DataFileConfig config) {
24+
ProvenanceFileCreator(ProvenanceFileConfig config) {
2525
super(config)
2626

2727
emissionMetricsOnly = config.emissionMetricsOnly

src/main/nextflow/co2footprint/FileCreation/ReportFileCreator.groovy

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,14 @@ class ReportFileCreator extends BaseFileCreator{
185185
).sum() as CO2Record
186186

187187
// Retrieve total CO₂ emissions and energy consumption for the given suffix
188-
Double co2e = workflowRecord.get("co2e${suffix}") as Double
189-
Double energy = workflowRecord.get("energy${suffix}") as Double
188+
Double co2e = workflowRecord.get("CO2e${suffix}") as Double
189+
Double energy = workflowRecord.get("energy_consumption${suffix}") as Double
190190

191191
if (co2e != null) {
192192
CO2EquivalencesRecord equivalences = co2FootprintComputer.computeCO2footprintEquivalences(co2e)
193193
return [
194-
("co2e${suffix}" as String): new Quantity(co2e,'', 'g').toReadable(),
195-
("energy${suffix}" as String): new Quantity(energy,'k','Wh').toReadable(),
194+
("CO2e${suffix}" as String): new Quantity(co2e,'', 'g').toReadable(),
195+
("energy_consumption${suffix}" as String): new Quantity(energy,'k','Wh').toReadable(),
196196
("car${suffix}" as String): equivalences.getCarKilometersReadable(),
197197
("tree${suffix}" as String): equivalences.getTreeMonthsReadable(),
198198
("plane_percent${suffix}" as String): equivalences.getPlanePercent() < 100.0 ? equivalences.getPlanePercentReadable() : null,
@@ -237,7 +237,7 @@ class ReportFileCreator extends BaseFileCreator{
237237
*/
238238
protected Map<String, Object> collectSummary(CO2RecordTree stats=this.stats) {
239239
// Add an empty map if the process is not already present
240-
return stats.collectByLevel('process', ['co2e', 'energy', 'co2e_non_cached', 'energy_non_cached'])
240+
return stats.collectByLevel('process', ['CO2e', 'energy_consumption', 'CO2e_non_cached', 'energy_consumption_non_cached'])
241241
}
242242

243243

0 commit comments

Comments
 (0)