Comments (16)
* Use a profiling tool (e.g. built-in in Pycharm) to investigate on the time consumption for the different toolbox parts for the provided examples or a dummy controller input * Identify possible potentials for improving the code in terms of processing time * Evaluate alternative implementations to speed up the code (e.g. on specific test branch)
- The profiling of course requires to interact with the toolbox either by inserting dummy actions or based on the already available RL/control examples. Nevertheless, the investigation should only focus on the calculation speed of the GEM part and not cover any external packages.
- The speed analysis obsiously has to cover different applications within the toolbox i.e. different motors (and inverters) as well as the disctinction between continuous and finite actions. Depending on the specific scenarios, the results of the investigation may change since other parts of the toolbox are actively used.
- For the first sprint of the summer semester 2020, the issue is mainly on the analysis itself to identify possible code bottlenecks and to suggest & try out first improvements. The specific implementations are likely to be covered in the subsequent sprints.
from gym-electric-motor.
The speed analysis has been done for various motor environments.
The GEM related code bottlenecks are prioritized.
The following steps were followed for the analysis:
-
A sanity check of code coverage while profiling each environment to substantiate covering the entire GEM part
-
Code profiling has been done using pycharm's Cprofile which gives both the statistical and graphical representation of profiled report
-
It is found that the majority of the time was utilized by an advanced non-gem frameworks like keras, tensorflow and libraries like scipy and others.
-
A rigorous investigation established that most of the time in GEM part was spent on following python files( kindly look at the attached report for function level details)
1. physical_systems.py
2. mechanical_loads.py
3. electric_motors.py
4. motor_dashboard.py
5. solvers.py etc -
Improvement suggestions:
At first sight, using python code optimization using cython, numba, pythron seems to fit the cause.
Although majority of modules are already using libraries which has such optimization in-built. It would be interesting to see where this would lead us and to what extent can we optimise
Additionally, I have also noticed the earlier optimization efforts using Jacobian. But, need to dig deeper on that.
from gym-electric-motor.
I had a call with Pramod in which he showed me the steps he did for the code investigations. I have no further remarks on this issue.
from gym-electric-motor.
@pramodcm95 : During the last meeting you also showed the structure overview of the built-in Pycharm profiler regarding the computational demand per code part (flowchart style diagram). Could you please add these diagrams as picures to this report issue, I belive they provide a valuable overiew.
from gym-electric-motor.
In the issue branch on git hub, I have checked in these files as "___.pstat' files (one for each environment) which needs to be imported to pycharm( in tools->open CProfile snapshot ). This should be the best way to get that graph since we can navigate to respective source file directly.
Here, In this issue, I can post the snapshot if you want. But are you expecting the flowchart snap of each environment and controller combination?, which I am afraid, may be chaotic here.
Please let me know if the snapshot is required for all environments. I will do the needful
from gym-electric-motor.
Since we would like to maintain a slim branch structure in the long-run, the issue branch will be deleted at some point. Hence, I believe it would be simplest if you could through the relevant files into an archive folder and upload it here to the issue thread - I believe these reportings are static files which do not require the specific code from which they have been generated, right?
from gym-electric-motor.
yes, they have been generated for different Environment-ID's. SO changing an environment would give me a new report.
And I understand the concept now. I am uploading a folder with relevant files for a quick update now. The snapshots will also be posted soon
from gym-electric-motor.
Code profiling delivered some interesting insights into the computational demand of the different parts of the toolbox.
Next steps will be to evaluate possible speed improvements e.g. if parts of the toolbox can be transfered to Cython or Numba to optain a speed-up.
from gym-electric-motor.
@pramodcm95
I believe with the above zip archive the results of your analysis are saved within this issue thread also for later inspection & discussion. For repo clearness I would like to delete the branch attached to this issue - do you object?
from gym-electric-motor.
No @wallscheid . It is good to remove it from repo.
from gym-electric-motor.
@pramodcm95 : could you please provide a short update on your working status? The supervisors missing a lifesign.
from gym-electric-motor.
Yes.
Initially I had 2 options to explore:
- cython - which requires all files to be converted to .pyx format and compile it from an external C compiler.
This resulted in loads of errors and upon further seep investigation, Realized that cython GitHub already has lots of issues posted and working on it.
So simpler option would be to switch to numba, which takes higher time for the first compilation and then on depending on the type of code, it speeds up the process.
- Numba: This basically uses JIT(just in time compiler)
The following libraries from numba have been explored and tried to integrate in project:
@jitclass - compiles whole class using JIT compiler
@jit _ simplest veersion, which gives us warnings if prerequisites of numba are not met
@njit - called "no python mode" completes runs on numba style
@njit(parallel = True) - parallelise the code, if the above @numba conditions are satisfied
@vectorise - vectorises the code.
As all these have lots of pre-requisites, the idea to attack the function taking a lots of time was an ambitious task, since it has lots of interlinked functions which cannot be converted to numba straightaway. I am stuck at a certain point, where adding a numba decorator is asking an extra argument in certain functions and doesn't behave similar for other functions. Reading through their repository to find any such issues reported before.
from gym-electric-motor.
I could execute mechanical_ode (in mechanical loads) in object mode of numba. Unfortunetly there isn't any great improvement. Instead, the own time of a function is increasing.
( to the left - without numba, to the right - with numba )
from gym-electric-motor.
@pramodcm95 : could you please upload your altered code to a dedicated feature branch such that also others can have a view on it.
Regarding the result: are there any statements from the numba project or numba users that initial calls of numba code is leading to quite a significant overhead? Maybe the computional load of the code you have exchanged is very small while this presumed overhead is large?
from gym-electric-motor.
sure. So i will create a new branch for this issue now?(since we had deleted the issue 35 branch before)
yes, Numba works that way. It has a very high initial overhead, once the all the values are cached it starts to reduce the execution time
A simple example looks like this:
from gym-electric-motor.
Maybe this package could help to outsource performance-critical code into c code:
https://github.com/mypyc/mypyc
from gym-electric-motor.
Related Issues (20)
- Can you email me, please ? HOT 1
- Log Variables on each Time Step in PMSM Example Notebook[feature request] HOT 10
- incompatibility with gym >0.24.0 HOT 9
- Improve ReferenceGenerator chapter in Gem_Cookbook
- Flat velocity plot for scim_ideal_grid_simulation.py HOT 2
- Limit values for PMSM motor appear to be a peak to peak value vs an amplitude value HOT 2
- Do GEM currently support 3-phase brushless motor control? HOT 3
- Typo in the calculation of the decoupling HOT 1
- Feature Request: migrate from gym to gymnasium HOT 5
- Documentation is showing only current API (no past releases APIs)
- Phase voltage accuracy for PMSM motors HOT 5
- ConstReferenceGenerator enters the reference_name not as string into the env
- gem modularization
- modularization
- CosSinProcessor calculates Cosinus and Sinus based on normalized Epsilon
- DqToAbcActionProcessor calculates advanced angle wrongly
- Extend the GEM cookbook to explain voltage supply usage
- change the nominalization of the voltage
- Change the mapping of discrete switching states in FiniteB6BridgeConverter
- Hi, We are using the GEM library for testing the functionality of PMSM as a part of our undergraduate project. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gym-electric-motor.