Coder V1

0 views
Skip to first unread message

Francisca Noggles

unread,
Aug 5, 2024, 7:00:49 AM8/5/24
to esaculak
Icreated an experiment in the PsychoPy builder and it ran smoothly. Then I wanted to clean the code and insert some custom functions (mainly to control the appearance of rating scales in several routines). I occasionally ran the experiment in Code View to insure that it still runs. It did! But when I started it again from Builder View, all my changes were gone. Of course I did save it before I ran the code. I have quite a number of routines so I really would like that the changes that I make in Coder View are applied to my experiment. Can anybody help me out here? Am I getting something wrong about how Builder and Coder interact?

Hi - every time you press the compile button, Psychopy builder creates a .py file file with the same name as the .psyexp file. This will overwrite if there is a .py file with the same name in the same directory.


This is currently a one way street because the builder components are standardised in XML format and are formatted as python code on compilation - going backwards on this introduces too many variables to deal with at this point, so you will have to repeat the changes every time you make a change in builder and then return to coder.


@fragmag, Builder has the option to use the Code Component. The code component opens a window, allowing you to enter custom code at different stages of your experiment. For example, at the beginning of your experiment, the beginning of your trial, during your trials on every screen refresh, etc. You can now also select whether you want to use Python or JavaScript coding, and have them compared side by side for easier translation using the code type drop down in the code component window. When you run your experiment, or compile your code, the code from the code components is inserted into your Python or JS scripts which are used to run the experiment.


Coder is a free, open source project that turns a Raspberry Pi into a simple platform that educators and parents can use to teach the basics of building for the web. New coders can craft small projects in HTML, CSS, and Javascript, right from the web browser.


Coder is designed for creating, editing, and running simple web apps. Coder apps are built using the standard building blocks of the web (HTML, CSS, and Javascript), and they can be crafted directly in your web browser. Click through the images below for a quick tour of Coder.


Your Coder's landing page contains all of your apps, organized by most recent. You can create new apps by clicking the Green '+' app in the top left. The gear in the top right opens your Coder's settings where you can change things like your name, password, wireless settings, and more.


This is Coder's development environment. It's a simple browser-based editor with quick access to all the files that make up your app. It also has a few extra tools to tweak, preview, save, and export your work.


Finally, the gear icon opens a project's settings. Here you can name your app, give yourself credit as the author, change its color on the homescreen, or export the whole thing to share with other coders.


To reset your Coder's password, place the Coder SD Card in another computer and place a file named "reset.txt" in the coder_settings directory. The reset.txt file doesn't need anything in it, and you can make it with any text editor. The next time your Coder boots using this card, it will find the reset.txt file and ask you to set a password, similar to the first time you started your Coder. All of your other data will remain on the device.


Some background for people reading this in the future (in case it's not locked). I tend to do my programming in a high level language to understand the problem first. After covering all possible corner cases I proceed to translating the code to C++ (or C).


This is a very opinionated post based on my expirience for one particular project. I have not used the latest version of the coder, but I do have expirience with the equivalent product (embedded coder) for converting matlab code to C++ that was included as part of the former Real Time Workshop product. These comments should still apply. Your mileage may vary.


In my situation, the embedded coder was used to make a processing block that fit into part of a larger audio application. The processing block had the job of processing a constant stream of sample buffers in real time. I made the original algorithm in matlab, and the conversion tool made it fairly simple to convert an early prototype into something that could be compiled to native code and used in a real time application. It was also nice to assume that the converted code was functioning numerically identically to the original without possibility of human error in the conversion process (assuming superhuman abilities of Mahworks engineers).


As the algorithm grew in complexity, i started worrying more and more about how to code the matlab interface to the function so that after conversion, it would be easy to interface with the C++ framework (I wanted to monitor the internal states in real time). This eventually started using as much time as the actual algorithm development itself, thus defeating the purpose of using such a tool. I could have broken down the algorithm into smaller chunks and then glued them together using C++, but then I'd loose the ability to have a direct Matlab-only comparison of he complete algorithm.


The coder supports a subset of the Matlab language. In some cases, supported functions are limited in some way. For example, in the application that I was working on, I wanted to be able to modify the characteristics of a filter in real time. I could not use the standard Matlab filter prototyping functions, because the code generation tool would not allow calls to the filter prototyping function with variable arguments. I ended up spending time with a DSP book developing my own implementation, even though we have a signal processing toolbox license.


I got frustrated with the interface issues and coded the algorithm by hand in C++. For my application, there was a 75% performance boost in the favour of the hand written code over the converted code. Performance differences will be very different depending on your application, probably the version of the conversion tool used, and your fondness of your profiler. The conversion tool itself is a complex product that has many settings to learn. Trying to work out how to tweak settings and the matlab code to improve performance uses more time that could be spent hand coding.


I now prefer a more test-assisted approach. I code a prototype in Matlab and tweak until I am sure that it behaves as I want it too. I then think in C++ and recode the algorithm in a way that is more natural to that language. I then make a mex file that interfaces with my C++ code so I can test it against my trusted matlab equivalent. For the problem space that I work in, this is a much more efficient (human and machine) way to get stuff done.


In conclusion, this is just the opinion of one user. Perhaps (as suggesred in a comment on your original post) you should sign up for the trial to see how you get along. However, if you are a bit of a C++ ninja, testing by building mex files does not require an expensive license for an add-on product and it will make you a better developer.


Comparing MATLAB and C or C++ for performance is very complicated. C or C++ are going to be faster in most cases, but in some linear algebra applications it is possible that MATLAB will execute the fastest. I remember a professor that claimed he had FORTRAN applications that ran slower than the equivalent in MATLAB. There are a lot of case studies on this - I would recommend you look at the different studies comparing the speed that turn up in google and compare them to what you're doing to make your decision.


Where I work, we've developed a good management scheme for our Simulink models and their dependencies. Then I've developed a script to proceed with the autocoding step and a colleague developed project files in an IDE, such that upon running my script, all source files are dispatched to a proper folder structure and the project can be readily compiled in the IDE, where someone else also deployed a wrapper code to interface the autocoded software.


The trick (IMHO) is to automate your process the best you can as early as you can. By doing so, you can develop very complex models and then create C code for production in a couple hours. And you can update the models all you like, but the code keeps easy to maintain.


Also, you should really put some testing in place to verify that the generated code does indeed represent the model you had. This is not guaranteed, and while I think Matlab Coder is pretty reliable, it is not error-free.


As it has been said above it depends upon ur application. I tried to convert the decoder (of a communication system) it gives the accurate results but for large number of bits it is slower than its own MATLAB version. So my conclusion was to convert MATLAB code to C by hand.


Another benefits I know: Since it's optimized for technical programming, you may have better performance when writing application on this field. The performance is very dependable, take a look at this question, it provides some helpful information.


I think MATLAB has lots of limitation over normal C coding. I agree that there are so many inbuilt blocks which can be used directly but if you write a code in MATLAB then it will take nearly 5 times longer in comparison to C code because from defining variables to taking loops, switch cases, its very time consuming in MATLAB modeling


Picture this, the year was 2003 and I was a newly certified coder working in a medium size cardiology office. After working for four years gaining experience in coding, we merged with a three surgeon cardio-thoracic practice. The practice needed a surgery coder and I landed the position.


So, I packed up my coding books and left the comfort of my fellow coders and headed to the new office. I was a stranger in a strange land, very similar of when I was 21 and in the Navy. I stepped off a plane in Prestwick, Scotland heading to my new home, the USS Simon Lake. I survived that, so I would survive this.

3a8082e126
Reply all
Reply to author
Forward
0 new messages