Show waves in Modelsim with Cocotb - modelsim

I'm getting started with cocotb.
I can run the example tests. They don't fail and cocotb terminates with success. My usual simulator is modelsim. If I start cocotb with:
make GUI=1 WAVES=1 I get the GUI of modelsim and can see the signals in the objects window. The only thing I did never get are the signals in the wave window. I can add them manually over the GUI, but this is too late. The test has already finished.
What is the correct way to select the waves I want to see?

Try setting the SCRIPT_FILE makefile variable to point to a modelsim wave.do file, which you should be able to produce from the GUI.

Related

%debug magic command not working in the Q# Jupyter Notebook environment

As per the documentation provided by Microsoft Azure Quantum at this link , I followed the steps given and installed Q# with Jupyter Notebook, using Anaconda.
I then wrote the following Q# program in a Jupyter Notebook (IQ# kernel) using the code taken from here.
(I am currently using Google Chrome)
open Microsoft.Quantum.Diagnostics;
operation MultiQubitDumpMachineDemo() : Unit {
use qubit = Qubit();
H(qubit);
DumpMachine();
Reset(qubit);
}
When I used the magic commands such as %simulate and %trace, the program executed normally. The DumpMachine result clearly shows the qubit in a superposition of |0> and |1> (measurement probability is 50%), and the trace command printed out the quantum circuit.
%simulate Result
%trace Result
However, when I run the %debug command, the interactive HTML display does not work. The debug control button can display the circuit but, the controls for the chart options do not display the amplitudes, probabilities, or real/imaginary co-efficients.
When I opened the console, I observed the following error, every time I clicked the chart options controls:
Couldn't process kernel message TypeError: state.getDenseAmplitudes is not a function
at fitChart (bundle.js?v=20221015232727:292:32)
at Object.updateChart (bundle.js?v=20221015232727:277:9)
at update (bundle.js?v=20221015232727:811:32)
at bundle.js?v=20221015232727:850:17
at Kernel._handle_iopub_message (main.min.js?v=a4e125c812cb3975203ae429a5b40d180b59b8e4602fcc78390ef4f0dd4d14ac3559189f65f23cd50fd971f98f5842b7746f4182babd20b7ca84e52314bcd4ac:63064:20)
at Kernel._finish_ws_message (main.min.js?v=a4e125c812cb3975203ae429a5b40d180b59b8e4602fcc78390ef4f0dd4d14ac3559189f65f23cd50fd971f98f5842b7746f4182babd20b7ca84e52314bcd4ac:62843:29)
at main.min.js?v=a4e125c812cb3975203ae429a5b40d180b59b8e4602fcc78390ef4f0dd4d14ac3559189f65f23cd50fd971f98f5842b7746f4182babd20b7ca84e52314bcd4ac:62834:44
Error Message
Unfortunately, I am not familiar with this type of error or its possible solutions, so I didn't try anything more than updating the 'iqsharp' package.
Can anyone explain why I'm getting this error, and, if possible, provide with me a solution for the same?
Thanks in advance!

Clean workspace, plot pane, and console on rerun in Julia

I am used to starting all my Matlab scripts with clear all; close all; clc to ensure I am not looking at any old data or plots. I found Julia's clearconsole() to be equivalent to Matlab's clc, but don't have working solutions for the other two Matlab commands yet. I mostly work in the Juno IDE and run scripts with the Play ("Run All") button.
The Revise.jl package is supposed to clear the workspace now that workspace() is deprecated, but it doesn't work for this simple test case. If I define x once and then comment that line out, it will continue to print each time I run without error.
using Revise
clearconsole()
#x=1
println(x)
I know I can hit "Stop" then "Play" to reset the workspace. However, that still doesn't close old plots, and the time to first plot issue makes this option undesirable.
I found the "Forget All Plots" button in Juno's plot pane, but I would like to have that functionality as a line in my script instead. Currently, it takes me three clicks to run a script again after I edit it (four if I include "Stop").
"Forget All Plots"
Somewhere in the editor to put focus back on my current file.
"Run All"
I would ideally like to rerun in a fresh environment with one click or keystroke, but any tips on a better Juno workflow would be appreciated.
My question was answered on the Julia discourse website: link.
Juno.clearconsole() may be used like Matlab's clc.
Writing a script within a module will clear the variables upon each run like Matlab's clear all.
A new function may be added to Juno.jl in the future which will work like Matlab's close all.

R/Rstudio Frustration - Can't Stop Code Execution

