Getting OpticSim.jl to work

The documentation for OpticSim.jl says that I should “Run this example to check that everything installed properly”. The example produces the following for me:

julia> using OpticSim

julia> Vis.draw(SphericalLens(OpticSim.GlassCat.SCHOTT.N_BK7, 0.0, 10.0, 10.0, 5.0, 5.0))
ERROR: UndefVarError: SCHOTT not defined
 [1] getproperty(x::Module, f::Symbol)
   @ Base ./Base.jl:31
 [2] top-level scope
   @ REPL[5]:1

System information:

julia> using Pkg

julia> Pkg.status("OpticSim")
Status `~/.julia/environments/v1.8/Project.toml`
  [24114763] OpticSim v0.6.0 ``

Any help?

Use Examples.Examples_N_BK7 instead of Schott. When that documentation was written we were using Schott glasses for many examples. But Schott kept changing the location of their glass catalog on their website which made it impossible to automatically download. That caused the examples to fail unpredictably.

Instead of using Schott glasses we switched to locally defined glass files. You can find them in the Examples module.

Most of the examples were rewritten to use locally defined glasses instead of Schott but we missed that one.

The repo has been updated with this fix to the documentation.


With your quick answer, the project seems supported (as documented; i.e. only by answering here question on discourse). I do see in the docs:

OpticSim.jl is optimized for use with Julia 1.7.x; using other versions will probably not work.

Julia 1.7 is no longer supported, so I take that as 1.8+ should work… but not older.


I don’t know much about Microsoft’s three Julia packages/repos (two active): Microsoft · GitHub

except that they archived that repo, and it moved to your personal github. I was very intrigued to see your/Microsoft’s project at the time (that they were supporting Julia), your package seems substantial and impressive, as is this new one: GitHub - microsoft/MPNODE.jl (depending on e.g. RobotDynamics.jl):


This repo contains the code associated with the paper Learning Modular Simulations for Homogenous Networks. Also see the blogpost.

Autonomous Systems and Robotics Group / Articles

Towards Modular Data-driven Simulations

November 23, 2022

The use of modeling and simulation in engineering is well recognized as a viable method to build surrogates for real-world systems. […] Simulation also plays a key role in AI […] A large amount of literature on data-driven simulations has explored the idea of building simulations through graph neural networks, such as the method in Learning to Simulate Complex Physics with Graph Networks. […] such approaches lack generalizability.

Given the inherent modularity of several real-life systems, we propose a method which places focus on individual nodes instead of the full graph. Our approach uses Neural Ordinary Differential Equations (NODE) to model a single dynamic entity.

From linked DeepMind/Google/Stanford paper:

Our framework—which we term “GraphNetwork-based Simulators” (GNS)
[…] Our GNS framework advances the state-of-the-art in learned physical simulation, and holds promise for solving a wide range of complex forward and inverse problems.

Nice! Thanks for the fix, and explanaition, I will test that the next time I work on that subject. Much appreciated.

I am taking an a course called “optical system engineering”, where it seems we will use Zemax’s Optics Studio (ZOS). It is explicitly not a course in ZOS, but it was clear that it will play a central role. I am running Linux, but have ZOS running in my virtual windows machine. I started looking into this package as a free and native linux alternative (I am a sucker for free and open source).

Is this a path worth investigating do you think? OpticSim as an alternative to follow along a class that uses ZOS?

I’ve worked with many optical engineers over the years and most of them have eventually encountered a problem that was better addressed by writing a program than using the Zemax UI. For these applications OpticSim could be better than Zemax.

We created OpticSim for just such a problem, designing multi-lens optics for head mounted displays. We found it difficult to use Zemax to create and simulate the complex systems we were developing.

The Zemax UI was not a practical way to specify and model these systems with hundreds or thousands of lenses, most of which used off axis freeform elements. It was much easier to write a program than to model them interactively. Julia was a better language for this purpose than the Zemax scripting language: Julia is more powerful, has better IDE support in the form of VSCode, executes more quickly, and is easier to debug.

OpticSim is also much faster than Zemax at non-sequential ray tracing of complex optical systems created with CSG operations. This was critical for our scattered light analyses.

However, Zemax has strong optimization features; OpticSim has limited support for optimization. We may improve OpticSim optimization but there are no firm plans to do so.


Alright, new problem on the next line.
I am getting a Makie figure from

Vis.draw(SphericalLens(Examples.Examples_N_BK7, 0.0, 10.0, 10.0, 5.0, 5.0))

The next line however gives

