User:Adrian

From ASCEND
Jump to: navigation, search

He is 4th year student of Gdansk University of Technology in the field of Computer Science. He has some expierence with professional work. He is passionate about parallel computing and great enthusiast for Linux and open source. Currently, he is involved in the development and improvements in the GUI of ASCEND.

Contact Email: adrbogus1@student.pg.gda.pl

Subversion account: adrian:/

GSoC 2015 Project: GUI Improvements

Generally GUI migration from Gtk2 to Gtk3 with some bugs fixing. Then implementation of an installer for the Windows users, which bundles and installs necessary libraries. Finally addition of some functionalities to GUI.

Build and install

Install ASCEND with Gtk3 GUI

Type following commands in order to get ASCEND with Gtk3 GUI. If you don't use Debian based operating system, please use appropriate tool and packages to your os. More info in INSTALL.txt.

sudo apt-get install subversion swig g++ gfortran python-dev scons flex bison graphviz-dev libsundials-serial-dev liblapack-dev libblas-dev \
ipython python-matplotlib coinor-libipopt-dev libmumps-seq-dev libgtk-3-0 git
svn co http://svn.ascend4.org/branches/adrian
cd adrian
scons
git clone -b gtk3 http://github.com/amolenaar/gaphas.git gaphastmp
cp -R gaphastmp/gaphas /usr/lib/python2.7/site-packages/
pygtk/ascdev models/johnpye/testlog10.a4c

Build Windows installer