I often include View() statements in my R scripts. If I accidentally forget the closing bracket at the end of the line, and then run the line of code from the script window using ctrl-enter, R just keeps trying to execute the remainder of my script. I don't know why it does that (rather than using the + symbol to prompt me to provide further input).
Moreover, I've tried to stop this by setting break points in my code - I can click on the LHS of the page and a little red circle appears. But the breakpoints don't seem to work - R just ignores them and keeps going.
The only way I can get out of it is by killing the process in the Windows task manager and then going back in afterwards. But it's wasting a lot of time.
Does anyone know how I can fix this please?
Thank you.
In effect, what your function is processing looks like that:
... %>% View(
lm(am~cyl, mtcars)
...
...
As R can't find the bracket for ) it includes remaining statements as input to View and searches for the bracket.
Solutions
Kind of depends on what you want to do with those scripts but if the intention is to run them in the background consider using callr. This package lets you run R from R and offers kill methods to kill the process you started that way.
On Windows pressing Esc should enable you to get back to the console but if it's a memory intense process it may be difficult.
You may try pressing Ctrl+c in order to kill the process.

keyboard shortcut for step out while debugging in rstudio

When I'm debugging, every time, I make a change to the source code, I find myself doing the following since it says, "Debug location is approximate because the source is not available.". Is this 3-step process necessary? Is there an easier way?
> debugSource('~/Desktop/foo1.R')
> debug(myfun1)
> myfun1()
Not sure that this is, what you want, but since you use the tag rstudio, it might help.
Clicking in the left border of the script window in RStudio (next to the line numbers) creates a break point. It is marked by a red circle (it it's inside a function) or a red dot (otherwise). If you now click the source button in RStudio, debugSource is run. If the program encounters a breakpoint, it stops and you are able to examine the state of the program. A breakpoint inside a function stops the code when the function is run (and not when it is sourced). The breakpoint will also work when you run the function from the console as in your example.
The breakpoint remains intact when you change your code. So you have, of course, to source your code after every change, but you don't need to rerun debug every time.
For more information on debugging with RStudio, the following link might be helpful: https://support.rstudio.com/hc/en-us/articles/200713843-Debugging-with-RStudio

Is there a hack to be able to run the current line or selection in RStudio without moving the cursor?

UPDATE (April 2013): As per answer below, RStudio no longer jumps cursor on selection.
I'm running RStudio 0.97.168.
I like to use the script editor in RStudio like a console. Thus, I run a line of code and then edit it a little bit and re-run it. I often also explore objects by selecting some of the code and running the selection and then progressively altering the selection. At present RStudio always moves the cursor after running a line of code. The cursor can move to a variety of places. Typically the cursor moves to the next line of R code, but depending on the context, it could move to the end of the code block or the next line. It's really frustrating having to constantly move the cursor back to where I want it.
While I often appreciate the default cursor movement behaviour, I'd like to have the option to run the selection or the current line without the cursor moving.
I've raised this as a suggestion on RStudio support.
I'd like to be able to have a shortcut key like "Cmd+Alt+Enter" that runs the current line or selection and does not move the cursor in the script editor.
I realise that this is not currently supported, but I was wondering whether there might be some creative hack that could enable the cursor not to move after running a command or even a patch or perhaps some sort of external macro.
For anyone who ends up here in 2020:
Ctrl(or Cmd) + Enter: Will run current line and jump to the next one. If a code portion is selected, run the selected code without jumping further.
Alt + Enter: – Will run the current line of code without moving the cursor to the next line, useful if you want to run it multiple times.
(Source)
For this kind of flexibility, I suggest you use the editor Sublime Text 2, add in the package installer by Will Bond and then install the SublimeREPL package which will allow you to use an R interpreter within ST2 (or BASH prompt, Python / Ruby / whatever interpeter, concurrently if you wish).
You can then alternate between your code and the interpreter without lifting your fingers from the keyboard and your cursor will be at the same point every time when you want to switch back.
Sublime Text will also allow you to write a custom keybinding to automate this task.
I cannot recommend using Sublime Text 2 highly enough when coding for R. You can even pass files directly from ST2 into RStudio very easily if you like using the plot panes (very easy to do with the SidebarEnhancements package in ST2).
RStudio is awesome for many things -- especially now with Knitr, builds etc etc. But ST2 with an R REPL is many orders of magnitude more powerful for general code writing / editing than RStudio.
Sorry it's not RStudio specific, but it is a nice workaround!
I updated to version 0.98.83 of RStudio using the daily build section.
It appears that at some point in recent versions of RStudio, the cursor no longer jumps when code is run from a selection in the script window.
That's great news.

Resources