Git Product home page Git Product logo

pycrop2ml's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

pycrop2ml's Issues

cyml fail when src does not exist

File "/Users/pradal/devlp/git/pycropml/src/pycropml/cyml.py", line 74, in main
   m2p.generate_package()        # generate cyml models in "pyx" directory          
 File "/Users/pradal/devlp/git/pycropml/src/pycropml/render_cyml.py", line 73, in generate_package
   self.dir = directory.mkdir()
 File "/Users/pradal/miniconda2/envs/crop2ml/lib/python2.7/site-packages/path.py", line 1199, in mkdir
   os.mkdir(self, mode)

using special character creates error ?

I received the following error trying to open a model unit that I created with jupyterlab. Maybe because I used special characters (French accented characters) in the model description. It was saved without raising an error, but could not be opened again. There should be checks on the user's inputs so that it does not create errors later.


Exception Traceback (most recent call last)
/opt/conda/lib/python3.7/site-packages/pycrop2ml_ui/menus/edition/editunit.py in _parse(self)
165 self._out2.clear_output()
166 with self._out:
--> 167 raise Exception('Critical error while parsing the file.')
168
169 self._buildEdit()

Exception: Critical error while parsing the file.
./packages/multiplication/crop2ml/unit.modelunit.xml is NOT in CropML Format ! no element found: line 1, column 0

AttributeError Traceback (most recent call last)
/opt/conda/lib/python3.7/site-packages/pycrop2ml_ui/menus/edition/editmenu.py in _eventEdit(self, b)
66 unit = editunit.editUnit({'Path': os.path.join(self._modelPath.value, 'crop2ml'), 'Model type': typemodel[0], 'Model name': typemodel[1]}, self.local)
---> 67 unit.displayMenu()
68 except:

/opt/conda/lib/python3.7/site-packages/pycrop2ml_ui/menus/edition/editunit.py in displayMenu(self)
1040
-> 1041 self._parse()
1042

/opt/conda/lib/python3.7/site-packages/pycrop2ml_ui/menus/edition/editunit.py in _parse(self)
168
--> 169 self._buildEdit()
170

/opt/conda/lib/python3.7/site-packages/pycrop2ml_ui/menus/edition/editunit.py in _buildEdit(self)
62
---> 63 self._datas['Old name'] = self._xmlfile.name
64 self._modelname.value = self._xmlfile.name

AttributeError: 'NoneType' object has no attribute 'name'

During handling of the above exception, another exception occurred:

Exception Traceback (most recent call last)
/opt/conda/lib/python3.7/site-packages/pycrop2ml_ui/menus/edition/editmenu.py in _eventEdit(self, b)
67 unit.displayMenu()
68 except:
---> 69 raise Exception('Could not load unit model edition menu.')
70
71 else:

Exception: Could not load unit model edition menu.
โ€‹
0

Refactoring PyCropML

Restructure render_python, render_java, render_csharp and render_notebook... to improve PyCropML readability and to have a good architecture.

Model composition in CropML

Add the composition of models in xml/dtd.
The composition follows the composite design pattern.

A model is either:

  • a model uint(atomic)
  • or a model composite , that is a model that is composed of models ( unit or composite)

The composition is represented as a directed port graph of models:

  • Vertices are the different models that form the composition.
  • Ports are the inputs and outputs of each model.
  • Edges are directed and connect one output port to an input port of another model.

A description of such workflow or composite model can be found at https://github.com/openalea/wlformat

Generation of a Python package

Python Package generation

Based on a repository containing xml declaration files, generate a Python package.

The Python package must contains:

  1. A src directory with a python module per ModelUnit. Each algorithm is a Python function of class.

  2. A wralea.py file containing (or generated from) the ModelUnit description

  3. A test directory that contains for tests from the ModelUnit

    • Tests may be also store in the documentation and run using doc tests
  4. We may generate automagically the setup.py file using OpenAlea tools

Module generation for composite

In Fortran, a module has to be generated from the

From a package, generate:

  • a module in Fortran
  • a namespace in C++
  • a package in Pythonl
    For a composite:
  • a module in Fortran
  • a class in C#, Java
  • a function in Python or a functor in C++

