Skip to content

Getting default scaler and default initializer broken for scaler state blocks #1686

@dallan-keylogic

Description

@dallan-keylogic

When trying to test the scaler object for the Helmholtz properties, I encountered the following error:

    @pytest.mark.unit
    def test_scaler_object_mole_basis():
        m = pyo.ConcreteModel()
        m.fs = FlowsheetBlock()

        m.fs.prop_water = HelmholtzParameterBlock(
            pure_component="h2o", amount_basis=AmountBasis.MOLE
        )

        m.fs.sb = m.fs.prop_water.build_state_block()

>       assert m.fs.sb.default_scaler is hstate.HelmholtzEoSScaler

tests\test_stateblock.py:52:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
..\..\..\core\base\property_base.py:602: in default_scaler
    return self.parent_component().default_scaler
..\..\..\core\base\property_base.py:602: in default_scaler
    return self.parent_component().default_scaler
E   RecursionError: maximum recursion depth exceeded while calling a Python object
!!! Recursion detected (same locals & position)

The problem here is that m.fs.sb.parent_component() is m.fs.sb because it is a scalar block. We have been attaching default_scaler and default_initializer attributes to the StateBlock instead of the StateBlockData children:

class _StateBlock(StateBlock):
    """
    This class contains methods which should be applied to Property Blocks as a
    whole, rather than individual elements of indexed Property Blocks.
    """

    # Set default initializer
    default_initializer = HelmholtzEoSInitializer
    default_scaler = HelmholtzEoSScaler

but evidentially that isn't sufficient.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions