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

Encountering error while running pytest on an M2 chip Mac #1552

Open
CopyDemon opened this issue Dec 18, 2024 · 0 comments
Open

Encountering error while running pytest on an M2 chip Mac #1552

CopyDemon opened this issue Dec 18, 2024 · 0 comments
Assignees
Labels
Priority:Normal Normal Priority Issue or PR

Comments

@CopyDemon
Copy link
Contributor

CopyDemon commented Dec 18, 2024

Attempt to run pytest on the idaes-pse package, specifically the test_demo_flowsheet.py file, and observe that pytest fails on my Mac but passes on the CI environment.

System:

$ sw_ver
ProductName:		macOS
ProductVersion:		15.1.1
BuildVersion:		24B91
$ sysctl -n machdep.cpu.brand_string
Apple M2 Pro

Run commands:

conda create --yes -n 312 python=3.12 && conda activate 312 
pip install idaes-pse
idaes get-extensions
pytest --pyargs idaes -k test_demo_flowsheet

Pytest show error:

models/flowsheets/tests/test_demo_flowsheet.py ...F.F                                                                                                                                                                                                                                                                                                                     [100%]

=================================================================================================================================================================================== FAILURES ====================================================================================================================================================================================
___________________________________________________________________________________________________________________________________________________________________________ test_initialize_flowsheet ___________________________________________________________________________________________________________________________________________________________________________

model = <pyomo.core.base.PyomoModel.ConcreteModel object at 0x1196f47d0>

    @pytest.mark.unit
    def test_initialize_flowsheet(model):
>       initialize_flowsheet(model)

../../../../miniforge3/envs/test-idaes-2.6/lib/python3.12/site-packages/idaes/models/flowsheets/tests/test_demo_flowsheet.py:77: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../../../miniforge3/envs/test-idaes-2.6/lib/python3.12/site-packages/idaes/models/flowsheets/demo_flowsheet.py:477: in initialize_flowsheet
    m.fs.M01.initialize(outlvl=idaeslog.WARNING)
../../../../miniforge3/envs/test-idaes-2.6/lib/python3.12/site-packages/idaes/core/base/unit_model.py:540: in initialize
    flags = blk.initialize_build(*args, **kwargs)
