Skip to content

Commit

Permalink
explicitly supports only one cas for CompileInput
Browse files Browse the repository at this point in the history
  • Loading branch information
yannrichet-irsn authored Dec 2, 2024
1 parent 3ff3a4b commit 4d3ab3b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
shell: bash
- run: pip3 install -r https://raw.githubusercontent.com/Funz/Funz.py/master/requirements.txt
- run: pip3 install git+https://github.com/Funz/Funz.py
- run: python3 -c "import Funz, os, numpy; Funz.CompileInput(model = 'Python',input_files = os.path.join(Funz.FUNZ_HOME,'samples','branin.py'),input_values = {'x1':numpy.arange(0,1,0.2),'x2':numpy.arange(0,1,0.2)},output_dir='${{matrix.os}}-Python${{matrix.Python}}/CompileInput')" > ${{matrix.os}}-Python${{matrix.Python}}/CompileInput.out
- run: python3 -c "import Funz, os, numpy; Funz.CompileInput(model = 'Python',input_files = os.path.join(Funz.FUNZ_HOME,'samples','branin.py'),input_values = {'x1':0.2,'x2':0.2},output_dir='${{matrix.os}}-Python${{matrix.Python}}/CompileInput')" > ${{matrix.os}}-Python${{matrix.Python}}/CompileInput.out
shell: bash
- if: matrix.os == 'windows-latest'
run: python3 -c "import Funz, os, re; f=open(os.path.join(Funz.FUNZ_HOME,'calculator.xml'), 'r+'); text = f.read(); text = re.sub('.sh', '.bat', text); f.seek(0); f.write(text); f.truncate()" > ${{matrix.os}}-Python${{matrix.Python}}/install.out
Expand Down
5 changes: 1 addition & 4 deletions Funz/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,13 @@ def CompileInput(model,input_files,input_values,output_dir="."):
""" Convenience method to compile variables in parametrized file.
@param model name of the code wrapper to use. See .Funz.Models global var for a list of possible values.
@param input_files files to give as input for the code.
@param input_values list of variable values to compile.
@param input_values list of variables value to compile (one value per variable).
@param output_dir directory where to put compiled files.
@export
@examples
Funz.CompileInput(model = "Python",
input_files = os.path.join(Funz.FUNZ_HOME,"samples","branin.py"),
input_values = {'x1':0.5, 'x2':0.6})
Funz.CompileInput(model = "Python",
input_files = os.path.join(Funz.FUNZ_HOME,"samples","branin.py"),
input_values = {'x1':[0.5,.55], b=[0.6,.7]})
"""
return(Funz_CompileInput(model=model,input_files=input_files,input_values=input_values,output_dir=output_dir))

Expand Down
13 changes: 5 additions & 8 deletions Funz/inst/Funz/Funz.py
Original file line number Diff line number Diff line change
Expand Up @@ -950,19 +950,16 @@ def Funz_CompileInput(model,input_files,input_values,output_dir=".") :
if isinstance(vals,numpy.ndarray): # convert to standard python arrays
vals = vals.tolist()
if isinstance(vals,list):
if len(vals)>0:
JMapinput_values.put(key, _JArray([str(v) for v in vals],"java.lang.String"))
if len(vals)==1:
JMapinput_values.put(key, str(vals[0]))
else:
JMapinput_values.put(key, _JArray([],"java.lang.String"))
raise Exception("CompileInput supports only one value per variable.")
else:
JMapinput_values.put(key, _JArray([str(vals)],"java.lang.String"))
JMapinput_values.put(key, str(vals))
#JMapinput_values.put(key, str(input_values[key]).replace("[","{").replace("]","}")) # because funz waits for the array of values between{}

output_dir = os.path.realpath(output_dir)
print(JMapinput_values)
for key in JMapinput_values.keys():
print(key)
print(JMapinput_values.get(key))

return(_jclassUtils.compileVariables("" if model is None else model,JArrayinput_files,JMapinput_values,_jclassFile(output_dir)))


Expand Down

0 comments on commit 4d3ab3b

Please sign in to comment.