Scientific ML Studio
Learn/ Studio Tour/ 4.1
4.1 · Getting the code out

Check the graph and generate the code

Two buttons turn the canvas into a Python file. This page covers what each one does, what the Graph check strip is telling you, and what happens the first time you press them.

Everything you have built on the canvas is saved as a graph: a list of blocks, their settings and the wires between them. Generating code means translating that graph into one Python file. The translation happens in your browser. Nothing is sent anywhere to build the script, so it works the same for a private notebook as for a starter.

The two buttons

Both are at the right of the bar above the canvas.

Button What it does
Generate code Builds the script and shows it in a window. You can read it, copy it, or download it from there
Download .py Builds the script and saves it straight to your downloads folder, without showing the window

The file is named after the notebook, in lower case with hyphens: a notebook called Poisson 1D gives poisson-1d.py.

While the script is being built, the window says Building the script… the first run loads Python into your browser and can take a few seconds. The Lab's engine is Python running inside your browser; if it has not finished starting yet, the first build waits for it. Later builds are quick.

The Generate code window

The window has a heading, Generated script, the script itself, and three buttons:

  • Copy code puts the whole script on your clipboard. The button says Copied for a moment. If your browser blocks clipboard access, it says Copy failed -- select manually; click inside the code, select all, and copy by hand. Use this to paste into a Colab cell.
  • Download .py saves it, the same as the button on the bar.
  • Close closes the window. So do the Esc key and a click on the dark area outside it.

Your screenshot · the Generated script window open over the studio, with the code visible and the three buttons at the top right.

When a button is greyed out

Only one thing disables the buttons: a loss weight list that cannot be read. The Loss block's BC or IC weights must have exactly one number per connected condition (see Balance the loss). While a list is wrong, Generate code is disabled, and hovering over either button shows the first problem as a tooltip. Fix the red list in the Loss panel and the buttons come back.

Everything else is a note, not a stop. Even a nearly empty canvas produces a file. It is a short stub whose comments say what is missing, which is why the Graph check is worth reading before you press the button.

The Graph check strip

The strip below the canvas reads your graph after each change and reports what it finds, in plain sentences. There are three states.

  • Graph check: waiting for the Lab engine to load… — Python is still starting. Wait a few seconds.
  • Graph check: nothing to flag. — the graph is complete as far as the Lab can tell.
  • Graph check — 2 notes (or however many), followed by a list. Each note says what is missing or unusual. Many include their own remedy.

Read the notes as advice. The Lab will generate a script regardless and fill any gap with a stated default, for example No Optimisation block is wired in. Adam at 1e-3 is used. Whether that default suits you is your decision. The notes are also copied into the docstring at the top of the script, under the heading Graph check, so you can see them again later.

Every note and what to do about it is listed on When the Graph check complains.

What the check cannot tell you

The Graph check counts and matches: is there a condition for every edge, does an equation that changes in time have an initial condition. It cannot tell whether the formulas you wrote make physical sense, whether the signs are right, or whether the problem is well posed. A graph with no notes can still describe the wrong problem.

The first time: a short registration form

The site may ask you to register once, the first time you use Generate code or Download .py. A form titled Before you generate code appears. It asks for your name, email, affiliation, what you will use the Lab for (with a further question if the answer is commercial use), and how you found the site, and it asks you to confirm that you have read the usage terms and the privacy notice.

Once you have sent it, the browser remembers, and you are not asked again on that browser. If the registration service cannot be reached, the form offers Continue anyway, so a technical fault never stops you from working. Closing the form without sending either carries on for a while without asking again, or (if the site is set to insist) stops the generation; the site's configuration decides which.

The licence note at the top of the file

Every script begins with a licence paragraph in its docstring. In short: the code is licensed under CC BY-NC 4.0. You may share and adapt it for non-commercial purposes, as long as you credit Scientific ML Studio and say what you changed. Commercial use, paid client work and production deployment need written permission, which you ask for through the Contact page.

Leave that paragraph in place if you pass the file on. It is the reason the notice is the first thing in the file.

Next: running the script on your computer or in Colab.