Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/pycropml/cyml.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from pycropml.transpiler.antlr_py.fortran.run import run_fortran
from pycropml.transpiler.antlr_py.python.run import run_python
from pycropml.transpiler.antlr_py.apsim.run import run_apsim
from pycropml.transpiler.antlr_py.csharp.run import run_csharp
from pycropml import render_cyml, nameconvention
from pycropml.pparse import model_parser
from pycropml.writeTest import WriteTest
Expand Down Expand Up @@ -68,7 +69,7 @@
"sirius2": 'cs'
}

cymltx_languages = ['dssat', "simplace", "bioma", "openalea", "f90", "stics", "py", "apsim"]
cymltx_languages = ['dssat', "simplace", "bioma", "openalea", "f90", "stics", "py", "apsim","cs"]
langs = ["cs", "cpp", "java", "f90", "r", "py"]

domain_class = ["cs", "java", "sirius", "cpp", "cpp2", "bioma", "sirius2", "apsim"]
Expand Down
30 changes: 17 additions & 13 deletions src/pycropml/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,23 @@ def __init__(self, name, pkg=None):
self.pkg = input(f"Give the path of package {self.name}")
self.data = Path(self.pkg)/"crop2ml"
self.diff_in, self.diff_out = {}, {}
composite_file = self.data.glob("composition*.xml")[0]
self.mu = model_parser(self.pkg)
self.model, = composition.model_parser(composite_file)
self.pkgs[self.name] = [self.pkg, self.model]
self.model.inputs = self.meta_inp(self.name)
self.model.outputs = self.meta_out(self.name)
self.model.ext = self.meta_ext(self.name)
self.model.states = self.findstates(self.model.inputs, self.model.outputs)
self.model.path = Path(self.pkg)
self.minout()
self.path_pkg = None
self.model.diff_in = self.diff_in
self.model.diff_out = self.diff_out
composite_file = None
composite_files = self.data.glob("composition*.xml")
if composite_files:
composite_file = composite_files[0]
self.mu = model_parser(self.pkg)
self.model, = composition.model_parser(composite_file)
self.pkgs[self.name] = [self.pkg, self.model]
self.model.inputs = self.meta_inp(self.name)
self.model.outputs = self.meta_out(self.name)
self.model.ext = self.meta_ext(self.name)
self.model.states = self.findstates(self.model.inputs, self.model.outputs)
self.model.path = Path(self.pkg)
self.minout()
self.path_pkg = None
self.model.diff_in = self.diff_in
self.model.diff_out = self.diff_out
self.composite_file = composite_file

def isPackage(self, name):
if sys.version_info[0] >= 3:
Expand Down
20 changes: 9 additions & 11 deletions src/pycropml/transpiler/antlr_py/apsim/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import absolute_import
from __future__ import print_function
from os.path import isdir
from path import Path
import os
from pycropml.transpiler.antlr_py.to_CASG import to_dictASG, to_CASG
Expand Down Expand Up @@ -236,9 +237,6 @@ def action_custom_call(self, tree):

if len(trees.args) != len(inps):
trees.args.extend(inps[len(trees.args):])
"""if f.name == "Divide":
print("Divideeeeeeee", [t.y for t in inps])
print("Divide", [t.y for t in trees.args])"""
for num1, ar1 in enumerate(trees.args):
for num2, ar2 in enumerate(inps):
if num1 == num2:
Expand Down Expand Up @@ -573,19 +571,19 @@ def action_for_statement(self, tree):

def create_package(output):
crop2ml_rep = Path(os.path.join(output, 'crop2ml'))
if not crop2ml_rep.isdir():
if not isdir(crop2ml_rep):
crop2ml_rep.mkdir()
algo_rep = Path(os.path.join(crop2ml_rep, 'algo'))
if not algo_rep.isdir():
if not isdir(algo_rep):
algo_rep.mkdir()
cyml_rep = Path(os.path.join(algo_rep, 'pyx'))
if not cyml_rep.isdir():
if not isdir(cyml_rep):
cyml_rep.mkdir()
return crop2ml_rep, cyml_rep





def function_dependency(st, f):
r = [f]
z = ApsimExtraction()
Expand Down Expand Up @@ -684,8 +682,6 @@ def run_apsim(component, output):