Use these sites to prepare enviroment for Windows installer: http://ascend4.org/Setting_up_a_MinGW-w64_build_environment and http://ascend4.org/Building_ASCEND_for_64-bit_Windows with following changes:

  • You can use newer version of programs except Python (it has to be 2.7)
  • Don't install GTK+ 2 library (it's useless)
  • For building 32bit and 64bit use mingw-w64 instead mingw32 (there are annoying bugs)
  • Choose win32 threads instead posix
  • If you have any problem with undefined references for python use: (more info: http://stackoverflow.com/questions/6731100/link-to-python-with-mingw)

echo EXPORTS > python27.def
nm python27.lib | grep " T _" | sed "s/.* T _//" >> python27.def
dlltool --input-def python27.def --dllname python27 --output-lib libpython27.a

Then:

python setup.py bdist_wininst
  • Create Windows installer typing:

scons installer

Your installer is in dist directory. Remember to upload all additional installers here: https://sourceforge.net/projects/ascend-sim/files/thirdparty/

New features

Appearance

  • Multiselection of variables to fix, free and observe
  • Menu option to show/hide different instance types
  • Report/enter celsius temperatures
  • Show output variables instead indices in external relations (e.g. CO.inlet.state.calc_ph and CO.inlet.state.calc_vT in combinedcycle_water model)
  • Show dialog boxes for when and logrel types
  • Live plotting during solution of dynamic models

Details

  • Canvas with Gtk3
If you want to use Canvas GUI you need to have gaphas library (gtk3 branch), which is available on https://github.com/amolenaar/gaphas/tree/gtk3. Then you should copy gaphas/gaphas directory either to canvas directory or to python site-packages (usually: /usr/lib/python2.*/site-packages).
  • Multiselection of variables
Gtk 3.2 or above is required to support multiselection of variables. The work is done in modelview.py.
  • Show/hide different instance types
Used filtered tree model. The main work is done in modelview.py. Function responsible for filtering is filter_rows. I had to store treeview original path, which is dictionary key, in initial tuple (see make_row function).
  • Show/enter celsius temperatures
Everything is done in gui layer. For user it looks like normal unit from libascend, but it doesn't. It's only nice gui hack. Underneath there are Kelvin units. The special class 'CelsiusUnits' is responsible for all conversions between Kelvins and Celsiuses. All code is marked between "##### CELSIUS TEMPERATURE WORKAROUND" to be easy to find it. Celsius temperatures are displayed in main treeview, properties, study and observe tabs. User also can type 'degC' and it will be converted to Kelvins. The work was done in modelview.py, properties.py, study.py, observer.py, unitsdialog.py, preferences.py and celsiusunits.py.
  • External relation indexed using output variables
Done in modelview.py, marked "##### EXTERNAL RELATION WORKAROUND". The output variables are extracted from relation string and replace array indices.
  • Dialog boxes for when and logrel types
Added special functions in ascxx module to get proper strings. Used properties dialog to display them. Work done in modelview.py and properties.py.
  • Background tasks for solving
Created background tasks in gtkbrowser.py, study.py and solverhooks.py. Unfortunately three times almost the same code, but due to difference, difficult to tied together. There are new functions responsible for gui updating "called" from GObject.idle_add(). All functions have main function name with appropriate suffixes (e.g. udpate, finish). Solving can be interrupted between iterations, so if solver doesn't support iterate function there is no possibility to stop it.
  • Background tasks for integration
Work done mainly in integratorreporter.py, because there was code responsible for integration. Moved observed values recording to ascxx layer, due to failed assertions in libascend, using previous approach. It looks like, after creating new not gui thread, program can't spend much time in python code. No idea why.
  • Live plotting during solution of dynamic models
Improved IntegratorReporterPlot class, which inherits IntegratorReporterPython instead ascxx class. It allows to plot values and show progress bar simultaneously. Implemented mainly in integratorreporter.py

Project implementation

General plan

Till mid-term (3rd July 2015):

  • complete working port to GTK3, including canvas GUI (completed)
    • port canvas GUI to GTK3 (completed)
    Firstly found all files which should be change. Then tried to port all of them file by file (using pygi-convert.sh, knowledge of pygtk and of course internet). Next tested GUI after every relevant change. Finally performed sanity testing on all changed widgets.
    • test main GUI and fix bugs (completed)
    • fork gaphas gtk3 branch and fix bugs (completed)
    I forked gaphas from https://github.com/amolenaar/gaphas, then fixed bugs and sent pull request, which was merged with origin.
    • install a few virtual machines (completed)
    Installed Fedora 20 32bit with Kde, Debian 7 32bit with Gnome 2 and Ubuntu 14.04 32bit with Unity on VirtualBox
    • test Ascend using them (completed)
    On every machine I downloaded Ascend, built it and then tested all canvas features canvas from its menus.
  • windows installer based on GTK3, tested and working on a clean Windows VM (completed)
    • create installers from trunk code (completed)
    Firstly I created 32 bit installer, as it looked simpler. When this was done, 64bit installer wasn't a problem. I used these pages: http://ascend4.org/Setting_up_a_MinGW-w64_build_environment and http://ascend4.org/Building_ASCEND_for_64-bit_Windows, but of course I had to resolve many problems e.g with mingw32 compiler, lyx for Windows, threading mode etc.
    • create 32bit Ascend installer with new GUI (completed)
    I cloned my repository and built installer using scons. I did a lot of changes in nsis files in order to customize installer to new requirements. I removed old urls, old dependencies checking and installing, added section involving Canvas GUI, added new dependencies checking and installing.
    • create 64bit Ascend installer with new GUI (completed)
    Ran the same environment in 64bit mode and built installer.
    • create all needed python dependencies' installers (PyGI, PyGobject, PyCairo, Pango etc.) (completed)
    I downloaded installer from http://sourceforge.net/projects/pygobjectwin32/files/ and removed some parts from it. More information how to do this, here: http://ascend4.org/Creating_slim_PyGI_installer_for_Windows
    • create Gaphas installer with its dependencies (completed)
    I took code from https://github.com and https://pypi.python.org/pypi and then run this command: 'python setup.py bdist_wininst', which produces binary Windows installer.
    • install Windows 32bit and 64bit as virtual machines (completed)
    • test Ascend on these vms (completed)
    Generally installed Ascend on clear vm. Installer downloaded and installed all dependencies and Ascend worked.
  • improved tree-view in main GUI: (completed)
    • multi-selection of variables to 'observe' (completed)
    I enabled multiselection mode and then allowed to fix, free and observe selected rows.
    • menu option to show/hide different instance types (completed)
    I had to add orignal treepath to every row (this is the key in the data dictionary), modified a lot of code using this dictionary and finally added dynamically changing show/hide menu and appropriate callback functions.
  • allow celsius temperatures to be entered/reported in the GUI (completed)
I added workarounds for displaying/entering celsius temperature in GUI. Every show/edit 'event' is checked whether there is need to change kelvin to celsius or vice versa. Changes are transparent for user, because it looks like 'normal' unit from libascend.

Till full term (21st August 2015):

  • improved tree-view in main GUI: (completed)
    • better handling of keyboard navigation and value input (completed)
    Added possibility to start editing value after pressing ENTER.
    • improve rendering of events, whens, conditionals. (completed)
    I added some function to libascend to call them from python gui and show some information about logrel and when to user.
    • dialog boxes for not-yet-supported instance types (completed)
    The same as above. Moreover added rendering external relation using output variables instead indices.
  • redesign solver/integrator APIs for better handling of user interrupts (completed)
    • create sample solution using multithreading (completed)
    Created daemon thread solving model in background.
    • create sample solution using multiprocessing (completed)
    Created new process for solving model. Not completed solution due to complexity.
    • test both of them (completed)
    Multithreading: Generally very good approach, because it has a lot of advantages. It's simple, light, it doesn't increase computation time and everywhere you can use variables from Browser class. However it has disadvantages also. You can stop the thread only between iterations, so if iteration is long, it takes some time. And what follows: it looks IPOPT doesn't support slv_iterate, so whole solving is done in one iteration. Therefore user can't stop thread (as I mentioned above, it possible only between iterations).
    Multiprocessing: Child process for solving and parent process for updating gui. The approach has great advantage. You can kill "everything" you want (like killing any process in linux), so even IPOPT isn't a problem now. But it has many cons. Implementation is a little more difficult and time spent on calculations is greater (e.g. about 1 second when solving models/johnpye/fprops/rankine_regen.a4c, model rankine_regen_water). Moreover every process has own variables, so they cannot exchange data as simple as in multithreading model. It's needed to create a pipe for communication. You need to send errors from libascend (some errors are reported in 'c' code, the receiver is child process, so it has to send them to parent, otherwise they aren't reported in gui), simulation status (if you want to see something in gui, the parent process must handle it) and finally whole simulation (child process solved it, so child process own it). This is the biggest problem. If you want to send something via pipe, you must serialize it. I added possibility to serialize SolverStatus, but in case of Simulation, the task is very hard, because underneath there are object and structures, which have to be serialized also. I think it's necessary to use external library for c++ serialization.
    • implement chosen solution for solve in gtkbrowser, solverhooks and study (completed)
    Every case has the same functions, but with a little bit different implementation. This is due to difference between behavior of every solving case.
    • implement chosen solution for integration (completed)
    I had to change a way for saving observed values due to some erros in libascend. Now it's done in ascxx module by calling saveObservations() and user can get them using getObservations().
  • live plotting during solution of dynamic models (completed)
Improved IntegratorReporterPlot class to be able to live plot solving model.
  • improved line-routing for the canvas GUI (not completed)
    • learn libavoid and libcola from adaptagrams (completed)
    • write sample program and test what adaptagrams can do (completed)
    Libavoid is separate library and it doesn't depend on any other from adaptagrams. It's good to create routes, which don't intersect any another element (box or line). It supports poly-line or orthogonal routing. I think in Ascend better option is orthogonal, because the picture is more clearly.
    There is option to draw lines with some gap (you need to set this parameter shapeBufferDistance for the router), but it doesn't work if you type more than 0.5. No idea why. It looks as bug. I think the example available here is good enough to understand how use it.
    Libcola depends on libvpsc and it's also good to draw not intersected lines, but it works much different. Libavoid doesn't touch elements on the plane, just avoid it creating paths. Libcola can move every element on the plane to draw as planar graph as possible. If you want to use it, you must use ConstrainedFDLayout class, where Rectangles describe boxes and edges describe connections. It's useful if user place many elements close to each other. You can customize the solution e.g. if you want to add some space between elements you need to add SeparationConstraints.
    Of course it's possible to use both of them. Sometimes it's better to move some elements and create as straight lines as possible than got "fancy" paths consist of many segments.
    • fix 'avoid' branch from gaphas (not completed)
    • use 'avoid' branch in Ascend Canvas (not started)
    There are two ways to use adaptagrams in canvas.
    First: use 'avoid' branch from gaphas
    This approach has some disadvantages. The biggest is 'avoid' branch is not finished. There are many TODOs and it works only when line isn't connected to any box. If you connect it, the line becomes straight and you can see this warning: " In ConnEnd::assignPinVisibilityTo(): ConnEnd for connector 1706124136 can't connect to shape 1715105448 since it has no pins with class id of 15."
    I tried to find when it's reported, but I couldn't. There are many glue and connect functions, when line can being connected with a box. And the warning is printed between gtk iterations.
    Moreover Amolenaar commited last time about 4 years ago, so he uses old adaptagrams version. For example there is no option to set gap between line and any box (mentioned above).
    Thirdly 'avoid' branch uses gtk2, so there is need to port this branch to gtk3.
    Second: use adaptagrams directly in canvas code
    Firstly create python wrapper classes:
    1. Clone Adaptagrams into a directory of your choice, ADAPDIR.
    2. Follow the instructions at the Adaptagrams repository page to build Adaptagrams.
    3. Python bindings for Adaptagrams can be generated using SWIG. After building Adaptagrams you should be able to create the SWIG bindings with the following commands:
      $ cd ADAPDIR/cola
      $ make -f Makefile-swig-python
    4. Finally, you need to copy adaptagrams.py and _adaptagrams.so to canvas code directory or to python dist-packages.
    Now it's possible to use adaptagrams in canvas. As canvas much depends on gaphas, the problem is almost the same like in first approach. You need to know where connecting, moving, creating is done and add there code using libavoid and/or libcola.
  • windows installers using msys2 (optional) (not started)
  • substantial progress on associated bug-fixed as agreed in weekly meetings (completed)
Fixed 64 bugs.

Timeline for task completion

  • 1st April 2015 - 3rd May 2015
Major points describing weeks' work
  • Ported Canvas GUI to Gtk3
Fixed bugs
  • Fixed properties displaying after model running
  • Fixed context menu displaying issue
  • Fixed context menu instance wrong tab displaying issue
  • Fixed context menu tool issue
  • Fixed method entry issue
  • Fixed zoom issue
  • Fixed solver status without parent issue
  • Fixed instance showing after run issue
  • Fixed canvas saving issue
  • Fixed blockproperties window issue
  • Fixed transient parent for about dialog issue
  • Fixed transient parent for canvasproperties issue
  • Fixed export svg dialog transient parent issue
  • Fixed KeyError in otank dictionary issue
  • Fixed selected item status issue
  • Fixed no icons issue
  • Fixed disappearing menu issue, removed unecessary multiple definitions of toolbar
  • Fixed adjustments issue
  • 4th May 2015 - 10th May 2015
Major points describing week's work
  • Installed three virtual machines and two native systems with different operating systems and desktop enviroments
    • Debian 7 32bit with Gnome 2 - virtual machine to test
    • Fedora 20 32bit with Kde - virtual machine to test
    • Ubuntu 14.04 32bit with Unity - virtual machine to test
    • Fedora 20 64bit with Gnome 3 - main computer to develop and test
    • Debian 8 64bit with Gnome 3 - laptop to develop and test
  • Tested Canvas GUI on every machine
Fixed bugs
  • Fixed renaming block issue
  • Fixed issue with endless depth string in obrowser
  • Fixed issue with attributes for tree column view in blockproperties for gnome 2
  • Fixed saving canvas after running issue
  • 11th May 2015 - 17th May 2015
Major points describing week's work
  • Created user wiki page
  • Forked gaphas and fixed bugs (gtk3 branch)
  • Initial work with windows 32bit installer
Fixed bugs
  • Fixed scroll adjustments issue
  • Fixed scrolling on canvas
  • Added gnome 2 compatibility
  • 18th May 2015 - 24th May 2015
Major points describing week's work
  • Further work with windows 32bit installer
Fixed bugs
  • Fixed no reporter instance issue
  • Removed workarounds after gaphas fixing
  • 25th May 2015 - 31st May 2015
Major points describing week's work
  • Resolved many problems with creating trunk code installer
  • Created first (bugged) version of 32 bit adrian branch installer
  • 1st June 2015 - 7th June 2015
Major points describing week's work
  • Created new 32bit Ascend installer for Windows
  • Created new 64bit Ascend installer for Windows
  • Tested both of them on virtual machines
Fixed bugs
  • Fixed windows real time library issue
  • Fixed null windows issue
  • Removed code, which causes problems with python dlls imports
  • Fixed 64bit installer filenames issue
  • 8th June 2015 - 14th June 2015
Major points describing week's work
  • Created slim PyGI installer for Windows
  • Created all python dependencies installers
  • Added matplotlib files to installer
  • Improved 32bit Ascend installer for Windows
  • Improved 64bit Ascend installer for Windows
  • Tested both of them on virtual machines
  • Allowed user to resize columns in observer tab
  • Updated gtk version in glade file
Fixed bugs
  • Fixed adjustment issue
  • Fixed transient window for plot
  • Fixed observed float values issue
  • 15th June 2015 - 21st June 2015
Major points describing week's work
  • Reformated ascend glade file
  • Added multiselection of variables to fix, free and observe
Fixed bugs
  • Fixed units issue
  • Fixed not refined solver var issue in context menu
  • 22nd June 2015 - 28th June 2015
Major points describing week's work
  • Added option to show/hide different instance types
Fixed bugs
  • Fixed dictionary keys issue
  • 29th June 2015 - 5th July 2015
Major points describing week's work
  • Added possibility to show/enter celsius temperatures
Fixed bugs
  • Fixed unitsdialog issue
  • Fixed model context menu issue
  • Fixed issue with too many items in menus after opening next model
  • Fixed incidence graph resizing issue
  • Fixed almost endless simulation creating in models with 'deep' dependencies
  • Fixed first time selected units issue
  • 6th July 2015 - 12th July 2015
Fixed bugs
  • Fixed first solver choice issue
  • Fixed solver choosing issue
  • Fixed builder substitution issue
  • Fixed displaying old module issue
  • 13th June 2015 - 19th July 2015
Major points describing week's work
  • Added external relation indexing using output variables
  • Added ability to edit the value using ENTER
Fixed bugs
  • Fixed delta temperature conversion issue
  • 20th June 2015 - 26th July 2015
Major points describing week's work
  • Added default selection in unitsdialog
  • Added support for celsius temperature in properties dialog
  • Added dialog boxes for when and logrel types
  • Initial work with background tasks
Fixed bugs
  • Fixed temperature properties displaying issue
  • Fixed observer tab label issue
  • Fixed endless editing while using ENTER issue
  • Fixed problem with entering boolean values
  • 27th June 2015 - 2nd August 2015
Major points describing week's work
  • Created multithreading solution for solving
  • Created multiprocessing solution for solving
  • Tested them and prepared report
Fixed bugs
  • Fixed too less errors after solving
  • Fixed no text on progress bar in solver status dialog
  • Fixed celsius temperature typing issue
  • 3rd August 2015 - 9th August 2015
Major points describing week's work
  • Added background task for integration
  • Added background task to solver hooks
  • Added celsius temperatures in observer tab
  • Added background task in study
  • Moved celsius temperature workaround code
  • Added celsius temperatures to study dialog
Fixed bugs
  • Fixed no text on progressbars issue
  • Fixed no change in observer tab issue
  • Fixed status comboboxes issues
  • Fixed module view issue
  • 10th August 2015 - 16th August 2015
Major points describing week's work
  • Added live plotting during solution of dynamic models
  • Learned adaptagrams
  • Created programs using libcola and libavoid and tested them
  • Tried to improve 'avoid' branch from 'gaphas'
Fixed bugs
  • Fixed no images in diagnose window issue
  • Fixed exception on wrong parameters in integrator window issue
  • 17th August 2015 - 23rd August 2015
Major points describing week's work
  • Improved celsius temperature conversion
  • Updated wiki information
  • Created 32bit and 64bit Windows installers
  • Tested Ascend on 5VMs (Ubuntu 14.04, Debian 7, Fedora 20, Fedora 22 and Windows 8.1)
  • Created steps to build Ascend
  • Created steps to build installer
Fixed bugs
  • Fixed observer values displaying issue
  • Fixed pixbuf issue in diagnose window
  • Fixed diagnose window resizing issue
  • Fixed diagnose window issue
  • Fixed temperature issue
  • Fixed many the same units issue
  • Fixed issue with idle_add for gnome 2
  • Fixed no observed values after interrupt issue