Thread: [myhdl-list] Reusability and encapsulation
Brought to you by:
jandecaluwe
From: Juan P. C. <jp...@gm...> - 2015-05-02 19:40:47
|
Hi, I use iPython a lot and need to launch multiple simulations of different models (and signals) within the same interpreter. And MyHDL does not play nicely with this. I've found a way to clean the environment in order to be able to run a new simulation: I import from myhdl import _simulator from myhdl import _traceSignals in the beginning, and before every simulation (and signal tracing) I do: _simulator._signals = [] _simulator._siglist = [] _simulator._futureEvents = [] _simulator._time = 0 _simulator._cosim = 0 _simulator._tracing = 0 _simulator._tf = None _traceSignals._tracing = 0 which is what is done upon importing the mentioned files. I would love if some re-structuring was done to the code providing better encapsulation of variables. It would alleviate a lot of problems that arise when trying to build upon the base myhdl library. As it stands, it's fine for end-user digital designers, but makes it hard to create software that use myhdl as a feature. Specifically, moving the above-mentioned variables to Simulation instances would be great, and in general, to not have any shared states. I would happily contribute towards these changes. I'd rather contribute to the project than be implementing my own ad-hoc fixes. Thanks, JP |
From: Henry G. <he...@ca...> - 2015-05-02 21:33:18
|
I just submitted a github issue on this. I suggest adding some to that. Please forgive me, I'm sending this from my phone so it's not easy to check the issue number. The basic problem as far as I can tell is the global state stored in simulator.py and the state that is stored on the signal itself. Possibly your ipython problems would be fixed by the patch I just submitted to clear the state on a new simulation instance. Cheers Henry. On 2 May 2015 20:40:19 BST, Juan Pablo Caram <jp...@gm...> wrote: >Hi, > >I use iPython a lot and need to launch multiple simulations of >different >models (and signals) within the same interpreter. And MyHDL does not >play >nicely with this. > >I've found a way to clean the environment in order to be able to run a >new >simulation: I import > >from myhdl import _simulator >from myhdl import _traceSignals > >in the beginning, and before every simulation (and signal tracing) I >do: > >_simulator._signals = [] >_simulator._siglist = [] >_simulator._futureEvents = [] >_simulator._time = 0 >_simulator._cosim = 0 >_simulator._tracing = 0 >_simulator._tf = None > >_traceSignals._tracing = 0 > >which is what is done upon importing the mentioned files. > >I would love if some re-structuring was done to the code providing >better >encapsulation of variables. It would alleviate a lot of problems that >arise >when trying to build upon the base myhdl library. As it stands, it's >fine >for end-user digital designers, but makes it hard to create software >that >use myhdl as a feature. > >Specifically, moving the above-mentioned variables to Simulation >instances >would be great, and in general, to not have any shared states. > >I would happily contribute towards these changes. I'd rather contribute >to >the project than be implementing my own ad-hoc fixes. > >Thanks, > >JP > > >------------------------------------------------------------------------ > >------------------------------------------------------------------------------ >One dashboard for servers and applications across >Physical-Virtual-Cloud >Widest out-of-the-box monitoring support with 50+ applications >Performance metrics, stats and reports that give you Actionable >Insights >Deep dive visibility with transaction tracing using APM Insight. >http://ad.doubleclick.net/ddm/clk/290420510;117567292;y > >------------------------------------------------------------------------ > >_______________________________________________ >myhdl-list mailing list >myh...@li... >https://lists.sourceforge.net/lists/listinfo/myhdl-list -- Sent from my Android device with K-9 Mail. Please excuse my brevity. |
From: Juan P. C. <jp...@gm...> - 2015-05-02 22:37:35
|
I found it. It's #68 (https://github.com/jandecaluwe/myhdl/issues/68). I commented with a short summary of my last post. Thanks! JP On Sat, May 2, 2015 at 5:08 PM, Henry Gomersall <he...@ca...> wrote: > I just submitted a github issue on this. I suggest adding some to that. > Please forgive me, I'm sending this from my phone so it's not easy to check > the issue number. > > The basic problem as far as I can tell is the global state stored in > simulator.py and the state that is stored on the signal itself. > > Possibly your ipython problems would be fixed by the patch I just > submitted to clear the state on a new simulation instance. > > Cheers Henry. > > > On 2 May 2015 20:40:19 BST, Juan Pablo Caram <jp...@gm...> wrote: > >> Hi, >> >> I use iPython a lot and need to launch multiple simulations of different >> models (and signals) within the same interpreter. And MyHDL does not play >> nicely with this. >> >> I've found a way to clean the environment in order to be able to run a >> new simulation: I import >> >> from myhdl import _simulator >> from myhdl import _traceSignals >> >> in the beginning, and before every simulation (and signal tracing) I do: >> >> _simulator._signals = [] >> _simulator._siglist = [] >> _simulator._futureEvents = [] >> _simulator._time = 0 >> _simulator._cosim = 0 >> _simulator._tracing = 0 >> _simulator._tf = None >> >> _traceSignals._tracing = 0 >> >> which is what is done upon importing the mentioned files. >> >> I would love if some re-structuring was done to the code providing better >> encapsulation of variables. It would alleviate a lot of problems that arise >> when trying to build upon the base myhdl library. As it stands, it's fine >> for end-user digital designers, but makes it hard to create software that >> use myhdl as a feature. >> >> Specifically, moving the above-mentioned variables to Simulation >> instances would be great, and in general, to not have any shared states. >> >> I would happily contribute towards these changes. I'd rather contribute >> to the project than be implementing my own ad-hoc fixes. >> >> Thanks, >> >> JP >> >> ------------------------------ >> >> One dashboard for servers and applications across Physical-Virtual-Cloud >> Widest out-of-the-box monitoring support with 50+ applications >> Performance metrics, stats and reports that give you Actionable Insights >> Deep dive visibility with transaction tracing using APM Insight. >> http://ad.doubleclick.net/ddm/clk/290420510;117567292;y >> >> ------------------------------ >> >> myhdl-list mailing list >> myh...@li... >> https://lists.sourceforge.net/lists/listinfo/myhdl-list >> >> > -- > Sent from my Android device with K-9 Mail. Please excuse my brevity. > |
From: Christopher F. <chr...@gm...> - 2015-05-03 00:22:18
|
On 5/2/15 2:40 PM, Juan Pablo Caram wrote: > Hi, > > I use iPython a lot and need to launch multiple simulations of different > models (and signals) within the same interpreter. And MyHDL does not > play nicely with this. That is odd, I use IPython console/notebook constantly, most my replies here include IPython snips. I have not run into any issues. http://nbviewer.ipython.org/github/cfelton/musicbox_simple/blob/master/musicbox.ipynb (my simple (ridiculously simple) vcd viewer needs some love :) There was an issue at one point for folks that used UTF8 encoding I can't remember if that is still true or not (a fix was identified but I can't recall the if was implemented or not). Regards, Chris |
From: Henry G. <he...@ca...> - 2015-05-03 08:03:32
|
On 03/05/15 01:21, Christopher Felton wrote: > On 5/2/15 2:40 PM, Juan Pablo Caram wrote: >> >Hi, >> > >> >I use iPython a lot and need to launch multiple simulations of different >> >models (and signals) within the same interpreter. And MyHDL does not >> >play nicely with this. > That is odd, I use IPython console/notebook constantly, > most my replies here include IPython snips. I have > not run into any issues. I suspect the state-on-the-signal issue we were discussing on IRC would show up as a potential problem here. For those that didn't happen to be watching IRC at that moment, it is discussed a bit in the PR: https://github.com/jandecaluwe/myhdl/pull/67 Cheers, Henry |
From: Christopher F. <chr...@gm...> - 2015-05-03 16:02:35
|
<snip> > > For those that didn't happen to be watching IRC at that moment, it is > discussed a bit in the PR: > https://github.com/jandecaluwe/myhdl/pull/67 There are logs for the IRC channel https://botbot.me/freenode/myhdl/ Regards, Chris |
From: Juan P. C. <jp...@gm...> - 2015-05-03 16:11:41
|
You will at least get the error: TraceSignalsError: Cannot trace multiple instances simultaneously if you try to run the line: Simulation(traceSignals(_test)).run() a second time without restarting the kernel. Cheers, JP On Sun, May 3, 2015 at 12:02 PM, Christopher Felton <chr...@gm...> wrote: > <snip> > > > > For those that didn't happen to be watching IRC at that moment, it is > > discussed a bit in the PR: > > https://github.com/jandecaluwe/myhdl/pull/67 > > There are logs for the IRC channel > https://botbot.me/freenode/myhdl/ > > Regards, > Chris > > > > ------------------------------------------------------------------------------ > One dashboard for servers and applications across Physical-Virtual-Cloud > Widest out-of-the-box monitoring support with 50+ applications > Performance metrics, stats and reports that give you Actionable Insights > Deep dive visibility with transaction tracing using APM Insight. > http://ad.doubleclick.net/ddm/clk/290420510;117567292;y > _______________________________________________ > myhdl-list mailing list > myh...@li... > https://lists.sourceforge.net/lists/listinfo/myhdl-list > |
From: Christopher F. <chr...@gm...> - 2015-05-04 15:08:16
|
On 5/3/2015 11:11 AM, Juan Pablo Caram wrote: > You will at least get the error: > > TraceSignalsError: Cannot trace multiple instances simultaneously > > > if you try to run the line: > > Simulation(traceSignals(_test)).run() > > > a second time without restarting the kernel. The fourth code cell can be run multiple times without restarting the kernel. You are saying, if the line where Simulation(...) occurs is repeated twice it fails? print("call simulation first time ...") Simulation(traceSignals(_test)).run() print("call simulation second time ...") Simulation(traceSignals(_test)).run() It does not fail with the version I have? The above works fine. call simulation first time ... The note has a tone at 1200.000 and 4000.000 call simulation second time ... The note has a tone at 1200.000 and 4000.000 I am not following what fails and how? Regards, Chris |
From: Juan P. C. <jp...@gm...> - 2015-05-05 13:31:33
|
I think I installed it from the Ubuntu 12.04 repository. Is there a variable containing the version number or should I look in the code? Thanks, JP On Mon, May 4, 2015 at 11:08 AM, Christopher Felton <chr...@gm...> wrote: > On 5/3/2015 11:11 AM, Juan Pablo Caram wrote: > > You will at least get the error: > > > > TraceSignalsError: Cannot trace multiple instances simultaneously > > > > > > if you try to run the line: > > > > Simulation(traceSignals(_test)).run() > > > > > > a second time without restarting the kernel. > > The fourth code cell can be run multiple times > without restarting the kernel. You are saying, if > the line where Simulation(...) occurs is repeated > twice it fails? > > print("call simulation first time ...") > Simulation(traceSignals(_test)).run() > print("call simulation second time ...") > Simulation(traceSignals(_test)).run() > > It does not fail with the version I have? The above > works fine. > > call simulation first time ... > The note has a tone at 1200.000 and 4000.000 > call simulation second time ... > The note has a tone at 1200.000 and 4000.000 > > I am not following what fails and how? > > Regards, > Chris > > > > > ------------------------------------------------------------------------------ > One dashboard for servers and applications across Physical-Virtual-Cloud > Widest out-of-the-box monitoring support with 50+ applications > Performance metrics, stats and reports that give you Actionable Insights > Deep dive visibility with transaction tracing using APM Insight. > http://ad.doubleclick.net/ddm/clk/290420510;117567292;y > _______________________________________________ > myhdl-list mailing list > myh...@li... > https://lists.sourceforge.net/lists/listinfo/myhdl-list > |
From: Christopher F. <chr...@gm...> - 2015-05-06 16:16:06
|
On 5/5/2015 8:31 AM, Juan Pablo Caram wrote: > I think I installed it from the Ubuntu 12.04 repository. Is there a > variable containing the version number or should I look in the code? > Looks like there is: https://github.com/ipython/ipython/issues/3025 In [5]: import IPython print(IPython.__version__) !ipython --version 3.0.0 3.0.0 I am using Chrome. I think, I installed with pip? Regards, Chris |
From: Juan P. C. <jp...@gm...> - 2015-05-06 16:33:17
|
Oh, I thought you were referring to which version of MyHDL I have. My IPython is 2.4.1 And Python 2.7.3 I believe I installed MyHDL via pip. So I don't know how old the code is... I can try the latest source. What would be the fastest way to do that without uninstalling my current MyHDL version? Or perhaps I should just go ahead and install the latest code. Is it stable? Thanks, JP On Wed, May 6, 2015 at 12:15 PM, Christopher Felton <chr...@gm...> wrote: > On 5/5/2015 8:31 AM, Juan Pablo Caram wrote: > > I think I installed it from the Ubuntu 12.04 repository. Is there a > > variable containing the version number or should I look in the code? > > > > Looks like there is: > https://github.com/ipython/ipython/issues/3025 > > In [5]: import IPython > print(IPython.__version__) > !ipython --version > 3.0.0 > 3.0.0 > > I am using Chrome. I think, I installed with pip? > > Regards, > Chris > > > > > > > ------------------------------------------------------------------------------ > One dashboard for servers and applications across Physical-Virtual-Cloud > Widest out-of-the-box monitoring support with 50+ applications > Performance metrics, stats and reports that give you Actionable Insights > Deep dive visibility with transaction tracing using APM Insight. > http://ad.doubleclick.net/ddm/clk/290420510;117567292;y > _______________________________________________ > myhdl-list mailing list > myh...@li... > https://lists.sourceforge.net/lists/listinfo/myhdl-list > |
From: Christopher F. <chr...@gm...> - 2015-05-06 16:40:36
|
On 5/6/2015 11:32 AM, Juan Pablo Caram wrote: > Oh, I thought you were referring to which version of MyHDL I have. > > My IPython is 2.4.1 > And Python 2.7.3 > > I believe I installed MyHDL via pip. So I don't know how old the code is... The pip version of MyHDL is 0.8 and is fairly old. You can get the MyHDL version via import myhdl print(myhdl.__version__) The `master` branch is stable but is still the development branch, nothing is merged that breaks the test suite, any existing code should be fine. You can install the latest via: >> pip install https://github.com/jandecaluwe/myhdl/archive/master.zip or >> pip install git+https://github.com/jandecaluwe/myhdl Regards, Chris |
From: Juan P. C. <jp...@gm...> - 2015-05-06 17:16:01
|
Ok, installed from git. Version is 0.9.dev0. And the problem persists. Here is some more detail: def tb(): ... return ... model_inst = traceSignals(tb) sim = Simulation(model_inst) sim.run(1 * us) RESULT: <class 'myhdl._SuspendSimulation'>: Simulated 1000000000.0 timesteps def tb(): # Different from previous tb() ... return ... model_inst = traceSignals(tb) sim = Simulation(model_inst) sim.run(3 * us) RESULT: --------------------------------------------------------------------------- TraceSignalsError Traceback (most recent call last) <ipython-input-22-710800f935f0> in <module>() 1 print "{:10} {:10} {:10}".format("Ref", "FB", "Err=Ref-FB") ----> 2 model_inst = traceSignals(tb) 3 sim = Simulation(model_inst) 4 sim.run(3 * us) /usr/local/lib/python2.7/dist-packages/myhdl-0.9.dev0-py2.7.egg/myhdl/_traceSignals.pyc in __call__(self, dut, *args, **kwargs) 73 raise TraceSignalsError(_error.ArgType, "got %s" % type(dut)) 74 if _simulator._tracing: ---> 75 raise TraceSignalsError(_error.MultipleTraces) 76 77 _tracing = 1 TraceSignalsError: Cannot trace multiple instances simultaneously It's probably something silly I'm doing. I suspect Simulation()._finalize() is not being called for some reason. Thanks, JP On Wed, May 6, 2015 at 12:43 PM, Christopher Felton <chr...@gm...> wrote: > <snip> > > > > You can install the latest via: > > >> pip install https://github.com/jandecaluwe/myhdl/archive/master.zip > > or > > >> pip install git+https://github.com/jandecaluwe/myhdl > > > > Actually, if you want to follow the development > and get the greatest and latest it is best to > git clone and update as outlined here: > > http://dev.myhdl.org/guide/guide.html > > If you want to contribute you need to create a > github fork, etc. etc. > > Regards, > Chris > > > > ------------------------------------------------------------------------------ > One dashboard for servers and applications across Physical-Virtual-Cloud > Widest out-of-the-box monitoring support with 50+ applications > Performance metrics, stats and reports that give you Actionable Insights > Deep dive visibility with transaction tracing using APM Insight. > http://ad.doubleclick.net/ddm/clk/290420510;117567292;y > _______________________________________________ > myhdl-list mailing list > myh...@li... > https://lists.sourceforge.net/lists/listinfo/myhdl-list > |
From: Juan P. C. <jp...@gm...> - 2015-05-06 17:58:32
|
Oh, sorry, I didn't actually run your notebook. I just didn't (and still don't) see the difference between my code and yours. I'm not explicitly using _SuspendSimulation or StopSimulation. I don't know why the simulation "stops" with _SuspendSimulation instead of StopSimulation. It's stopping at the end of the specified time in sim.run(stoptime). Okay, now I see it. At the completion of simulation time _SuspendSimulation is raised to exit (this is the bug?). You explicitly use StopSimulation. Thanks, JP On Wed, May 6, 2015 at 1:50 PM, Christopher Felton <chr...@gm...> wrote: > On 5/6/2015 12:15 PM, Juan Pablo Caram wrote: > > Ok, installed from git. Version is 0.9.dev0. And the problem persists. > Here > > is some more detail: > > > > def tb(): > > ... > > return ... > > > > model_inst = traceSignals(tb) > > sim = Simulation(model_inst) > > sim.run(1 * us) > > > > This is a known problem with a known solution, the > difference between _SuspendSimulation and StopSimulation. > > There will probably be a fix shortly'sh. > > There was a little confusion in this thread, because I > thought you said you observed this issue in the example > I mentioned: > > http://nbviewer.ipython.org/github/cfelton/musicbox_simple/blob/master/musicbox.ipynb > > >>> if you try to run the line: > >>> > >>> Simulation(traceSignals(_test)).run() > >>> > >>> a second time without restarting the kernel. > > This problem (the second), could not be reproduced with the > example I provided as described in a previous reply. > > Regards, > Chris > > > > > ------------------------------------------------------------------------------ > One dashboard for servers and applications across Physical-Virtual-Cloud > Widest out-of-the-box monitoring support with 50+ applications > Performance metrics, stats and reports that give you Actionable Insights > Deep dive visibility with transaction tracing using APM Insight. > http://ad.doubleclick.net/ddm/clk/290420510;117567292;y > _______________________________________________ > myhdl-list mailing list > myh...@li... > https://lists.sourceforge.net/lists/listinfo/myhdl-list > |
From: Christopher F. <chr...@gm...> - 2015-05-06 16:45:12
|
<snip> > > You can install the latest via: > >> pip install https://github.com/jandecaluwe/myhdl/archive/master.zip > or > >> pip install git+https://github.com/jandecaluwe/myhdl > Actually, if you want to follow the development and get the greatest and latest it is best to git clone and update as outlined here: http://dev.myhdl.org/guide/guide.html If you want to contribute you need to create a github fork, etc. etc. Regards, Chris |
From: Christopher F. <chr...@gm...> - 2015-05-06 17:50:43
|
On 5/6/2015 12:15 PM, Juan Pablo Caram wrote: > Ok, installed from git. Version is 0.9.dev0. And the problem persists. Here > is some more detail: > > def tb(): > ... > return ... > > model_inst = traceSignals(tb) > sim = Simulation(model_inst) > sim.run(1 * us) > This is a known problem with a known solution, the difference between _SuspendSimulation and StopSimulation. There will probably be a fix shortly'sh. There was a little confusion in this thread, because I thought you said you observed this issue in the example I mentioned: http://nbviewer.ipython.org/github/cfelton/musicbox_simple/blob/master/musicbox.ipynb >>> if you try to run the line: >>> >>> Simulation(traceSignals(_test)).run() >>> >>> a second time without restarting the kernel. This problem (the second), could not be reproduced with the example I provided as described in a previous reply. Regards, Chris |
From: Christopher F. <chr...@gm...> - 2015-05-06 18:06:16
|
On 5/6/2015 12:58 PM, Juan Pablo Caram wrote: > Oh, sorry, I didn't actually run your notebook. I just didn't (and still > don't) see the difference between my code and yours. > > I'm not explicitly using _SuspendSimulation or StopSimulation. I don't know > why the simulation "stops" with _SuspendSimulation instead of > StopSimulation. It's stopping at the end of the specified time in > sim.run(stoptime). Understand, _SuspendSimulation and StopSimulation are the internal exceptions (state) for the simulator. When you run the simulator for a specific period of time: sim = Simulation(tb()) sim.run(100) The simulator suspends so that it can resume: sim.run(100) In my example I did not define a number of simulation steps to run (the argument to run). When no duration is specified the simulation runs until there are no more events or StopSimulation is raised. Restarting the simulator in the second condition works fine but restarting in the first has an issue. > > Okay, now I see it. At the completion of simulation time _SuspendSimulation > is raised to exit (this is the bug?). You explicitly use StopSimulation. The raising of _SuspendSimulation is not the bug, the bug is when a new simulation instance is created after a suspend. Regards, Chris |
From: Juan P. C. <jp...@gm...> - 2015-05-06 18:14:20
|
Got it. Definitely not a blocker! I can work around it. Is there a github ticket for it? Thanks, JP On Wed, May 6, 2015 at 2:06 PM, Christopher Felton <chr...@gm...> wrote: > On 5/6/2015 12:58 PM, Juan Pablo Caram wrote: > > Oh, sorry, I didn't actually run your notebook. I just didn't (and still > > don't) see the difference between my code and yours. > > > > I'm not explicitly using _SuspendSimulation or StopSimulation. I don't > know > > why the simulation "stops" with _SuspendSimulation instead of > > StopSimulation. It's stopping at the end of the specified time in > > sim.run(stoptime). > > Understand, _SuspendSimulation and StopSimulation > are the internal exceptions (state) for the simulator. > > When you run the simulator for a specific period > of time: > > sim = Simulation(tb()) > sim.run(100) > > The simulator suspends so that it can resume: > > sim.run(100) > > In my example I did not define a number of simulation > steps to run (the argument to run). When no duration > is specified the simulation runs until there are no > more events or StopSimulation is raised. > > Restarting the simulator in the second condition works > fine but restarting in the first has an issue. > > > > > Okay, now I see it. At the completion of simulation time > _SuspendSimulation > > is raised to exit (this is the bug?). You explicitly use StopSimulation. > > The raising of _SuspendSimulation is not the bug, the > bug is when a new simulation instance is created after > a suspend. > > Regards, > Chris > > > > > ------------------------------------------------------------------------------ > One dashboard for servers and applications across Physical-Virtual-Cloud > Widest out-of-the-box monitoring support with 50+ applications > Performance metrics, stats and reports that give you Actionable Insights > Deep dive visibility with transaction tracing using APM Insight. > http://ad.doubleclick.net/ddm/clk/290420510;117567292;y > _______________________________________________ > myhdl-list mailing list > myh...@li... > https://lists.sourceforge.net/lists/listinfo/myhdl-list > |