mirror of
https://github.com/edoverg/modeconverter.git
synced 2026-10-14 23:06:39 +00:00
added timestamps for evaluation
This commit is contained in:
@@ -2,11 +2,10 @@
|
|||||||
#from jax.numpy.fft import fft2, ifft2, fftshift, ifftshift
|
#from jax.numpy.fft import fft2, ifft2, fftshift, ifftshift
|
||||||
from typing import List, Tuple, Union
|
from typing import List, Tuple, Union
|
||||||
from autograd import numpy as npa, tensor_jacobian_product, grad as gd
|
from autograd import numpy as npa, tensor_jacobian_product, grad as gd
|
||||||
import meep.adjoint as mpa
|
import time
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
import xarray as xr
|
|
||||||
from PIL import Image
|
|
||||||
import nlopt
|
import nlopt
|
||||||
from scipy.special import jv, kv
|
from scipy.special import jv, kv
|
||||||
ArrayLikeType = Union[List, Tuple, np.ndarray]
|
ArrayLikeType = Union[List, Tuple, np.ndarray]
|
||||||
@@ -24,6 +23,7 @@ ds = 1 / res_x
|
|||||||
|
|
||||||
Nx = int(round(res_x * size_x)) + 1
|
Nx = int(round(res_x * size_x)) + 1
|
||||||
Ny = int(round(res_y * size_y)) + 1
|
Ny = int(round(res_y * size_y)) + 1
|
||||||
|
print("Nx: ", Nx)
|
||||||
S = Nx * Ny
|
S = Nx * Ny
|
||||||
|
|
||||||
norm_phase_min = 0
|
norm_phase_min = 0
|
||||||
@@ -149,6 +149,7 @@ def forward_propagate(phase_mask:np.ndarray) -> Tuple[List[np.ndarray], List[np.
|
|||||||
The output field after propagation (flattened) and the propagation matrices P used in the forward propagation.
|
The output field after propagation (flattened) and the propagation matrices P used in the forward propagation.
|
||||||
'''
|
'''
|
||||||
print("Starting propagating...")
|
print("Starting propagating...")
|
||||||
|
start_time = time.time()
|
||||||
phase_mask_1 = phase_mask[:S]
|
phase_mask_1 = phase_mask[:S]
|
||||||
phase_mask_2 = phase_mask[S:]
|
phase_mask_2 = phase_mask[S:]
|
||||||
d1 = d[0]
|
d1 = d[0]
|
||||||
@@ -180,7 +181,8 @@ def forward_propagate(phase_mask:np.ndarray) -> Tuple[List[np.ndarray], List[np.
|
|||||||
output_field_2_2d = np.fft.ifft2(np.fft.ifftshift(fft_field_propagated_2))
|
output_field_2_2d = np.fft.ifft2(np.fft.ifftshift(fft_field_propagated_2))
|
||||||
output_field_2 = output_field_2_2d.flatten()
|
output_field_2 = output_field_2_2d.flatten()
|
||||||
|
|
||||||
print("Propagation finished.")
|
end_time = time.time()
|
||||||
|
print("Propagation finished in {:.6f} seconds.".format(end_time - start_time))
|
||||||
|
|
||||||
output_fields = [output_field_1, output_field_2]
|
output_fields = [output_field_1, output_field_2]
|
||||||
propagation_matrices = [P_1, P_2]
|
propagation_matrices = [P_1, P_2]
|
||||||
@@ -196,6 +198,8 @@ def adjoint_propagate(output_fields,propagation_matrices,phase_mask):
|
|||||||
Returns:
|
Returns:
|
||||||
The backpropagated field (flattened)
|
The backpropagated field (flattened)
|
||||||
'''
|
'''
|
||||||
|
print("Computing adjoint...")
|
||||||
|
start_time = time.time()
|
||||||
phase_mask_1 = phase_mask[:S]
|
phase_mask_1 = phase_mask[:S]
|
||||||
phase_mask_2 = phase_mask[S:]
|
phase_mask_2 = phase_mask[S:]
|
||||||
|
|
||||||
@@ -233,6 +237,8 @@ def adjoint_propagate(output_fields,propagation_matrices,phase_mask):
|
|||||||
|
|
||||||
grads = np.concatenate((grad_C_phi_1, grad_C_phi_2))
|
grads = np.concatenate((grad_C_phi_1, grad_C_phi_2))
|
||||||
|
|
||||||
|
end_time = time.time()
|
||||||
|
print("Adjoint finished in {:.6f} seconds.".format(end_time - start_time))
|
||||||
return grads
|
return grads
|
||||||
|
|
||||||
def _compute_cost(phase_mask):
|
def _compute_cost(phase_mask):
|
||||||
|
|||||||
Reference in New Issue
Block a user