From 074e8dd1c7f415c1fa40b405433d29d2a261f7f3 Mon Sep 17 00:00:00 2001 From: Jonas Kaufman Date: Wed, 11 Feb 2026 09:39:16 -0800 Subject: [PATCH] Fix energy shape check in formation energy calculation --- .../composition/_formation_energy_calculator.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/python/libcasm/composition/_formation_energy_calculator.py b/python/libcasm/composition/_formation_energy_calculator.py index 2358fb1..fa8e461 100644 --- a/python/libcasm/composition/_formation_energy_calculator.py +++ b/python/libcasm/composition/_formation_energy_calculator.py @@ -132,17 +132,17 @@ def formation_energy( f"with shape ({self.independent_compositions},)" ) else: - if energy.shape != (self.independent_compositions,): - raise ValueError( - "If energy is an array, " - f"it must have shape ({self.independent_compositions},)" - ) if composition.shape[0] != self.independent_compositions: raise ValueError( - "If energy is an array," + "If energy is an array, " "composition must be a 2d array with shape " f"({self.independent_compositions}, n)" ) + if energy.shape != (composition.shape[1],): + raise ValueError( + "If energy is an array, " + f"it must have shape (n,)" + ) return energy - self.reference_energy(composition) def to_dict(self):