Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnboundLocalError in ipython #1164

Closed
smartalecH opened this issue Mar 30, 2020 · 1 comment · Fixed by #1165
Closed

UnboundLocalError in ipython #1164

smartalecH opened this issue Mar 30, 2020 · 1 comment · Fixed by #1165
Assignees
Labels

Comments

@smartalecH
Copy link
Collaborator

smartalecH commented Mar 30, 2020

There's a bug when the user specifies a simulation run function (e.g. stop_when_fields_decayed) and iPython is in the current python environment. The issue is related to the Jupyter notebook progress bar update #1078.

Here's a simple test script:

import numpy as np
import meep as mp
from matplotlib import pyplot as plt

sx = 8
sy = 6
cell = mp.Vector3(sx, sy, 0)
geometry = [mp.Block(center=mp.Vector3(), size=mp.Vector3(mp.inf,0.5,0), material=mp.Medium(epsilon=12))]

fcen = 0.15
df = 0.1
sources = [mp.Source(mp.GaussianSource(fcen, fwidth=df), component=mp.Ez,
                        center=mp.Vector3(1 + (-0.5 * sx), 0), size=mp.Vector3(0, 2))]

pml_layers = [mp.PML(2.0)]
resolution = 10
nfreq = 100

sim = mp.Simulation(cell_size=cell,
                            boundary_layers=pml_layers,
                            geometry=geometry,
                            sources=sources,
                            resolution=resolution)
sim.run(until=mp.stop_when_fields_decayed(50, mp.Ez, mp.Vector3(), 1e-6))

Which throws the following error:

Traceback (most recent call last):
  File "test_converge.py", line 51, in <module>
    sim.run(until=mp.stop_when_fields_decayed(50, mp.Ez, mp.Vector3(), 1e-6))
  File "/$$meep_python_filepath$$/simulation.py", line 2249, in run
    self._run_until(until, step_funcs)
  File "/$$meep_python_filepath$$/simulation.py", line 1498, in _run_until
    self.progress.value = t0 + stop_time
UnboundLocalError: local variable 't0' referenced before assignment

As the error indicates, t0 is not properly defined:

meep/python/simulation.py

Lines 1497 to 1499 in 5e48aa2

if do_progress:
self.progress.value = t0 + stop_time
self.progress.description = "100% done "

Travis probably didn't catch this since iPython isn't part of the yaml file build instructions.

@smartalecH
Copy link
Collaborator Author

Note: stop_time is not properly initialized/defined either.

@stevengj stevengj added the bug label Mar 31, 2020
@stevengj stevengj changed the title Simulation run functions with iPython in environment UnboundLocalError in ipython Mar 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants