Code Monkey home page Code Monkey logo

modeltranslator's Introduction




Carthage compatible Carthage compatible Carthage compatible Carthage compatible Carthage compatible

MODEL TRANSLATOR


Translate XML model into Python code
Visit our website for full documentation »

View current process · Report Bug · Request Feature



TABLE OF CONTENTS

  1. About the Project
  2. Getting Started
  3. Current Features
  4. Usage/Application
  5. Roadmap
  6. Coding Style Convention
  7. License
  8. Contact


About The Project

This project will assist developers in implementing custom IoT systems.

Here's why you should use this:

  • Users who want to design automata system with UPPAAL
  • Users who want their modeled diagrams to run on a Rasberry Pi device
  • Users who want to test out IoT environment with the modeling tool (UPPAAL)

(back to top)

Tools Used With (Translator)


Getting Started

Prerequisites

Download UPPAAL to create your model

Demo Installation

  1. Clone the repo

    git clone https://github.com/TCC2021SeniorProject/ModelTranslator.git
  2. Download XML examples

  3. Run Main.py program

     cd ./MdoelTranslator/src

Current Features

  • The translator can handle the below features from UPPAAL

    • Identifies Start and End node by name (This feature will be changed to tag identification)
    • Change UPPAAL XML into abstract graph structure
    • Parse given global declaration from UPPAAL to variables
  • General features:

    • Handling multiple transitions
    • Identifiying classes, nodes, transitions
    • Handling system scripts
    • Handling sync broadcasting and respoding
    • Handling parameters
    • Access of gloabal fields
  • Template:

    • Stores every objects: transitions, nodes, local fields, etc.
  • Transition:

    • Select (name)
    • Guard (conditionals)
    • Assignment (variable update in local)
    • Sync
    • Conditional statement conversion(UPPAAL syntax -> Python syntax)
    • Locate linked node sources
  • Node

    • Node's name as function definition in Python
    • Transition's destination is a function call


Roadmap

For more plans, please see the plan documentation.

Current Tasks. (Due Jan 2022)

See current task list

  • Fully implement operational and conditional statement converter
    • Implement converter
    • Fix potential bugs & issues.
    • Identify variables.

  • Refactor packages(modules) structures to do only relative jobs
    • Object package only holds class data
    • Parser package holds only relavant modules
      • Components package only does parsing job
      • Syntax package only converts syntactical string
    • Translator package only translates objects into python scripts
    • Main.py only runs a root module of the packages.

  • Accept parameters on sender and on receiver
  • [-] Implement access of global variables from local field


Previous Tasks
    First Tasks

    First Task - Aug 2021 ~ Oct 2021

    • Update mark down documentation.
    • Create mock Python code output.
    • Make UPPAAL parser.
    • Program is able to traverse all the nodes through tranistion objects.
    • Program is able to identify the validity of the model.
    • Program is able to validate the node function (e.g. starting node, termination node, logic node, process node, etc)
    • Make Python code generator/converter.
    • Test simple diagram.

    Second Tasks

    Task 2 check list - Oct 2021 ~ Nov 2021.

    • Make complex diagram 1
    • Update(enhance) UPPAAL parser
    • Update(enhance) Python code generator/converter
    • Test complex diagram 1
    • Update (enhance) UPPAAL parser
    • Update (enhance) Python code generator/converter
    • Test complex diagram 1

See the open issues for a full list of proposed features (and known issues).

Testing schedules

    General testing Schedules

    • Test case 1 (Due Oct 9): Produce code from a simple model
    • Test case 2 (Due Oct 17): Model comparatively massive size diagram
    • Test case 3 (Due Oct 23): Build infinite loops / Redundant transitions.
    • Test case 4-1 (Due Nov 21): Change models to python codes that MCCD accepts.
    • Test case 4-2 (Due Jan 20): Create executable model.
    • Test case 7 (Due Feb 1): Create a web application version of translator.
    • Test case 8 (Due Feb 29): Check main control device can be postponed until specified device finishes its current job

Example of how software works


1. Build your own model in UPPAAL

Templates


Global declaration


System declaration


First template


Second template


Third template



2. XML input of UPPAAL model

Expand to see the code

  <?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE nta PUBLIC '-//Uppaal Team//DTD Flat System 1.1//EN' 'http://www.it.uu.se/research/group/darts/uppaal/flat-1_2.dtd'>
<nta>
	<declaration>// Global declaration(s)
int[1,2] status;
int battery;
chan check_mode;
</declaration>
	<template>
		<name x="0" y="0">all_tran_example</name>
		<parameter>int &amp;mode, int &amp;charge</parameter>
		<declaration>// Place local declarations here.</declaration>
		<location id="id0" x="-1411" y="-425">
			<name x="-1428" y="-459">Idle</name>
		</location>
		<location id="id1" x="-1173" y="-425">
			<name x="-1190" y="-459">Run</name>
		</location>
		<location id="id2" x="-935" y="-425">
			<name x="-952" y="-459">Dock</name>
		</location>
		<init ref="id0"/>
		<transition>
			<source ref="id2"/>
			<target ref="id0"/>
			<label kind="assignment" x="-1207" y="-340">mode = 0</label>
			<nail x="-1020" y="-340"/>
			<nail x="-1360" y="-340"/>
		</transition>
		<transition>
			<source ref="id1"/>
			<target ref="id2"/>
			<label kind="guard" x="-1139" y="-425">mode == 4 || charge &lt; 10</label>
		</transition>
		<transition>
			<source ref="id0"/>
			<target ref="id1"/>
			<label kind="guard" x="-1377" y="-425">mode == 1 &amp;&amp; charge &gt; 10</label>
			<label kind="synchronisation" x="-1326" y="-442">check_mode?</label>
		</transition>
	</template>
	<template>
		<name>clean</name>
		<parameter>int &amp;mode</parameter>
		<location id="id3" x="-629" y="-272">
			<name x="-646" y="-306">Clean</name>
		</location>
		<location id="id4" x="-773" y="-272">
		</location>
		<init ref="id4"/>
		<transition>
			<source ref="id4"/>
			<target ref="id3"/>
			<label kind="guard" x="-748" y="-272">mode == 3</label>
			<label kind="synchronisation" x="-748" y="-289">check_mode!</label>
		</transition>
	</template>
	<template>
		<name>explore</name>
		<parameter>int &amp;mode</parameter>
		<location id="id5" x="-850" y="-493">
			<name x="-867" y="-527">Explore</name>
		</location>
		<location id="id6" x="-1020" y="-493">
		</location>
		<init ref="id6"/>
		<transition>
			<source ref="id6"/>
			<target ref="id5"/>
			<label kind="guard" x="-986" y="-493">mode == 2</label>
			<label kind="synchronisation" x="-986" y="-510">check_mode!</label>
		</transition>
	</template>
	<system>// Template instantiation(s)
Roomba = all_tran_example(status, battery);
// Processe(s) to be composed into a system(s)
system Roomba;
    </system>
	<queries>
		<query>
			<formula></formula>
			<comment></comment>
		</query>
	</queries>
</nta>



3. Auto-generated output in python:

    Expand to see the code

    import asyncio
    
    status = 0
    battery = 0
    check_mode = None #Channel variable
    
    class all_tran_example:
    	def __init__(self, mode, charge, ):
    		self.mode = mode
    		self.charge = charge
    
    	async def Dock(self):
    		await self.Idle()
    
    	async def Run(self):
    		if self.mode == 4 or self.charge < 10:
    			await self.Dock()
    
    	async def Idle(self):
    		if self.mode == 1 and self.charge > 10:
    			await self.Run()
    
    class clean:
    	def __init__(self, mode, ):
    		self.mode = mode
    
    	async def Clean(self):
    		exit()
    
    	async def default_init(self):
    		if self.mode == 3:
    			Roomba.Run()
    			await self.Clean()
    
    class explore:
    	def __init__(self, mode, ):
    		self.mode = mode
    
    	async def Explore(self):
    		exit()
    
    	async def default_init(self):
    		if self.mode == 2:
    			Roomba.Run()
    			await self.Explore()
    
    loop = asyncio.get_event_loop()
    
    Roomba = all_tran_example(status, battery)
    
    loop.run_until_complete(Roomba.Idle())
    



(back to top)

Process logic flow




