Skip to content

Commit 4d3ab3b

Browse files
explicitly supports only one cas for CompileInput
1 parent 3ff3a4b commit 4d3ab3b

File tree

3 files changed

+7
-13
lines changed

3 files changed

+7
-13
lines changed

.github/workflows/examples.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
shell: bash
3232
- run: pip3 install -r https://raw.githubusercontent.com/Funz/Funz.py/master/requirements.txt
3333
- run: pip3 install git+https://github.com/Funz/Funz.py
34-
- 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
34+
- 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
3535
shell: bash
3636
- if: matrix.os == 'windows-latest'
3737
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

Funz/client.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,16 +186,13 @@ def CompileInput(model,input_files,input_values,output_dir="."):
186186
""" Convenience method to compile variables in parametrized file.
187187
@param model name of the code wrapper to use. See .Funz.Models global var for a list of possible values.
188188
@param input_files files to give as input for the code.
189-
@param input_values list of variable values to compile.
189+
@param input_values list of variables value to compile (one value per variable).
190190
@param output_dir directory where to put compiled files.
191191
@export
192192
@examples
193193
Funz.CompileInput(model = "Python",
194194
input_files = os.path.join(Funz.FUNZ_HOME,"samples","branin.py"),
195195
input_values = {'x1':0.5, 'x2':0.6})
196-
Funz.CompileInput(model = "Python",
197-
input_files = os.path.join(Funz.FUNZ_HOME,"samples","branin.py"),
198-
input_values = {'x1':[0.5,.55], b=[0.6,.7]})
199196
"""
200197
return(Funz_CompileInput(model=model,input_files=input_files,input_values=input_values,output_dir=output_dir))
201198

Funz/inst/Funz/Funz.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -950,19 +950,16 @@ def Funz_CompileInput(model,input_files,input_values,output_dir=".") :
950950
if isinstance(vals,numpy.ndarray): # convert to standard python arrays
951951
vals = vals.tolist()
952952
if isinstance(vals,list):
953-
if len(vals)>0:
954-
JMapinput_values.put(key, _JArray([str(v) for v in vals],"java.lang.String"))
953+
if len(vals)==1:
954+
JMapinput_values.put(key, str(vals[0]))
955955
else:
956-
JMapinput_values.put(key, _JArray([],"java.lang.String"))
956+
raise Exception("CompileInput supports only one value per variable.")
957957
else:
958-
JMapinput_values.put(key, _JArray([str(vals)],"java.lang.String"))
958+
JMapinput_values.put(key, str(vals))
959959
#JMapinput_values.put(key, str(input_values[key]).replace("[","{").replace("]","}")) # because funz waits for the array of values between{}
960960

961961
output_dir = os.path.realpath(output_dir)
962-
print(JMapinput_values)
963-
for key in JMapinput_values.keys():
964-
print(key)
965-
print(JMapinput_values.get(key))
962+
966963
return(_jclassUtils.compileVariables("" if model is None else model,JArrayinput_files,JMapinput_values,_jclassFile(output_dir)))
967964

968965

0 commit comments

Comments
 (0)