ulia>"assets/test_install.png") # hide
ERROR: MethodError: no method matching size(::Makie.Figure)
Closest candidates are:
  size(::Union{LinearAlgebra.QR, LinearAlgebra.QRCompactWY, LinearAlgebra.QRPivoted}) at ~/.julia/juliaup/julia-1.8.3+0.x64.linux.gnu/share/julia/stdlib/v1.8/LinearAlgebra/src/qr.jl:581
  size(::Union{LinearAlgebra.QR, LinearAlgebra.QRCompactWY, LinearAlgebra.QRPivoted}, ::Integer) at ~/.julia/juliaup/julia-1.8.3+0.x64.linux.gnu/share/julia/stdlib/v1.8/LinearAlgebra/src/qr.jl:580
  size(::Union{LinearAlgebra.Cholesky, LinearAlgebra.CholeskyPivoted}) at ~/.julia/juliaup/julia-1.8.3+0.x64.linux.gnu/share/julia/stdlib/v1.8/LinearAlgebra/src/cholesky.jl:514
 [1] save(path::String)
   @ OpticSim.Vis ~/.julia/packages/OpticSim/5FrKf/src/Vis/Visualization.jl:269
 [2] top-level scope
   @ REPL[1]:1

Edit: Versions:

(@v1.8) pkg> st
Status `~/.julia/environments/v1.8/Project.toml`
⌃ [1520ce14] AbstractTrees v0.4.3
  [4eb35182] AutoSysimages v0.2.6
  [6e4b80f9] BenchmarkTools v1.3.2
  [54eefc05] Cascadia v1.0.2
⌃ [992eb4ea] CondaPkg v0.2.14
⌃ [717857b8] DSP v0.7.7
⌃ [a93c6f00] DataFrames v1.4.3
⌃ [82cc6244] DataInterpolations v3.10.1
  [0c46a032] DifferentialEquations v7.6.0
⌃ [31c24e10] Distributions v0.25.79
  [08be435b] EasyFFTs v0.2.0 `~/.julia/dev/EasyFFTs`
  [7a1cc6ca] FFTW v1.5.0
  [5789e2e9] FileIO v1.16.0
⌅ [e9467ef8] GLMakie v0.7.3
  [708ec375] Gumbo v0.8.2
⌅ [cd3eb016] HTTP v0.9.17
  [aef96434] HypothesisTestsExperimentalRedo v0.1.0 ``
⌃ [6218d12a] ImageMagick v1.2.1
⌃ [de52edbc] Integrals v3.3.0
⌃ [d2bf35a9] IntervalRootFinding v0.5.10
⌃ [23fbe1c1] Latexify v0.15.17
⌃ [7ed4a6bd] LinearSolve v1.29.0
  [2fda8390] LsqFit v0.13.0
  [23992714] MAT v0.10.3
  [10e44e05] MATLAB v0.8.3
  [eff96d63] Measurements v2.8.0
⌃ [8913a72c] NonlinearSolve v1.1.0
⌃ [5fb14364] OhMyREPL v0.5.12
  [24114763] OpticSim v0.6.0 ``
⌃ [9b87118b] PackageCompiler v2.1.0
  [65888b18] ParameterizedFunctions v5.15.0
⌃ [18e31ff7] Peaks v0.4.1
⌃ [14b8a8f1] PkgTemplates v0.7.29
⌅ [c3e4b0f8] Pluto v0.19.9
⌃ [438e738f] PyCall v1.94.1
⌃ [6099a3de] PythonCall v0.9.9
⌃ [295af30f] Revise v3.4.0
  [f2b01f46] Roots v2.0.8
  [82ae8749] StatsAPI v1.5.0
  [2913bbd2] StatsBase v0.33.21
  [78aadeae] SymbolicNumericIntegration v0.8.6
⌅ [0c5d862f] Symbolics v4.13.0
  [c544e3c2] Tau v1.0.0
  [6aa5eb33] TaylorSeries v0.12.2
⌃ [22787eb5] Term v1.0.5
⌃ [731e570b] TiffImages v0.6.2
  [75d8cae4] Tools v0.1.0 ``
⌃ [b8865327] UnicodePlots v3.3.0
⌃ [1986cc42] Unitful v1.12.1
⌅ [276b4fcb] WGLMakie v0.7.3
  [fdbf4ff8] XLSX v0.8.4
Info Packages marked with ⌃ and ⌅ have new versions available, but those with ⌅ are restricted by compatibility constraints from upgrading. To see why use `status --outdated`

Thank you for the detailed reply. I think I will start by trying to use both, and see whatever fits my needs and wants the best :slight_smile:

@TheLateKronos Create an issue on the OpticSim repo for the size error in Makie. I’ll get around to it. Makie changes frequently; this is probably a backward incompatibility problem because we updated to a newer version of Makie than we should have.

1 Like

Will do. Thanks