-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated Optimizer Class in JAX and Torch.
- Loading branch information
Showing
13 changed files
with
110 additions
and
440 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import optax | ||
|
||
import meent | ||
from meent.on_jax.optimizer.loss import LossDeflector | ||
from meent.on_jax.optimizer.optimizer import OptimizerJax | ||
|
||
|
||
mode = 1 | ||
dtype = 0 | ||
device = 0 | ||
grating_type = 2 | ||
|
||
conditions = meent.testcase.load_setting(mode, dtype, device, grating_type) | ||
mee = OptimizerJax(**conditions) | ||
|
||
pois = ['ucell', 'thickness'] | ||
|
||
forward = mee.conv_solve | ||
loss_fn = LossDeflector(x_order=0, y_order=0) | ||
|
||
# case 1: Gradient | ||
grad = mee.grad(pois, forward, loss_fn) | ||
print(1, grad) | ||
|
||
# case 2: SGD | ||
optimizer = optax.sgd(learning_rate=1e-2) | ||
mee.fit(pois, forward, loss_fn, optimizer) | ||
print(3, mee.thickness*1E5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import torch | ||
|
||
import meent | ||
from meent.on_torch.optimizer.loss import LossDeflector | ||
from meent.on_torch.optimizer.optimizer import OptimizerTorch | ||
|
||
|
||
mode = 2 | ||
dtype = 0 | ||
device = 0 | ||
grating_type = 2 | ||
|
||
conditions = meent.testcase.load_setting(mode, dtype, device, grating_type) | ||
mee = OptimizerTorch(**conditions) | ||
|
||
pois = ['ucell', 'thickness'] | ||
|
||
forward = mee.conv_solve | ||
loss_fn = LossDeflector(x_order=0, y_order=0) | ||
|
||
# case 1: Gradient | ||
grad = mee.grad(pois, forward, loss_fn) | ||
print(1, grad) | ||
|
||
# case 2: SGD | ||
opt_torch = torch.optim.SGD | ||
opt_options = {'lr': 1E-2, | ||
'momentum': 0.9, | ||
} | ||
|
||
mee.fit(pois, forward, loss_fn, opt_torch, opt_options) |
Oops, something went wrong.