idaes-pse icon indicating copy to clipboard operation
idaes-pse copied to clipboard

Improve Error Message When kwargs Is Not Unpacked?

Open dallan-keylogic opened this issue 2 years ago • 1 comments
trafficstars

Today, I was working with a modular property block, and got a bizarre error that seemed inexplicable:

    def build(self):
        """
        Callable method for Block construction.
        """
        # Call super.build() to initialize Block
        super(GenericParameterData, self).build()

        # Set base units of measurement
        self.get_metadata().add_default_units(self.config.base_units)

        # Call configure method to set construction arguments
        self.configure()

        # Build core components
        self._state_block_class = GenericStateBlock

        # Add Phase objects
        if self.config.phases is None:
>           raise ConfigurationError(
                "{} was not provided with a phases argument.".format(self.name)
            )
E           idaes.core.util.exceptions.ConfigurationError: params[phases] was not provided with a phases argument.

base\generic_property.py:303: ConfigurationError

All I was doing was taking a configuration dictionary already used in an example and changing/adding some parameters:

    def model(self):
        m = ConcreteModel()
        config = deepcopy(configuration)
        config["phases"]["Liq"]["equation_of_state_options"]["reference_state"] = InfiniteDilutionAqueous
        # Since the phase is water, these numbers don't actually matter, but they're taken from Table III from
        # Rashin and Honig, Reevaluation of the Born Model of Ion Hydration, J. Phys. Chem., 1985, 89, 5588-5593
        config["components"]["Na+"]["parameter_data"] = {"born_radius": (1.680, pyunits.angstrom)}
        config["components"]["K+"]["parameter_data"] = {"born_radius": (2.172, pyunits.angstrom)}
        config["components"]["Cl-"]["parameter_data"] = {"born_radius": (1.937, pyunits.angstrom)}
        m.params = GenericParameterBlock(config)

        m.state = m.params.build_state_block([1])
        ...

Of course, the problem is that I forgot to unpack the configuration dictionary config, changing the line to:

        m.params = GenericParameterBlock(**config)

fixed the problem.

Is there a way we could add a better error message for this sort of issue?

dallan-keylogic avatar Jun 12 '23 18:06 dallan-keylogic