diff --git a/.maint/contributors.json b/.maint/contributors.json index bd791e566..505bba7b1 100644 --- a/.maint/contributors.json +++ b/.maint/contributors.json @@ -19,6 +19,11 @@ "name": "Benson, Noah C.", "orcid": "0000-0002-2365-8265" }, + { + "affiliation": "Montreal Neurological Institute, McGill University", + "name": "Bhagwat, Nikhil", + "orcid": "0000-0001-6073-7141" + }, { "affiliation": "Perelman School of Medicine, University of Pennsylvania, PA, USA", "name": "Cieslak, Matthew", diff --git a/fmriprep/cli/parser.py b/fmriprep/cli/parser.py index f13a22d06..efac6aa81 100644 --- a/fmriprep/cli/parser.py +++ b/fmriprep/cli/parser.py @@ -629,6 +629,20 @@ def _slice_time_ref(value, parser): help="Use low-quality tools for speed - TESTING ONLY", ) + # Carbon tracker options + g_other.add_argument( + "--track-carbon", + action="store_true", + help="Tracks power draws using CodeCarbon package", + ) + g_other.add_argument( + "--country-code", + action="store", + default="CAN", + type=str, + help="Country ISO code used by carbon trackers", + ) + latest = check_latest() if latest is not None and currentv < latest: print( diff --git a/fmriprep/cli/run.py b/fmriprep/cli/run.py old mode 100755 new mode 100644 index c88a6407c..289d17207 --- a/fmriprep/cli/run.py +++ b/fmriprep/cli/run.py @@ -39,6 +39,20 @@ def main(): parse_args() + # Code Carbon + if config.execution.track_carbon: + from codecarbon import OfflineEmissionsTracker + + country_iso_code = config.execution.country_code + config.loggers.workflow.log(25, "CodeCarbon tracker started ...") + config.loggers.workflow.log(25, f"Using country_iso_code: {country_iso_code}") + config.loggers.workflow.log(25, f"Saving logs at: {config.execution.log_dir}") + + tracker = OfflineEmissionsTracker( + output_dir=config.execution.log_dir, country_iso_code=country_iso_code + ) + tracker.start() + if "pdb" in config.execution.debug: from fmriprep.utils.debug import setup_exceptionhook @@ -179,6 +193,13 @@ def main(): finally: from pkg_resources import resource_filename as pkgrf + # Code Carbon + if config.execution.track_carbon: + emissions: float = tracker.stop() + config.loggers.workflow.log(25, "CodeCarbon tracker has stopped.") + config.loggers.workflow.log(25, f"Saving logs at: {config.execution.log_dir}") + config.loggers.workflow.log(25, f"Carbon emissions: {emissions} kg") + from fmriprep.reports.core import generate_reports # Generate reports phase diff --git a/fmriprep/config.py b/fmriprep/config.py index fa5fee4ed..2c3fe3dd4 100644 --- a/fmriprep/config.py +++ b/fmriprep/config.py @@ -400,6 +400,10 @@ class execution(_Config): """Do not convert boilerplate from MarkDown to LaTex and HTML.""" notrack = False """Do not monitor *fMRIPrep* using Sentry.io.""" + track_carbon = False + """Tracks power draws using CodeCarbon package.""" + country_code = "CAN" + """Country ISO code used by carbon trackers.""" output_dir = None """Folder where derivatives will be stored.""" me_output_echos = False diff --git a/setup.cfg b/setup.cfg index 45818cff6..5a8301267 100644 --- a/setup.cfg +++ b/setup.cfg @@ -40,6 +40,9 @@ install_requires = tedana ~= 0.0.9 templateflow >= 0.6 toml + codecarbon + APScheduler + test_requires = coverage codecov