Skip to content

Commit 8d53a1f

Browse files
Make carbon tracking optional (#343)
1 parent 01b5ba8 commit 8d53a1f

23 files changed

+377
-21
lines changed

janus_core/calculations/base.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ class BaseCalculation(FileNameMixin):
4747
Whether to attach a logger. Default is False.
4848
log_kwargs : Optional[dict[str, Any]]
4949
Keyword arguments to pass to `config_logger`. Default is {}.
50+
track_carbon : bool
51+
Whether to track carbon emissions of calculation. Default is True.
5052
tracker_kwargs : Optional[dict[str, Any]]
5153
Keyword arguments to pass to `config_tracker`. Default is {}.
5254
file_prefix : Optional[PathLike]
@@ -79,6 +81,7 @@ def __init__(
7981
set_calc: Optional[bool] = None,
8082
attach_logger: bool = False,
8183
log_kwargs: Optional[dict[str, Any]] = None,
84+
track_carbon: bool = True,
8285
tracker_kwargs: Optional[dict[str, Any]] = None,
8386
file_prefix: Optional[PathLike] = None,
8487
additional_prefix: Optional[str] = None,
@@ -115,6 +118,8 @@ def __init__(
115118
Whether to attach a logger. Default is False.
116119
log_kwargs : Optional[dict[str, Any]]
117120
Keyword arguments to pass to `config_logger`. Default is {}.
121+
track_carbon : bool
122+
Whether to track carbon emissions of calculation. Default is True.
118123
tracker_kwargs : Optional[dict[str, Any]]
119124
Keyword arguments to pass to `config_tracker`. Default is {}.
120125
file_prefix : Optional[PathLike]
@@ -137,6 +142,7 @@ def __init__(
137142
self.read_kwargs = read_kwargs
138143
self.calc_kwargs = calc_kwargs
139144
self.log_kwargs = log_kwargs
145+
self.track_carbon = track_carbon
140146
self.tracker_kwargs = tracker_kwargs
141147

142148
if not self.model_path and "model_path" in self.calc_kwargs:
@@ -179,4 +185,6 @@ def __init__(
179185

180186
self.log_kwargs.setdefault("name", calc_name)
181187
self.logger = config_logger(**self.log_kwargs)
182-
self.tracker = config_tracker(self.logger, **self.tracker_kwargs)
188+
self.tracker = config_tracker(
189+
self.logger, self.track_carbon, **self.tracker_kwargs
190+
)

janus_core/calculations/descriptors.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ class Descriptors(BaseCalculation):
4747
Whether to attach a logger. Default is False.
4848
log_kwargs : Optional[dict[str, Any]]
4949
Keyword arguments to pass to `config_logger`. Default is {}.
50+
track_carbon : bool
51+
Whether to track carbon emissions of calculation. Default is True.
5052
tracker_kwargs : Optional[dict[str, Any]]
5153
Keyword arguments to pass to `config_tracker`. Default is {}.
5254
invariants_only : bool
@@ -79,6 +81,7 @@ def __init__(
7981
set_calc: Optional[bool] = None,
8082
attach_logger: bool = False,
8183
log_kwargs: Optional[dict[str, Any]] = None,
84+
track_carbon: bool = True,
8285
tracker_kwargs: Optional[dict[str, Any]] = None,
8386
invariants_only: bool = True,
8487
calc_per_element: bool = False,
@@ -114,6 +117,8 @@ def __init__(
114117
Whether to attach a logger. Default is False.
115118
log_kwargs : Optional[dict[str, Any]]
116119
Keyword arguments to pass to `config_logger`. Default is {}.
120+
track_carbon : bool
121+
Whether to track carbon emissions of calculation. Default is True.
117122
tracker_kwargs : Optional[dict[str, Any]]
118123
Keyword arguments to pass to `config_tracker`. Default is {}.
119124
invariants_only : bool
@@ -153,6 +158,7 @@ def __init__(
153158
set_calc=set_calc,
154159
attach_logger=attach_logger,
155160
log_kwargs=log_kwargs,
161+
track_carbon=track_carbon,
156162
tracker_kwargs=tracker_kwargs,
157163
)
158164

@@ -182,6 +188,7 @@ def run(self) -> None:
182188
self.logger.info("invariants_only: %s", self.invariants_only)
183189
self.logger.info("calc_per_element: %s", self.calc_per_element)
184190
self.logger.info("calc_per_atom: %s", self.calc_per_atom)
191+
if self.tracker:
185192
self.tracker.start_task("Descriptors")
186193

187194
if isinstance(self.struct, Sequence):
@@ -191,14 +198,15 @@ def run(self) -> None:
191198
self._calc_descriptors(self.struct)
192199

193200
if self.logger:
201+
self.logger.info("Descriptors calculation complete")
202+
if self.tracker:
194203
emissions = self.tracker.stop_task().emissions
195204
if isinstance(self.struct, Sequence):
196205
for image in self.struct:
197206
image.info["emissions"] = emissions
198207
else:
199208
self.struct.info["emissions"] = emissions
200209
self.tracker.stop()
201-
self.logger.info("Descriptors calculation complete")
202210

203211
output_structs(
204212
self.struct,

janus_core/calculations/eos.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ class EoS(BaseCalculation):
5151
Whether to attach a logger. Default is False.
5252
log_kwargs : Optional[dict[str, Any]]
5353
Keyword arguments to pass to `config_logger`. Default is {}.
54+
track_carbon : bool
55+
Whether to track carbon emissions of calculation. Default is True.
5456
tracker_kwargs : Optional[dict[str, Any]]
5557
Keyword arguments to pass to `config_tracker`. Default is {}.
5658
min_volume : float
@@ -112,6 +114,7 @@ def __init__(
112114
set_calc: Optional[bool] = None,
113115
attach_logger: bool = False,
114116
log_kwargs: Optional[dict[str, Any]] = None,
117+
track_carbon: bool = True,
115118
tracker_kwargs: Optional[dict[str, Any]] = None,
116119
min_volume: float = 0.95,
117120
max_volume: float = 1.05,
@@ -155,6 +158,8 @@ def __init__(
155158
Whether to attach a logger. Default is False.
156159
log_kwargs : Optional[dict[str, Any]]
157160
Keyword arguments to pass to `config_logger`. Default is {}.
161+
track_carbon : bool
162+
Whether to track carbon emissions of calculation. Default is True.
158163
tracker_kwargs : Optional[dict[str, Any]]
159164
Keyword arguments to pass to `config_tracker`. Default is {}.
160165
min_volume : float
@@ -241,6 +246,7 @@ def __init__(
241246
set_calc=set_calc,
242247
attach_logger=attach_logger,
243248
log_kwargs=log_kwargs,
249+
track_carbon=track_carbon,
244250
tracker_kwargs=tracker_kwargs,
245251
file_prefix=file_prefix,
246252
)
@@ -313,17 +319,19 @@ def run(self) -> EoSResults:
313319

314320
if self.logger:
315321
self.logger.info("Starting of fitting equation of state")
322+
if self.tracker:
316323
self.tracker.start_task("Fit EoS")
317324

318325
v_0, e_0, bulk_modulus = eos.fit()
319326
# transform bulk modulus unit in GPa
320327
bulk_modulus *= 1.0e24 / kJ
321328

322329
if self.logger:
330+
self.logger.info("Equation of state fitting complete")
331+
if self.tracker:
323332
emissions = self.tracker.stop_task().emissions
324333
self.struct.info["emissions"] = emissions
325334
self.tracker.stop()
326-
self.logger.info("Equation of state fitting complete")
327335

328336
if self.write_results:
329337
with open(f"{self.file_prefix}-eos-fit.dat", "w", encoding="utf8") as out:
@@ -346,6 +354,7 @@ def _calc_volumes_energies(self) -> None:
346354
"""Calculate volumes and energies for all lattice constants."""
347355
if self.logger:
348356
self.logger.info("Starting calculations for configurations")
357+
if self.tracker:
349358
self.tracker.start_task("Calculate configurations")
350359

351360
cell = self.struct.get_cell()
@@ -380,6 +389,7 @@ def _calc_volumes_energies(self) -> None:
380389
)
381390

382391
if self.logger:
392+
self.logger.info("Calculations for configurations complete")
393+
if self.tracker:
383394
emissions = self.tracker.stop_task().emissions
384395
self.struct.info["emissions"] = emissions
385-
self.logger.info("Calculations for configurations complete")

janus_core/calculations/geom_opt.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ class GeomOpt(BaseCalculation):
5151
Whether to attach a logger. Default is False.
5252
log_kwargs : Optional[dict[str, Any]]
5353
Keyword arguments to pass to `config_logger`. Default is {}.
54+
track_carbon : bool
55+
Whether to track carbon emissions of calculation. Default is True.
5456
tracker_kwargs : Optional[dict[str, Any]]
5557
Keyword arguments to pass to `config_tracker`. Default is {}.
5658
fmax : float
@@ -104,6 +106,7 @@ def __init__(
104106
set_calc: Optional[bool] = None,
105107
attach_logger: bool = False,
106108
log_kwargs: Optional[dict[str, Any]] = None,
109+
track_carbon: bool = True,
107110
tracker_kwargs: Optional[dict[str, Any]] = None,
108111
fmax: float = 0.1,
109112
steps: int = 1000,
@@ -146,6 +149,8 @@ def __init__(
146149
Whether to attach a logger. Default is False.
147150
log_kwargs : Optional[dict[str, Any]]
148151
Keyword arguments to pass to `config_logger`. Default is {}.
152+
track_carbon : bool
153+
Whether to track carbon emissions of calculation. Default is True.
149154
tracker_kwargs : Optional[dict[str, Any]]
150155
Keyword arguments to pass to `config_tracker`. Default is {}.
151156
fmax : float
@@ -224,6 +229,7 @@ def __init__(
224229
set_calc=set_calc,
225230
attach_logger=attach_logger,
226231
log_kwargs=log_kwargs,
232+
track_carbon=track_carbon,
227233
tracker_kwargs=tracker_kwargs,
228234
)
229235

@@ -292,6 +298,7 @@ def run(self) -> None:
292298

293299
if self.logger:
294300
self.logger.info("Starting geometry optimization")
301+
if self.tracker:
295302
self.tracker.start_task("Geometry optimization")
296303

297304
converged = self.dyn.run(fmax=self.fmax, steps=self.steps)
@@ -351,7 +358,8 @@ def run(self) -> None:
351358
)
352359

353360
if self.logger:
361+
self.logger.info("Geometry optimization complete")
362+
if self.tracker:
354363
emissions = self.tracker.stop_task().emissions
355364
self.struct.info["emissions"] = emissions
356365
self.tracker.stop()
357-
self.logger.info("Geometry optimization complete")

janus_core/calculations/md.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ class MolecularDynamics(BaseCalculation):
7676
Whether to attach a logger. Default is False.
7777
log_kwargs : Optional[dict[str, Any]]
7878
Keyword arguments to pass to `config_logger`. Default is {}.
79+
track_carbon : bool
80+
Whether to track carbon emissions of calculation. Default is True.
7981
tracker_kwargs : Optional[dict[str, Any]]
8082
Keyword arguments to pass to `config_tracker`. Default is {}.
8183
struct : Atoms
@@ -187,6 +189,7 @@ def __init__(
187189
set_calc: Optional[bool] = None,
188190
attach_logger: bool = False,
189191
log_kwargs: Optional[dict[str, Any]] = None,
192+
track_carbon: bool = True,
190193
tracker_kwargs: Optional[dict[str, Any]] = None,
191194
ensemble: Optional[Ensembles] = None,
192195
steps: int = 0,
@@ -250,6 +253,8 @@ def __init__(
250253
Whether to attach a logger. Default is False.
251254
log_kwargs : Optional[dict[str, Any]]
252255
Keyword arguments to pass to `config_logger`. Default is {}.
256+
track_carbon : bool
257+
Whether to track carbon emissions of calculation. Default is True.
253258
tracker_kwargs : Optional[dict[str, Any]]
254259
Keyword arguments to pass to `config_tracker`. Default is {}.
255260
ensemble : Ensembles
@@ -448,6 +453,7 @@ def __init__(
448453
set_calc=set_calc,
449454
attach_logger=attach_logger,
450455
log_kwargs=log_kwargs,
456+
track_carbon=track_carbon,
451457
tracker_kwargs=tracker_kwargs,
452458
file_prefix=file_prefix,
453459
additional_prefix=self.ensemble,
@@ -1070,6 +1076,7 @@ def _run_dynamics(self) -> None:
10701076

10711077
if self.logger:
10721078
self.logger.info("Beginning temperature ramp at %sK", temps[0])
1079+
if self.tracker:
10731080
self.tracker.start_task("Temperature ramp")
10741081

10751082
for temp in temps:
@@ -1087,13 +1094,15 @@ def _run_dynamics(self) -> None:
10871094

10881095
if self.logger:
10891096
self.logger.info("Temperature ramp complete at %sK", temps[-1])
1097+
if self.tracker:
10901098
emissions = self.tracker.stop_task().emissions
10911099
self.struct.info["emissions"] = emissions
10921100

10931101
# Run MD
10941102
if self.steps > 0:
10951103
if self.logger:
10961104
self.logger.info("Starting molecular dynamics simulation")
1105+
if self.tracker:
10971106
self.tracker.start_task("Molecular dynamics")
10981107
self.temp = md_temp
10991108
if self.ramp_temp:
@@ -1104,10 +1113,11 @@ def _run_dynamics(self) -> None:
11041113
self._write_final_state()
11051114
self.created_final_file = True
11061115
if self.logger:
1116+
self.logger.info("Molecular dynamics simulation complete")
1117+
if self.tracker:
11071118
emissions = self.tracker.stop_task().emissions
11081119
self.struct.info["emissions"] = emissions
11091120
self.tracker.stop()
1110-
self.logger.info("Molecular dynamics simulation complete")
11111121

11121122

11131123
class NPT(MolecularDynamics):

0 commit comments

Comments
 (0)