If a composite is defined as a graph, each edge has to be translated into a variable, and each vertex is a call of a function/functor.
Using a traversal of the graph from inputs to outputs, call the different functions in that order.

OpenAlea Integration

When the Python package is generated, extend it with OpenAlea package.
Run it inside OpenAlea.

Python package generation

Generate a real Python package:

  • Define a specific name for the package
  • Add init.py to have a package
  • Generate a Python package with a setup.py, test directory, ...

Add tests to the package

Add test to check on the example:

  • Retrieve all the fields (inputs, outputs)
    • number, values
    • type conversion (for params int or float values)
  • Make the connection between data and reference
    • parametersets can be given as data, or as reference to an already define parameterset

CI is failling

unyt dependency is not found. Add conda-forge as a channel dependency

Full transformation from XML to an object model

Currently, objects are created from XML.
However, the parsing is incomplete.
Define the full conceptual object model, and then fill it from xml.

Moreover, generate xml files from the objects.

Translation issue for handling brackets which behinds "/โ€œ or "-"

I got translation result which improperly removed brackets used in the calculation as below.

pyx code:
RLINIT = WTNEW * FRRT * PLTPOP * RFAC1 * DEP / ( RTDEP * 10000 )

generated f90 code
RLINIT = WTNEW * FRRT * PLTPOP * RFAC1 * DEP / RTDEP * 10000

the brackets should be kept if it appears after divided or minus operation.

Jupyter Notebook

Enhance integration of PyCropMl with Jupyter Notebooks:

  • Add widgets to interact with the model
  • Add metainformation to be able to reconstruct the xml
  • Add a text cell or an xml one (if this exists) with the content of the xml (or json) file.

Ideas:

  • User can play with the code
  • Notebook can also be thinked as a new GUI with the model
  • Code generation can be driven from the notebook

Plugin architecture with code generation

Define a plugin architecture. Each plugin implement a strategy.
Strategies are generators of Python, C++ and C# libraries.
And OpenAlea, RECORD, Sirius, BioMA components.

Strategies will transform the conceptual object model into the target using templating engines (Jinja2 or Mako).

Operation translation cyml to fortran

program test
integer ::a=4
integer :: b=5
real c
c=a/b ! transform it to c=real(a)/b
print *, c
end program

We got 0 as result.
Need to improve operation translation. The problem is not just brackets

Translated Array variable in test case for F90 has syntax error

Following is the input XML for translation, generated test case code, compiler error for the generated code and revision of code for passing the compiling.

*XML:
[5,5,10,10,20,20,40,40,0,0]

*Generated F90 test case code:
INTEGER:: NL
REAL, ALLOCATABLE, DIMENSION(NL) :: DLAYR
....
NL = 10
DLAYR = [5,5,10,10,20,20,40,40,0,0]

*Compiler error message:
REAL, ALLOCATABLE, DIMENSION(NL) :: DLAYR
1
Error: Explicit shaped array with nonconstant bounds at (1)

 DLAYR = [5,5,10,10,20,20,40,40,0,0]
1

Error: Incompatible ranks 0 and 1 in assignment at (1)

  • Revised code:
    REAL, DIMENSION(10) :: DLAYR = [5,5,10,10,20,20,40,40,0,0]

Formalism Crop2ML for units

Is there a formalism to write units in the documentation ? For example for exponents (squared, cubed, ...), dates, initials or whole word, etc.

Notebook generation

Notebook generation

Notebook generation to interact and view models and model units
A Notebook can be generated from the models description. This will allow to test, visualise both the description and the model code, as well as execute the model on parametersets and run the tests.

Tools

To generate a Notebook, use nbformat (http://nbformat.readthedocs.io).

Method

Add cells for model units, documentation to render the description and the math of the model, as well as interactors based on metainformation.

Add also cells that test the Model Unit.

Use Case

Define a simple but realistic use case

convert xml to json - simplify function calls

Objectives:
[ ] implement a class that parses xml file and transform it in json
[ ] Define the JSON schema in json and validate it using jsonschema
[ ] a function that calls parsing and render in order to access xml files for notebook generation
(Review render structure)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.