files = repowalk.walk(component, "cs" )
xfiles = repowalk.walk(component, "xml" )
modelp = ModelParser()
mp = modelp.parse(component)
res = {}
stra = {}
straNames = []
Expand Down Expand Up @@ -735,7 +731,6 @@ def run_apsim(component, output):
kk = ApsimExtraction()
#all_var = kk.getAllVar(vinfo)
all_var = extract_io(list(xfiles.values())[0])
#print("all", all_var)
for k, st in enumerate(strats):
print(k, st)
mod = source_codes[k]
Expand Down Expand Up @@ -945,10 +940,13 @@ def run_apsim(component, output):
description["url"] = ""
description["ExtendedDescription"]="Soil Temperature"
description["ShortDescription"]="Soil Temperature"

modelp = ModelParser()
mp = modelp.parse(output)
mc = createObjectCompo(description,mp)

xml_ = Pl2Crop2ml(mc, "APSIM_").run_compo()
filename = os.path.join(pkg, "crop2ml", "composition.%s.xml"%(mp[0].name))
filename = os.path.join(output, "crop2ml", "composition.%s.xml"%(mp[0].name))
with open(filename, "wb") as xml_file:
r = '<?xml version="1.0" encoding="UTF-8"?>\n'
r += '<!DOCTYPE ModelComposition PUBLIC " " "https://raw.githubusercontent.com/AgriculturalModelExchangeInitiative/crop2ml/master/ModelComposition.dtd">\n'
Expand Down
3 changes: 2 additions & 1 deletion src/pycropml/transpiler/antlr_py/bioma/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"DATELIST":"List",
"BOOLEAN":"bool",
"DOUBLEARRAY":"array",
"INTARRAY":"array"}
"INTARRAY":"array",
"STRINGARRAY":["array", "string"]}

pseudo_type_={
"DOUBLE":"double",
Expand Down
2 changes: 1 addition & 1 deletion src/pycropml/transpiler/antlr_py/createXml.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def run_unit(self):
def run_compo(self):
""" Generate Crop2ML specification of a CompositeModel from a workflow. """
md = self.md
name = md.name[:-9] if md.name.endswith("Component") else md.name
name = md.name.replace("Component", "") if md.name.endswith("Component") else md.name
# ModelComposition name id version timestep
xml = ns.ModelComposition(name=name, id=self.pkgname + "." + name, version=md.version, timestep=md.timestep)

Expand Down
9 changes: 7 additions & 2 deletions src/pycropml/transpiler/antlr_py/csharp/api_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,8 @@ def integr_expander(type, message, args):

},
'array':{
'array': StandardMethodCall('numpy', 'array', expander = array_expander )
'array': StandardMethodCall('numpy', 'array', expander = array_expander ),
'ConstrainedCopy': StandardMethodCall('array', 'constrained_copy', expander = constrained_copy_expander)
} ,
'Array':{
'Copy': StandardMethodCall('array', 'copy', expander = copyarray_expander ),
Expand Down Expand Up @@ -391,7 +392,8 @@ def integr_expander(type, message, args):
'append': StandardMethodCall('array', 'append'),
'Length': StandardMethodCall('array', 'len', expander=len_expander),
'CopyTo': StandardMethodCall('array', 'copyto', expander=copyto_expander),
'Except': StandardMethodCall('array', 'except')
'Except': StandardMethodCall('array', 'except')#,
#'ConstrainedCopy': StandardMethodCall('array', 'ConstrainedCopy')
},

'tuple': {
Expand All @@ -405,6 +407,9 @@ def integr_expander(type, message, args):
},
"array":{
"Length": StandardMethodCall("array", "len", expander=len_expander)
},
"Array":{
"Length": StandardMethodCall("array", "len", expander=len_expander)
}

}
Expand Down
2 changes: 1 addition & 1 deletion src/pycropml/transpiler/antlr_py/csharp/cs_cyml.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def visit_array(self, node):
return res

def visit_List(self, node):
if "value" not in dir(node) and "elements" not in dir(node):
if "init" not in dir(node) and "value" not in dir(node) and "elements" not in dir(node):
z = []
elif "elements" in dir(node):
z = self.visit(node.elements)
Expand Down
Loading
Loading