Skip to the guide
‹ Back to the app CivilKit Buckling · Guide

The Python console

The console runs your own Python scripts in the page, on the same engine as the analysis. A script written for cufsm-rs-py, the Python package (pip install cufsm-rs-py), runs here as it does on your own machine, with the same numbers.

What it is#

The app's buttons solve one section at a time. A script can solve hundreds: sweep a dimension, search a catalogue, check every result against a design rule, and print a table. The console is where such a script runs without installing anything.

  • The same API as the package. import cufsm_rs gives the names, signatures and defaults of cufsm-rs-py: Model, section_properties, first_yield, stress, signature, strip, classify, the templates and cufsm_rs.plot. The Python API reference lists them all.
  • The same engine. Every load factor, mode and property comes from cufsm.wasm, the Rust engine the analysis on screen uses (Engine API).
  • Two Pythons. Most scripts run at once on MicroPython, which the page already has. A script that uses numpy, scipy or matplotlib runs on full Python (Pyodide), downloaded the first time a script needs it, once you agree. MicroPython and full Python explains how the console chooses.
  • Your device only. A script runs in a background worker in your browser. There is no server: nothing you type or run is sent anywhere.

The console is for your own scripts. To give other people a tool with a form and a Verified badge, write an extension instead; extensions stay on MicroPython, in the sandbox (why).

Where it is#

  • On a phone: More in the tab bar, then Python in its switch (Projects | Tables | Extensions | Python).
  • On a desktop or tablet: the Python tab in the results pane's row of tabs.

The console's code, MicroPython and the cufsm_rs package load when you first open it, so a visit that never opens it downloads nothing extra. The first time, the editor holds the analysis on screen as a script (see Use the model on screen); after that it holds whatever you left in it.

The console's Docs link opens this page.

A first script#

Paste this into the editor and press Run (or Ctrl+Enter, on a Mac ⌘+Enter):

import cufsm_rs as fsm
from cufsm_rs.plot import plot_signature

m = fsm.lipped_c(200, 76, 15, 1.9, ri=3)   # outside dimensions and inside radius, mm; steel E in MPa
y = fsm.first_yield(m, fy=450)              # N and N·mm
mc = fsm.stress(m, P=y.Py)                  # uniform compression at the squash load
sig = fsm.signature(mc)                     # CUFSM's 100 default half-wavelengths
print(sig)
for (L, lf), c in zip(sig.minima, sig.classify_minima()):
    print("%6.0f mm  Pcr = %.3f Py  G %3.0f%%  D %3.0f%%  L %3.0f%%" % (L, lf, c[0], c[1], c[2]))
plot_signature(sig, classify=True)
a line StripResult(signature, bc=S-S, 100 lengths …, neigs=1, … minima), one line per minimum of the curve with its load factor as a fraction of the squash load and its cFSM classification, then the signature curve with the minima labelled. The badge above the output reads Ran on: MicroPython.

Because the reference stresses were set from P = Py, each load factor reads directly as Pcr / Py (load factors).

The toolbar#

ControlWhat it does
RunRuns the script in the editor. Ctrl+Enter or ⌘+Enter does the same anywhere in the console.
StopEnds a script that is still running (Stop). Also answers a download prompt that is still waiting.
Examples…Loads one of the shipped scripts. The ones under Full Python (downloads Pyodide when you agree) need full Python. Python examples describes each.
Use the model on screenPuts the analysis on screen in the editor as a cufsm-rs-py script: the model as CUFSM's tables, row for row at full precision, and the same analysis (signature curve, or General BC with its end conditions and terms). The same script as the report's "analysis as Python". Run it and it prints the page's own minima.
Open…Opens a .py or .txt file in the editor. Dropping a file on the editor does the same.
DownloadSaves the editor's text as a .py file: the name of the file or example you loaded, or buckling-script.py.
⤢ Full viewThe console over the whole screen, with the editor beside its output on a wide screen. The same button, or Esc, closes it.
Save outputShown after a run with output. Saves the output, and the traceback if there is one, as a .txt file (figures become a line such as [figure: signature curve]).
Remove full Python from this deviceShown once full Python is stored on the device. Deletes it, and the "always" choice (Always, Remove and offline).

Loading an example, a file or the model on screen replaces the editor's text through the browser's own editing, so Ctrl+Z (⌘+Z) brings back what was there. On a touch screen the text is set directly, so the keyboard does not pop up; Undo cannot bring it back there, so Download first if you want to keep it.

A link to the app with ?py= and an example's file name opens the console with that example in the editor. It does not run it: press Run.

https://mageengineering.com.au/apps/buckling/?py=dsm_lip_study.py
https://mageengineering.com.au/apps/buckling/?py=full/readme_quickstart.py

The name must be one of the shipped examples (the full-Python ones start with full/); any other name leaves the editor unchanged and says there is no such example. Your own scripts cannot be shared this way: send the .py file.

Output and figures#

A run's output appears all at once when the script finishes, never partway. While it runs, the status line counts the seconds. When it ends, the status line says how long it took and how many figures it drew, and the badge says which Python ran it: Ran on: MicroPython or Ran on: full Python (Pyodide). When full Python ran it, or you chose not to download it, a line under the badge says why (the badge).

  • Printed text appears as printed, with each figure in its place between the lines.
  • An error shows its Python traceback, and the editor marks the script's line that raised it. A missing module (on MicroPython) shows a note instead, naming the full Python runtime.
  • cufsm_rs.plot on MicroPython draws with the page's own drawing code: an SVG in the page's colours, which follows the light or dark theme, with a Download SVG button that saves it in the colours on screen. The plot functions lists what differs from matplotlib.
  • matplotlib on full Python (including cufsm_rs.plot there) draws the figure exactly as matplotlib does. Each figure appears where the script calls plt.show(); figures still open when the script ends appear at the end. Each is shown as an image of its SVG, with Download SVG.
  • Every figure has a text alternative for screen readers, read from what it shows (its title, axes and contents).

Each run starts afresh: nothing a script defines is left for the next one. On MicroPython every run gets a new interpreter; on full Python every run gets fresh globals and a clean matplotlib, and the packages already loaded stay loaded, so a second run does not download them again.

Stop#

There is no time limit on a console script (unlike an extension's 20 seconds): the end conditions example can take up to about 25 seconds. Stop ends a run that should not go on, such as an endless loop. The console's background workers are ended and a fresh MicroPython one is started; nothing the script printed is kept. If full Python was loaded, it is unloaded too, and the next script that needs it starts it again from the device's copy (no download).

Drafts and files#

The editor's text is saved as you type, with its file name, in this browser's storage for this site. Close the tab and come back, and it is there. It is one draft per browser on one device: another browser or device, a private window, or clearing the site's data starts afresh, with the analysis on screen as a script. Nothing is uploaded. Keep the scripts that matter as files: Download saves one, and Open… brings it back.

Open takes a .py or .txt file (or any text file) of up to 1 MB, in UTF-8. A file that is too large, is not text or is another kind of file is refused with a message, and the editor is left as it was.

Limits#

LimitValue
Output kept from one run1 MB of text (1,048,576 characters); the output then says it was cut off
Figures in one run50; the 51st raises an error
A file opened in the editor1 MB, text (UTF-8)
Python heap on MicroPython64 MB
Timenone; use Stop
Modules on MicroPythonsee How the console picks one

CivilKit Buckling runs cufsm-rs, a Rust port of CUFSM, the finite strip software by Benjamin W. Schafer and co-workers (constrained FSM with Sándor Ádány), compiled to WebAssembly. An analysis tool, not a design certificate: check what you use.