Google Colab Notebooks
Run FZ examples directly in your browser with Google Colab - no installation required!
What is Google Colab?
Google Colab is a free cloud-based Jupyter notebook environment. It's perfect for trying FZ without setting up a local environment.
Available Notebooks
1. Getting Started
Core FZ workflow: fzl, fzi, fzc, fzo, fzr — Perfect Gas PV=nRT end-to-end example.
What you'll learn:
- Installing FZ in Colab
- Listing available models with
fzl - Parsing variables with
fzi - Compiling templates with
fzc - Running parametric studies with
fzr - Parsing outputs with
fzo - Visualizing results with matplotlib
2. Variable Syntax & Formulas
All variable syntaxes, @{} formula expressions, #@ context code, and delimiter styles.
What you'll learn:
$name,${name},${name~default}variable forms@{expr}inline formula evaluation (Python & R)#@ codecontext blocks and#@: staticconstants- Legacy
?(name)syntax - Custom delimiter styles:
(),{},[],<>
3. Parametric Studies (fzr)
Grid and DataFrame inputs, progress callbacks, parallel calculators.
What you'll learn:
- Factorial grid inputs (dict of lists)
- Explicit scenario inputs (DataFrame)
- All callback signatures (
on_start,on_case_start,on_case_complete,on_progress,on_complete) - Running cases across multiple parallel calculators
4. Design of Experiments (fzd)
Adaptive sampling, 1D minimization, N-D optimization, and Monte Carlo.
What you'll learn:
- Random sampling over a parameter space
- 1D minimization with Brent's method
- N-D optimization with BFGS (Rosenbrock function)
- Monte Carlo estimation of π with convergence analysis
5. Caching & Advanced Features
Cache reuse, multi-output models, logging, coarse-to-fine DOE.
What you'll learn:
- Cold vs warm cache speed comparison
- Numpy array inputs
- Multi-output model parsing
- Logging levels and
print_config() fzl(check=True)model validationalgorithm_optionstuning- Coarse-to-fine DOE with
cache://reuse
Creating Your Own Colab Notebook
Step 1: Install FZ
Add this cell at the beginning:
For plugins:
Step 2: Install Dependencies
# For OpenModelica
!apt-get update
!apt-get install -y omc
# For visualization
!pip install matplotlib seaborn pandas
Step 3: Create Input Files
Step 4: Create Calculation Script
%%writefile calculate.sh
#!/bin/bash
source $1
# Your calculation
echo "result = $temp" > output.txt
!chmod +x calculate.sh
Step 5: Run FZ
import fz
model = {
"varprefix": "$",
"output": {"result": "grep 'result = ' output.txt | awk '{print $3}'"}
}
results = fz.fzr(
"input.txt",
{"temp": [100, 200, 300]},
model,
calculators="sh://bash calculate.sh",
results_dir="results"
)
print(results)
OpenModelica Example
Complete notebook for dynamic system simulations:
# Install OpenModelica
!apt-get update -qq
!apt-get install -y omc
# Install FZ
!pip install git+https://github.com/Funz/fz.git
# Create Modelica model
%%writefile Oscillator.mo
model Oscillator
parameter Real omega = $omega; // Natural frequency
parameter Real zeta = $zeta; // Damping ratio
Real x(start=1.0);
Real v(start=0.0);
equation
der(x) = v;
der(v) = -omega^2 * x - 2*zeta*omega*v;
end Oscillator;
# Create simulation script
%%writefile simulate.sh
#!/bin/bash
# Compile Modelica model
omc -s Oscillator.mo
# Run simulation
./Oscillator -override omega=$omega,zeta=$zeta -r=result.mat
# Extract peak overshoot
python3 << EOF
import scipy.io
mat = scipy.io.loadmat('result.mat')
x = mat['data_2'][0] # Position data
peak = max(abs(x))
print(f"peak_overshoot = {peak}")
EOF
!chmod +x simulate.sh
# Define FZ model
import fz
model = {
"varprefix": "$",
"output": {
"peak_overshoot": "grep 'peak_overshoot = ' stdout | awk '{print $3}'"
}
}
# Run parametric study
results = fz.fzr(
"Oscillator.mo",
{
"omega": [1, 2, 5, 10], # 4 frequencies
"zeta": [0.1, 0.3, 0.7, 1.0] # 4 damping ratios
},
model,
calculators="sh://bash simulate.sh",
results_dir="oscillator_results"
)
# Visualize
import matplotlib.pyplot as plt
import seaborn as sns
pivot = results.pivot(index='zeta', columns='omega', values='peak_overshoot')
sns.heatmap(pivot, annot=True, fmt='.2f', cmap='RdYlGn_r')
plt.title('Peak Overshoot: Damping vs Frequency')
plt.show()
Plugins in Colab
Installing Plugins
# Install base FZ
!pip install git+https://github.com/Funz/fz.git
# Install plugins
!pip install git+https://github.com/Funz/fz-moret.git
!pip install git+https://github.com/Funz/fz-mcnp.git
# etc.
Using Plugin Models
from fz_moret import get_model
# Use plugin model
model = get_model('moret')
results = fz.fzr(
"input.txt",
variables,
model,
calculators="sh://bash run_moret.sh"
)
Accessing Files in Colab
Upload Files
from google.colab import files
# Upload input files
uploaded = files.upload()
# Select files from your computer
Download Results
# Download results CSV
results.to_csv('results.csv', index=False)
files.download('results.csv')
# Download all results directory
!zip -r results.zip results/
files.download('results.zip')
Mount Google Drive
from google.colab import drive
drive.mount('/content/drive')
# Save to Drive
results.to_csv('/content/drive/MyDrive/fz_results.csv', index=False)
# Load from Drive
import fz
results = fz.fzo('/content/drive/MyDrive/previous_results', model)
Tips for Colab
1. Session Timeout
Colab sessions timeout after inactivity. For long runs:
# Keep session alive
from google.colab import output
output.no_vertical_scroll()
# Save checkpoints
for i in range(0, len(all_cases), 10):
batch = all_cases[i:i+10]
results = fz.fzr(...)
results.to_csv(f'checkpoint_{i}.csv')
2. GPU/TPU Not Needed
FZ doesn't use GPU/TPU. Use default runtime:
3. Install System Packages
# Install bc for calculations
!apt-get install -y bc
# Install simulation tools
!apt-get install -y modelica
4. Debugging
Enable debug logging:
View execution logs:
Sharing Your Notebook
- Save to GitHub:
- File → Save a copy in GitHub
-
Choose your repository
-
Get Colab Link:
-
Add Badge to README:
Example Notebooks Repository
All example notebooks are available at:
https://github.com/Funz/fz-notebooks
Clone to customize:
Next Steps
- Perfect Gas Example - Detailed walkthrough
- Modelica Integration - Dynamic systems
- Plugins - Explore available plugins
- User Guide - Deep dive into FZ