(back to top)

File structure

├── data
├── docs
├── img
│   └── icon
├── README.md
└── src
    ├── main.py
    ├── objects
    │   ├── global_set.py
    │   ├── node.py
    │   ├── sync.py
    │   ├── system.py
    │   ├── template.py
    │   ├── transition.py
    │   └── variable.py
    ├── parser
    │   ├── components
    │   │   ├── declaration_parser.py
    │   │   ├── node_parser.py
    │   │   ├── system_parser.py
    │   │   └── transition_parser.py
    │   ├── syntax
    │   │   └── cpyparser.py
    │   ├── tag_set.py
    │   └── XML_parser.py
    └── translator
        ├── class_gen.py
        ├── function_gen.py
        ├── py_export.py
        └── script_gen.py

Valid model rule


+Rules before giving an input
  1. A model must be a valid model. The validity of the model can be checked in UPPAAL software. Any invalid UPPAAL model will cause a program crash.
  2. All variables must be defined. Any unidentified variables may cause errors either while using the software (translation) or executing output (Python code).
  3. All variable declarations must be valid, according to its template.
  4. Every node must have a unique identifier. Duplicate identifiers will result in overwriting of functions.

Usage/Application

For more examples, please refer to the Design Documentation.

(back to top)


To view the specific testing details, click here

MCCD refers to Main Control Center Device.

(back to top)

Coding Style Convention

See the following link: Style Guide for Python Code

Follow rules for better readability: Clean Code by Robert C. Martin

Getter first, setter later for function definitions

Only one thing in a function

Consider portability and readability

License

Currently, there is no license for this repo, meaning our team retains all rights to the source code and no one may reproduce, distribute, or create derivative works from our work.

This will not be permanent until the completion of the project.

(back to top)

Contact

Director

Dr. Siddhartha Bhattacharyya
Email: [email protected]

Developers

Sung-Jun Baek
Email: [email protected]
GitHub: MarcoBackman

Caelan Shoop
Email: [email protected]
GitHub: CCShoop

Cameron Wright
Email: [email protected]
GitHub: CameronWr

(back to top)

modeltranslator's People

Contributors

cameronwr avatar marcobackman avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

modeltranslator's Issues

Output error

Output error on file
fischer.zip

Assignment missing variable.
Comparison does not match as given.
Parameter is not populated.

parenthesis not concatenated on Synchronization call

Synchronization call does not call function with parenthesis "()"

class A:
def a():

class B:
def b():
//sync call on def a in class A
A.a() // <- This should be A().a() or A has to be an instance of A passed as a parameter

System bug on no declaration but with a system call

fischer.zip
Problem:
When P is not declared, but calls as an system instance, it should know which template to call by name.
Current Limitation:
Current version of Translator requires instance to be declared first before getting called.
Solution;
Search by template name instead of looking into instance declaration dictionary.

undesired line of code removal

Code with comment on predefined code will cause line removal.

In predefined code
EX) if a < b: //This is comment

will omit the entire line, but not only removing the comments

Possible stack overflow on function call on continuous node calls.

Currently implemented function calls based on the output script implies that the function call will never return(stacking up the stack call) until it reaches to the end of the call.
Consider calling them as Lambda function or make them to return if some certain node processes are done.

Unimplemented Inline function declaration

  • Function declaration is not supported
    ex)
    int i;
    bool increment(int i) { return i + 1 }
    is not accepted and ignored -> node that contains function call on such conditional statement for example if increment(2) == 3: will not work but does not get ignored which leads to erroneous output

  • Variable reassignment would not work within the declaration section.

Actual device execution is not working on generated code

Solutions

  1. Sync syntax is not actually running in parallel. -> Refactor all to asyncio.gather() / remove the sleep
  2. Global variable access from class functions -> Add line "global [name]" based on used global variables in the function.
  3. implement parameter pass

Global keyword appending error on script generation

Does not create global keyword when using global variable in the guard. Only assignments are creating global keywords

When we set a variable named global_var to be in the global field.

Ex)
if (global_var < 2):
global_var = 5

Expected)
global global_var
if (global_var < 2):
global_var = 5

Current)

if(global_var < 2):
global global_var
global_var = 5

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.