../../../../miniforge3/envs/test-idaes-2.6/lib/python3.12/site-packages/idaes/models/unit_models/mixer.py:1035: in initialize_build
    flags[i] = i_block.initialize(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

blk = <idaes.core.base.process_block._IndexedActivityCoeffStateBlock object at 0x11988c410>, state_args = None, hold_state = True, state_vars_fixed = False, outlvl = 30, solver = None, optarg = None

    def initialize(
        blk,
        state_args=None,
        hold_state=False,
        state_vars_fixed=False,
        outlvl=idaeslog.NOTSET,
        solver=None,
        optarg=None,
    ):
        """
        Initialization routine for property package.
        Keyword Arguments:
            state_args : Dictionary with initial guesses for the state vars
                         chosen. Note that if this method is triggered
                         through the control volume, and if initial guesses
                         were not provided at the unit model level, the
                         control volume passes the inlet values as initial
                         guess.
                         If FTPz are chosen as state_vars, then keys for
                         the state_args dictionary are:
                         flow_mol, temperature, pressure and mole_frac_comp
                         If FcTP are chose as the state_vars, then keys for
                         the state_args dictionary are:
                         flow_mol_comp, temperature, pressure.
            outlvl : sets output level of initialization routine
            optarg : solver options dictionary object (default=None, use
                     default solver options)
            solver : str indicating which solver to use during
                     initialization (default = None, use default solve)
            hold_state : flag indicating whether the initialization routine
                         should unfix any state variables fixed during
                         initialization (default=False).
                         - True - states variables are not unfixed, and
                                 a dict of returned containing flags for
                                 which states were fixed during
                                 initialization.
                        - False - state variables are unfixed after
                                 initialization by calling the
                                 release_state method
            state_vars_fixed: Flag to denote if state vars have already been
                              fixed.
                              - True - states have already been fixed and
                                       initialization does not need to worry
                                       about fixing and unfixing variables.
                             - False - states have not been fixed. The state
                                       block will deal with fixing/unfixing.
        Returns:
            If hold_states is True, returns a dict containing flags for
            which states were fixed during initialization.
        """
        # Deactivate the constraints specific for outlet block i.e.
        # when defined state is False
        init_log = idaeslog.getInitLogger(blk.name, outlvl, tag="properties")
        solve_log = idaeslog.getSolveLogger(blk.name, outlvl, tag="properties")
    
        for k in blk.values():
            if (k.config.defined_state is False) and (
                k.params.config.state_vars == "FTPz"
            ):
                k.eq_mol_frac_out.deactivate()
    
        # Fix state variables if not already fixed
        if state_vars_fixed is False:
            flags = fix_state_vars(blk, state_args)
        else:
            # Check when the state vars are fixed already result in dof 0
            for k in blk.values():
                if degrees_of_freedom(k) != 0:
                    # PYLINT-TODO
                    # pylint: disable-next=broad-exception-raised
                    raise Exception(
                        "State vars fixed but degrees of freedom "
                        "for state block is not zero during "
                        "initialization."
                    )
    
        # Create solver
        opt = get_solver(solver, optarg)
    
        # ---------------------------------------------------------------------
        # Initialization sequence: Deactivating certain constraints
        # for 1st solve
        for k in blk.values():
            for c in k.component_objects(Constraint):
                if c.local_name in [
                    "eq_total",
                    "eq_comp",
                    "eq_phase_equilibrium",
                    "eq_enth_mol_phase",
                    "eq_entr_mol_phase",
                    "eq_Gij_coeff",
                    "eq_A",
                    "eq_B",
                    "eq_activity_coeff",
                ]:
                    c.deactivate()
    
        # First solve for the active constraints that remain (p_sat, T_bubble,
        # T_dew). Valid only for a 2 phase block. If single phase,
        # no constraints are active.
        # NOTE: "k" is the last value from the previous for loop
        # only for the purpose of having a valid index. The assumption
        # here is that for all values of "blk[k]", the attribute exists.
        if (
            (k.config.has_phase_equilibrium)
            or (k.config.parameters.config.valid_phase == ("Liq", "Vap"))
            or (k.config.parameters.config.valid_phase == ("Vap", "Liq"))
        ):
    
            with idaeslog.solver_log(solve_log, idaeslog.DEBUG) as slc:
                res = solve_indexed_blocks(opt, [blk], tee=slc.tee)
    
        else:
            res = "skipped"
        init_log.info("Initialization Step 1 {}.".format(idaeslog.condition(res)))
    
        # Continue initialization sequence and activate select constraints
        for k in blk.values():
            for c in k.component_objects(Constraint):
                if c.local_name in [
                    "eq_total",
                    "eq_comp",
                    "eq_phase_equilibrium",
                ]:
                    c.activate()
            if k.config.parameters.config.activity_coeff_model != "Ideal":
                # assume ideal and solve
                k.activity_coeff_comp.fix(1)
    
        # Second solve for the active constraints
        with idaeslog.solver_log(solve_log, idaeslog.DEBUG) as slc:
            res = solve_indexed_blocks(opt, [blk], tee=slc.tee)
        init_log.info("Initialization Step 2 {}.".format(idaeslog.condition(res)))
    
        # Activate activity coefficient specific constraints
        for k in blk.values():
            if k.config.parameters.config.activity_coeff_model != "Ideal":
                for c in k.component_objects(Constraint):
                    if c.local_name in ["eq_Gij_coeff", "eq_A", "eq_B"]:
                        c.activate()
    
        with idaeslog.solver_log(solve_log, idaeslog.DEBUG) as slc:
            res = solve_indexed_blocks(opt, [blk], tee=slc.tee)
        init_log.info("Initialization Step 3 {}.".format(idaeslog.condition(res)))
    
        for k in blk.values():
            if k.config.parameters.config.activity_coeff_model != "Ideal":
                k.eq_activity_coeff.activate()
                k.activity_coeff_comp.unfix()
    
        with idaeslog.solver_log(solve_log, idaeslog.DEBUG) as slc:
            res = solve_indexed_blocks(opt, [blk], tee=slc.tee)
        init_log.info("Initialization Step 4 {}.".format(idaeslog.condition(res)))
    
        for k in blk.values():
            for c in k.component_objects(Constraint):
                if c.local_name in ["eq_enth_mol_phase", "eq_entr_mol_phase"]:
                    c.activate()
    
        with idaeslog.solver_log(solve_log, idaeslog.DEBUG) as slc:
            res = solve_indexed_blocks(opt, [blk], tee=slc.tee)
        init_log.info("Initialization Step 5 {}.".format(idaeslog.condition(res)))
    
        if not check_optimal_termination(res):
>           raise InitializationError(
                f"{blk.name} failed to initialize successfully. Please check "
                f"the output logs for more information."
            )
E           idaes.core.util.exceptions.InitializationError: fs.M01.inlet_2_state failed to initialize successfully. Please check the output logs for more information.

../../../../miniforge3/envs/test-idaes-2.6/lib/python3.12/site-packages/idaes/models/properties/activity_coeff_models/activity_coeff_prop_pack.py:679: InitializationError
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Captured log call -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
WARNING  pyomo.repn.plugins.nl_writer:nl_writer.py:451 model contains export suffix 'scaling_factor' that contains 9 component keys that are not exported as part of the NL file.  Skipping.
WARNING  pyomo.repn.plugins.nl_writer:nl_writer.py:451 model contains export suffix 'scaling_factor' that contains 7 component keys that are not exported as part of the NL file.  Skipping.
WARNING  pyomo.repn.plugins.nl_writer:nl_writer.py:451 model contains export suffix 'scaling_factor' that contains 7 component keys that are not exported as part of the NL file.  Skipping.
WARNING  pyomo.repn.plugins.nl_writer:nl_writer.py:451 model contains export suffix 'scaling_factor' that contains 7 component keys that are not exported as part of the NL file.  Skipping.
WARNING  pyomo.repn.plugins.nl_writer:nl_writer.py:451 model contains export suffix 'scaling_factor' that contains 5 component keys that are not exported as part of the NL file.  Skipping.
WARNING  pyomo.repn.plugins.nl_writer:nl_writer.py:451 model contains export suffix 'scaling_factor' that contains 9 component keys that are not exported as part of the NL file.  Skipping.
WARNING  pyomo.repn.plugins.nl_writer:nl_writer.py:451 model contains export suffix 'scaling_factor' that contains 7 component keys that are not exported as part of the NL file.  Skipping.
WARNING  pyomo.repn.plugins.nl_writer:nl_writer.py:451 model contains export suffix 'scaling_factor' that contains 7 component keys that are not exported as part of the NL file.  Skipping.
WARNING  pyomo.repn.plugins.nl_writer:nl_writer.py:451 model contains export suffix 'scaling_factor' that contains 7 component keys that are not exported as part of the NL file.  Skipping.
WARNING  pyomo.repn.plugins.nl_writer:nl_writer.py:451 model contains export suffix 'scaling_factor' that contains 5 component keys that are not exported as part of the NL file.  Skipping.
WARNING  pyomo.core:PyomoModel.py:212 Loading a SolverResults object with a warning status into model.name="ScalarBlock";
  - termination condition: infeasible
  - message from solver: Ipopt 3.13.2\x3a Converged to a locally infeasible point. Problem may be infeasible.
_____________________________________________________________________________________________________________________________________________________________________________ test_solve_flowsheet ______________________________________________________________________________________________________________________________________________________________________________

model = <pyomo.core.base.PyomoModel.ConcreteModel object at 0x1196f47d0>

    @pytest.mark.unit
    def test_solve_flowsheet(model):
        solve_flowsheet(model)
    
>       assert model.fs.M01.outlet.flow_mol[0].value == pytest.approx(2.0, 1e-4)
E       AssertionError

../../../../miniforge3/envs/test-idaes-2.6/lib/python3.12/site-packages/idaes/models/flowsheets/tests/test_demo_flowsheet.py:96: AssertionError
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Captured log call -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
WARNING  pyomo.repn.plugins.nl_writer:nl_writer.py:451 model contains export suffix 'scaling_factor' that contains 47 component keys that are not exported as part of the NL file.  Skipping.
WARNING  pyomo.repn.plugins.nl_writer:nl_writer.py:463 model contains export suffix 'scaling_factor' that contains 14 keys that are not Var, Constraint, Objective, or the model.  Skipping.
=============================================================================================================================================================================== warnings summary ================================================================================================================================================================================
<frozen importlib._bootstrap>:530: 10 warnings
  <frozen importlib._bootstrap>:530: DeprecationWarning: the load_module() method is deprecated and slated for removal in Python 3.12; use exec_module() instead

../../../../miniforge3/envs/test-idaes-2.6/lib/python3.12/site-packages/idaes/core/util/env_info.py:22
  /Users/shengpang/miniforge3/envs/test-idaes-2.6/lib/python3.12/site-packages/idaes/core/util/env_info.py:22: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
    import pkg_resources

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
============================================================================================================================================================================ short test summary info ============================================================================================================================================================================
FAILED models/flowsheets/tests/test_demo_flowsheet.py::test_initialize_flowsheet - idaes.core.util.exceptions.InitializationError: fs.M01.inlet_2_state failed to initialize successfully. Please check the output logs for more information.
FAILED models/flowsheets/tests/test_demo_flowsheet.py::test_solve_flowsheet - AssertionError
@ksbeattie ksbeattie added the Priority:Normal Normal Priority Issue or PR label Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority:Normal Normal Priority Issue or PR
Projects
None yet
Development

No branches or pull requests

3 participants