Error when optimizing over goos.Cuboid variable.
ichristen opened this issue · 2 comments
Hi,
First of all, thanks to all of you for making this codebase open-source. It really is awesome to not have to go about reinventing this particular wheel.
I am interested in optimizing grating efficiency over the z
-position of a reflective buried layer (in addition to a standard barcode grating optimization). I attempted to do this by inserting a 3-vector goos.Variable
into the goos.Cuboid
that is the reflective buried layer. However, when running the simulation, I receive errors similar to ValueError: 0-th dimension must be fixed to 489 but got 487
. After some digging, I determined that a 3-vector from my variable is appended to the initial_val
list (as expected), whereas the grad(x)
list is given a 1-vector from my variable (see spins/goos/optimize.py:run()
). Hence the error, as scipy.optimize.minimize
gets confused when trying to apply a N+1
-long Jacobian to a N+3
-long vector. At this point, I wasn't sure if goos.Cuboid
s hadn't been fully-implemented in goos
or if I was using something incorrectly, so I would appreciate any insight. It is possible that I'm initializing the goos.Variable
incorrectly or something.
One can test out this issue easily by editing a line or two in the substrate
variable from the examples/goos/grating_1d
example (in this example, the z
-position of the substrate isn't super critical for grating optimization, but it illustrates the issue). The different variants that I tried included:
- Original code (works):
substrate = goos.Cuboid(
pos=goos.Constant([
params.coupler_len / 2, 0,
-params.box_size - params.wg_thickness / 2 - 5000
]),
extents=goos.Constant([params.coupler_len + 10000, 1000, 10000]),
material=goos.material.Material(index=params.eps_wg))
- Turning
extents
into a 3-vectorgoos.Variable
(fails):
substrate = goos.Cuboid(
pos=goos.Constant([
params.coupler_len / 2, 0,
-params.box_size - params.wg_thickness / 2 - 5000
]),
extents=goos.Variable([params.coupler_len + 10000, 1000, 10000]),
material=goos.material.Material(index=params.eps_wg))
- Adding a 3-vector
goos.Variable
toextents
(fails):
substrate = goos.Cuboid(
pos=goos.Constant([
params.coupler_len / 2, 0,
-params.box_size - params.wg_thickness / 2 - 5000
]),
extents=goos.Constant([params.coupler_len + 10000, 1000, 10000]) + goos.Variable([0, 0, 0]),
material=goos.material.Material(index=params.eps_wg))
- Multiplying
extents
by a 1-vectorgoos.Variable
(fails):
substrate = goos.Cuboid(
pos=goos.Constant([
params.coupler_len / 2, 0,
-params.box_size - params.wg_thickness / 2 - 5000
]),
extents=goos.Variable(1) * goos.Constant([params.coupler_len + 10000, 1000, 10000]),
material=goos.material.Material(index=params.eps_wg))
- Variations of the above with upper and lower bounds included on the
goos.Variable
(fails). - Variations of the above that try to change
pos
rather thanextents
[although the code ofgoos.CuboidFlow
seems to imply that one should makeextents
thatgoos.Variable
, notpos
?] (fails).
Thanks much for any help!
Hi! Is this still an issue?
Closing for now.