Basics

Saving and Loading Files

Save Optiland systems as human-readable JSON and restore them later.

BeginnerBasicsNumPy backend3 min read

Introduction

This tutorial shows the minimal workflow for serializing an Optiland optical system to disk and restoring it later. The saved file is a readable JSON document, which makes it convenient for versioning, sharing, and reproducible examples.

The example uses the built-in UVReflectingMicroscope sample so you can compare the system before and after reloading.

Core concepts used

save_optiland_file(system, path)
Serializes an Optiland model to a JSON file on disk.
load_optiland_file(path)
Reconstructs an Optiland model from a saved JSON file.
UVReflectingMicroscope()
Provides a ready-to-use sample system for testing the save/load workflow.
draw()
Visualizes the optical layout before and after serialization.

Step-by-step walkthrough

1

Set up and preview the sample microscope

Import the save/load utilities and a built-in optical system, then instantiate and draw it to establish a visual baseline before serialization.

python
from optiland.fileio import load_optiland_file, save_optiland_file
from optiland.samples.microscopes import UVReflectingMicroscope

system = UVReflectingMicroscope()
_ = system.draw()
UV Reflecting Microscope optical layout
2

Save the system as JSON

Write the full optical model to a human-readable JSON file.

python
save_optiland_file(system, "uv_reflecting_microscope.json")
3

Reload and verify the saved system

Reconstruct the optical system from the saved JSON file, then draw it to confirm the reloaded model is identical to the original.

python
new_system = load_optiland_file("uv_reflecting_microscope.json")
_ = new_system.draw()
Reloaded UV Reflecting Microscope optical layout

Full code listing

Show full code listing
python
from optiland.fileio import load_optiland_file, save_optiland_file
from optiland.samples.microscopes import UVReflectingMicroscope

system = UVReflectingMicroscope()
_ = system.draw()

save_optiland_file(system, "uv_reflecting_microscope.json")

new_system = load_optiland_file("uv_reflecting_microscope.json")
_ = new_system.draw()

Conclusions

Saving Optiland models as JSON gives you a lightweight way to archive, exchange, and reload systems without rebuilding them manually. This is especially useful for tutorial assets, regression examples, and collaborative design work.

Next tutorials

Original notebook: Tutorial_1c_Save_and_Load_Files.ipynb on GitHub