NanoComp / meep

free finite-difference time-domain (FDTD) software for electromagnetic simulations
GNU General Public License v2.0
1.21k stars 618 forks source link

Kernel Error? #1136

Closed BaileyM25 closed 4 years ago

BaileyM25 commented 4 years ago

So I am trying to run the example of a Cylindrical Ring Resonator but when I try to run it using the main, I get a kernel error.

CODE:

# Calculating 2d ring-resonator modes using cylindrical coordinates,
# from the Meep tutorial.
from __future__ import division

import meep as mp
import argparse

def main(args):

    n = 3.4     # index of waveguide
    w = 1       # width of waveguide
    r = 1       # inner radius of ring
    pad = 4     # padding between waveguide and edge of PML
    dpml = 32    # thickness of PML

    sr = r + w + pad + dpml  # radial size (cell is from 0 to sr)
    dimensions = mp.CYLINDRICAL
    cell = mp.Vector3(sr, 0, 0)

    # in cylindrical coordinates, the phi (angular) dependence of the fields
    # is given by exp(i m phi), where m is given by:
    m = args.m

    geometry = [mp.Block(center=mp.Vector3(r + (w / 2)),
                         size=mp.Vector3(w, mp.inf, mp.inf),
                         material=mp.Medium(index=n))]

    pml_layers = [mp.PML(dpml)]
    resolution = 20

    # If we don't want to excite a specific mode symmetry, we can just
    # put a single point source at some arbitrary place, pointing in some
    # arbitrary direction.  We will only look for Ez-polarized modes.

    fcen = args.fcen  # pulse center frequency
    df = args.df      # pulse frequency width
    sources = [mp.Source(src=mp.GaussianSource(fcen, fwidth=df),
                         component=mp.Ez,
                         center=mp.Vector3(r + 0.1))]

    # note that the r -> -r mirror symmetry is exploited automatically

    sim = mp.Simulation(cell_size=cell,
                        geometry=geometry,
                        boundary_layers=pml_layers,
                        resolution=resolution,
                        sources=sources,
                        dimensions=dimensions,
                        m=m)

    sim.run(mp.after_sources(mp.Harminv(mp.Ez, mp.Vector3(r + 0.1), fcen, df)),
            until_after_sources=200)

    # Output fields for one period at the end.  (If we output
    # at a single time, we might accidentally catch the Ez field when it is
    # almost zero and get a distorted view.)  We'll append the fields
    # to a file to get an r-by-t picture.  We'll also output from -sr to -sr
    # instead of from 0 to sr.
    sim.run(mp.in_volume(mp.Volume(center=mp.Vector3(), size=mp.Vector3(2 * sr)),
                         mp.at_beginning(mp.output_epsilon),
                         mp.to_appended("ez", mp.at_every(1 / fcen / 20, mp.output_efield_z))),
            until=1 / fcen)

THE MAIN IS APART OF THE CODE BUT FOR SOME REASON NOT LETTING ME KEEP IT IN THE CODE PORTION:

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('-fcen', type=float, default=0.15, help='pulse center frequency')
    parser.add_argument('-df', type=float, default=0.1, help='pulse frequency width')
    parser.add_argument('-m', type=int, default=3, help='phi (angular) dependence of the fields given by exp(i m phi)')
    args = parser.parse_args()
    main(args)

RESULTS:

usage: ipykernel_launcher.py [-h] [-fcen FCEN] [-df DF] [-m M]
ipykernel_launcher.py: error: argument -fcen: invalid float value: '/home/bailey/.local/share/jupyter/runtime/kernel-23f09698-88aa-4430-8940-03b037b2a30f.json'
ERROR:root:Internal Python error in the inspect module.
Below is the traceback from this internal error.

Traceback (most recent call last):
  File "/home/bailey/anaconda3/envs/mp/lib/python3.6/argparse.py", line 2294, in _get_value
    result = type_func(arg_string)
ValueError: could not convert string to float: '/home/bailey/.local/share/jupyter/runtime/kernel-23f09698-88aa-4430-8940-03b037b2a30f.json'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/bailey/anaconda3/envs/mp/lib/python3.6/argparse.py", line 1766, in parse_known_args
    namespace, args = self._parse_known_args(args, namespace)
  File "/home/bailey/anaconda3/envs/mp/lib/python3.6/argparse.py", line 1972, in _parse_known_args
    start_index = consume_optional(start_index)
  File "/home/bailey/anaconda3/envs/mp/lib/python3.6/argparse.py", line 1912, in consume_optional
    take_action(action, args, option_string)
  File "/home/bailey/anaconda3/envs/mp/lib/python3.6/argparse.py", line 1824, in take_action
    argument_values = self._get_values(action, argument_strings)
  File "/home/bailey/anaconda3/envs/mp/lib/python3.6/argparse.py", line 2265, in _get_values
    value = self._get_value(action, arg_string)
  File "/home/bailey/anaconda3/envs/mp/lib/python3.6/argparse.py", line 2307, in _get_value
    raise ArgumentError(action, msg % args)
argparse.ArgumentError: argument -fcen: invalid float value: '/home/bailey/.local/share/jupyter/runtime/kernel-23f09698-88aa-4430-8940-03b037b2a30f.json'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/bailey/anaconda3/envs/mp/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 3331, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-1-463be6cccb74>", line 69, in <module>
    args = parser.parse_args()
  File "/home/bailey/anaconda3/envs/mp/lib/python3.6/argparse.py", line 1734, in parse_args
    args, argv = self.parse_known_args(args, namespace)
  File "/home/bailey/anaconda3/envs/mp/lib/python3.6/argparse.py", line 1773, in parse_known_args
    self.error(str(err))
  File "/home/bailey/anaconda3/envs/mp/lib/python3.6/argparse.py", line 2393, in error
    self.exit(2, _('%(prog)s: error: %(message)s\n') % args)
  File "/home/bailey/anaconda3/envs/mp/lib/python3.6/argparse.py", line 2380, in exit
    _sys.exit(status)
SystemExit: 2
stevengj commented 4 years ago

(PS. Please learn how to quote code blocks on github — I had to edit your post to make it readable. See https://help.github.com/en/github/writing-on-github/creating-and-highlighting-code-blocks)

stevengj commented 4 years ago

It sounds like you're having trouble using the argparser Python module in IPython, nothing to do with Meep?

BaileyM25 commented 4 years ago

https://medium.com/@milved/meep-is-a-free-and-open-source-software-package-for-electromagnetics-simulation-via-the-2ced3a86091c

This is all I have done and went straight to doing examples in meep documentation. The error with argparser I have know idea what the error could be.