code-saturne / code_saturne

code_saturne public mirror
https://www.code-saturne.org
GNU General Public License v2.0
225 stars 82 forks source link

cs_studymanager_study.py fails to run #54

Closed paspro closed 4 years ago

paspro commented 4 years ago

When trying to use the studymanager I get the following error:

File "/home/panos/Applications/Code_Saturne/code_saturne-6.0/arch/Linux_x86_64/lib/python3.7/site-packages/code_saturne/studymanager/cs_studymanager_study.py", line 226, in __get_exe
    pkg = package()
UnboundLocalError: local variable 'package' referenced before assignment

Code_Saturne is running under Python 3.7 on my system and the code which causes this problem is the following:

def __get_exe(self, old_pkg, run_ref):
        """
        Return the name of the exe of the case, in order to mix
        Code_Saturne and NEPTUNE_CFD test cases in the same study.
        """

        # Read the runcase script from the Repository

        runcase = cs_runcase.runcase(run_ref)

        if runcase.cmd_name == "code_saturne":
            from cs_package import package
        elif runcase.cmd_name == "neptune_cfd":
            from nc_package import package
        pkg = package()

        return runcase.cmd_name, pkg

This part is problematic because what value does pkg take when none of the if-statements are valid? I fixed this by changing this code to the following:

def __get_exe(self, old_pkg, run_ref):
        """
        Return the name of the exe of the case, in order to mix
        Code_Saturne and NEPTUNE_CFD test cases in the same study.
        """

        # Read the runcase script from the Repository

        runcase = cs_runcase.runcase(run_ref)
        pkg = 0

        if runcase.cmd_name == "code_saturne":
            from cs_package import package
            pkg = package()
        elif runcase.cmd_name == "neptune_cfd":
            from nc_package import package
            pkg = package()

        return runcase.cmd_name, pkg
YvanFournier commented 4 years ago

Are you running the studymanager through the "code_saturne studymanager" command or calling the associated Python script directly ?

pkg should always be defined (in other words, runcase is expected to always contain either code_saturne or neptune_cfd). In which context is this failing ?

To reflect on the fact that package is a more complex object than an integer, an alternative is to replace package = 0 by package = None in your patch.

paspro commented 4 years ago

I am running it using the "code_saturne studymanager" command for a number of test cases as:

code_saturne studymanager -f test.xml -r

and the complete error message is the following:

code_saturne studymanager -f test.xml -r
Error: unable to determine the name of the script for /home/panos/Development/Code_Saturne/Renuda/cases/Pod-Boiler/AUTOVNV_TEST/AUTOVNV_REPOSITORY/JOINING_TESTS/1_2_DUCT_IN_joining/SCRIPTS/runcaseTraceback (most recent call last):
  File "/home/panos/Applications/Code_Saturne/code_saturne/arch/Linux_x86_64/bin/code_saturne", line 76, in <module>
    retcode = cs.execute()
  File "/home/panos/Applications/Code_Saturne/code_saturne-6.0/arch/Linux_x86_64/lib/python3.7/site-packages/code_saturne/cs_script.py", line 93, in execute
    return self.commands[command](options)
  File "/home/panos/Applications/Code_Saturne/code_saturne-6.0/arch/Linux_x86_64/lib/python3.7/site-packages/code_saturne/cs_script.py", line 130, in studymanager
    return cs_studymanager.main(options, self.package)
  File "/home/panos/Applications/Code_Saturne/code_saturne-6.0/arch/Linux_x86_64/lib/python3.7/site-packages/code_saturne/cs_studymanager.py", line 413, in main
    retcode = run_studymanager(pkg, options)
  File "/home/panos/Applications/Code_Saturne/code_saturne-6.0/arch/Linux_x86_64/lib/python3.7/site-packages/code_saturne/cs_studymanager.py", line 298, in run_studymanager
    studies = Studies(pkg, options, exe, dif)
  File "/home/panos/Applications/Code_Saturne/code_saturne-6.0/arch/Linux_x86_64/lib/python3.7/site-packages/code_saturne/studymanager/cs_studymanager_study.py", line 1236, in __init__
    options.debug)] )
  File "/home/panos/Applications/Code_Saturne/code_saturne-6.0/arch/Linux_x86_64/lib/python3.7/site-packages/code_saturne/studymanager/cs_studymanager_study.py", line 840, in __init__
    self.__dest)
  File "/home/panos/Applications/Code_Saturne/code_saturne-6.0/arch/Linux_x86_64/lib/python3.7/site-packages/code_saturne/studymanager/cs_studymanager_study.py", line 208, in __init__
    self.exe, self.pkg = self.__get_exe(pkg, run_ref)
  File "/home/panos/Applications/Code_Saturne/code_saturne-6.0/arch/Linux_x86_64/lib/python3.7/site-packages/code_saturne/studymanager/cs_studymanager_study.py", line 226, in __get_exe
    pkg = package()
UnboundLocalError: local variable 'package' referenced before assignment

So the initial error message says that it cannot determine the name of the 'runcase' script and I don't understand what that means. Is it supposed to determine whether we are running code_saturne or neptune from the runcase script? My script calls code_saturne so what is the problem then?

paspro commented 4 years ago

I think I found the problem. The "runcase" script is supposed to call code_saturne as:

\code_saturne run --param setup.xml

but in my case the script was

code_saturne run --param setup.xml

and it could not understand that I was using code_saturne. I think that this should be fixed to avoid similar errors.

YvanFournier commented 4 years ago

I have a fix, but will probably not be able to push the fix to the main repository before a few days (out of office with limited network access)

YvanFournier commented 4 years ago

Version 6.2 will have a more robust way od dealing with this (runcase generated on the fly, run configuration except for path in run.cfg).

As this seems non-blocking also in prior versions, we can close this issue.