From 4d3ab3b4ec28e4d11f67c9ee8b922e5ace8da5df Mon Sep 17 00:00:00 2001 From: Yann Richet Date: Mon, 2 Dec 2024 18:51:24 +0100 Subject: [PATCH] explicitly supports only one cas for CompileInput --- .github/workflows/examples.yml | 2 +- Funz/client.py | 5 +---- Funz/inst/Funz/Funz.py | 13 +++++-------- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index 5cb366d..ed5a50e 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -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 diff --git a/Funz/client.py b/Funz/client.py index 3801df9..83df482 100644 --- a/Funz/client.py +++ b/Funz/client.py @@ -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)) diff --git a/Funz/inst/Funz/Funz.py b/Funz/inst/Funz/Funz.py index bd2e1e7..c114fca 100755 --- a/Funz/inst/Funz/Funz.py +++ b/Funz/inst/Funz/Funz.py @@ -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)))