Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Error Message When kwargs Is Not Unpacked? #1205

Open
dallan-keylogic opened this issue Jun 12, 2023 · 1 comment
Open

Improve Error Message When kwargs Is Not Unpacked? #1205

dallan-keylogic opened this issue Jun 12, 2023 · 1 comment
Assignees
Labels
discussion Discussion enhancement New feature or request Priority:Normal Normal Priority Issue or PR

Comments

@dallan-keylogic
Copy link
Contributor

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?

@andrewlee94
Copy link
Member

The line raising the ConfigurationError (303) could be extended with "Did you forget to unpack the configuration dictionary?"

@lbianchi-lbl lbianchi-lbl added enhancement New feature or request discussion Discussion Priority:Normal Normal Priority Issue or PR labels Jun 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Discussion enhancement New feature or request Priority:Normal Normal Priority Issue or PR
Projects
None yet
Development

No branches or pull requests

3 participants