Skip to content

Commit 127bf7c

Browse files
committed
Remove .report.compat.assert_dims() and usage
1 parent 59f4179 commit 127bf7c

File tree

1 file changed

+3
-44
lines changed

1 file changed

+3
-44
lines changed

message_ix_models/report/compat.py

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,11 @@ def pe_w_ccs_retro(
193193

194194
# TODO determine the dimensions to drop for the numerator
195195
k3, *_ = iter_keys(c.add(anon(dims=k2), "div", k2.drop("yv"), k2, sums=True))
196-
assert_dims(c, k3)
197196

198197
filters_out = dict(c=["electr"], l=["secondary"])
199198
k4 = eff(c, [t], filters_in=filters, filters_out=filters_out)
200199
k5 = single_key(c.add(anon(), "mul", k3, k4))
201200
k6 = single_key(c.add(anon(dims=k5), "div", k1, k5))
202-
assert_dims(c, k6)
203201

204202
return k6
205203

@@ -252,39 +250,6 @@ def prepare_techs(c: "Computer", technologies: list["Code"]) -> None:
252250
c.add(f"t::{k}", quote(sorted(v)))
253251

254252

255-
def assert_dims(c: "Computer", *keys: Key):
256-
"""Check the dimensions of `keys` for an "add", "sub", or "div" task.
257-
258-
This is a sanity check needed because :py:`c.add("name", "div", …)` does not (yet)
259-
automatically infer the dimensions of the resulting key. This is in contrast to
260-
:py:`c.add("name", "mul", …)`, which *does* infer.
261-
262-
Use this function after manual construction of a key for a "add", "div", or "sub"
263-
task, in order to ensure the key matches the dimensionality of the quantity that
264-
will result from the task.
265-
266-
.. deprecated:: 2025-02-17
267-
Handled upstream in :func:`genno.operator.add_binop` with genno ≥1.20.
268-
"""
269-
from warnings import warn
270-
271-
warn(
272-
"message-ix-models.report.compat.assert_dims()",
273-
DeprecationWarning,
274-
stacklevel=2,
275-
)
276-
277-
for key in keys:
278-
task = c.graph[key]
279-
expected = Key.product("foo", *task[1:])
280-
281-
op = f" {task[0].__name__} "
282-
assert set(key.dims) == set(expected.dims), (
283-
f"Task should produce {op.join(repr(k) for k in task[1:])} = "
284-
f"{str(expected).split(':')[1]}; key indicates {str(key).split(':')[1]}"
285-
)
286-
287-
288253
def callback(rep: "Reporter", context: "Context") -> None:
289254
"""Partially duplicate the behaviour of :func:`.default_tables.retr_CO2emi`.
290255
@@ -321,17 +286,15 @@ def full(name: str) -> Key:
321286
k0 = out(rep, ["gas_cc", "gas_ppl"])
322287
for t in "gas_cc", "gas_ppl":
323288
k1 = out(rep, [t])
324-
k2 = rep.add(Key(f"{t}_share", k1.dims), "div", k0, k1)
325-
assert_dims(rep, single_key(k2))
289+
rep.add(Key(f"{t}_share", k1.dims), "div", k0, k1)
326290

327291
# L3026
328292
# "in:*:nonccs_gas_tecs": Input to non-CCS technologies using gas at l=(secondary,
329293
# final), net of output from transmission and distribution technologies.
330294
c_gas = dict(c=["gas"])
331295
k0 = inp(rep, techs("gas", "all extra"), filters=c_gas)
332296
k1 = out(rep, ["gas_t_d", "gas_t_d_ch4"], filters=c_gas)
333-
k2 = rep.add(Key("in", k1.dims, "nonccs_gas_tecs"), "sub", k0, k1)
334-
assert_dims(rep, single_key(k2))
297+
rep.add(Key("in", k1.dims, "nonccs_gas_tecs"), "sub", k0, k1)
335298

336299
# L3091
337300
# "Biogas_tot_abs": absolute output from t=gas_bio [energy units]
@@ -351,7 +314,6 @@ def full(name: str) -> Key:
351314
k1 = rep.add(
352315
Key("in", k0.dims, "all_gas_tecs"), "add", full("in::nonccs_gas_tecs"), k0
353316
)
354-
assert_dims(rep, k1)
355317

356318
# L3165
357319
# "Hydrogen_tot:*": CO₂ emissions from t=h2_mix [mass/time]
@@ -386,7 +348,6 @@ def full(name: str) -> Key:
386348
full("in::nonccs_gas_tecs"),
387349
k0,
388350
)
389-
assert_dims(rep, k0, k1)
390351

391352
# L3144, L3234
392353
# "Biogas_trp", "Hydrogen_trp": transportation shares of emissions savings from
@@ -398,8 +359,7 @@ def full(name: str) -> Key:
398359
("Hydrogen", full("in::nonccs_gas_tecs_wo_ccsretro")),
399360
):
400361
k1 = rep.add(anon(dims=other), "div", k0, other)
401-
k2 = rep.add(f"{name}_trp", "mul", f"{name}_tot", k1)
402-
assert_dims(rep, single_key(k1))
362+
rep.add(f"{name}_trp", "mul", f"{name}_tot", k1)
403363

404364
# L3346
405365
# "FE_Transport": CO₂ emissions from all transportation technologies directly using
@@ -420,7 +380,6 @@ def full(name: str) -> Key:
420380
k1, *_ = iter_keys(
421381
rep.add(Key("Transport", k0.dims), "add", k0, full("Hydrogen_trp"), sums=True)
422382
)
423-
assert_dims(rep, k0, k1)
424383

425384
# TODO Identify where to sum on "h", "m", "yv" dimensions
426385

0 commit comments

Comments
 (0)