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

Division by 0 error in FastFitter #1631

Closed
weiliangjin2021 opened this issue Apr 23, 2024 · 0 comments · Fixed by #1672
Closed

Division by 0 error in FastFitter #1631

weiliangjin2021 opened this issue Apr 23, 2024 · 0 comments · Fixed by #1672
Assignees
Labels
Bug something isnt working

Comments

@weiliangjin2021
Copy link
Collaborator

The code to reproduce the error:

import numpy as np
from tidy3d.plugins.dispersion import FastDispersionFitter

N = 2
wvl_um = np.linspace(0.5, 0.6, N)
n_data = np.ones(N) * 2
k_data = np.ones(N) * 0.5

fitter = FastDispersionFitter(wvl_um = wvl_um, n_data = n_data, k_data = k_data)
medium, rms_error = fitter.fit(max_num_poles=2, tolerance_rms=1e-3)

Error message:

tidy3d_frontend/tidy3d/plugins/dispersion/fit_fast.py:360: RuntimeWarning: divide by zero encountered in divide
pole_matrix[:, offset + 2 * i] = 1 / (1j * omega + pole) + 1 / (
File "tidy3d_frontend/tidy3d/plugins/dispersion/fit_fast.py", line 498, in fit_residues
x_vector = scipy.optimize.lsq_linear(a_matrix_real, b_vector_real).x
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "python3.11/site-packages/scipy/optimize/_lsq/lsq_linear.py", line 316, in lsq_linear
unbd_lsq = np.linalg.lstsq(A, b, rcond=-1)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "python3.11/site-packages/numpy/linalg/linalg.py", line 2326, in lstsq
x, resids, rank, s = gufunc(a, b, rcond, signature=signature, extobj=extobj)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "python3.11/site-packages/numpy/linalg/linalg.py", line 124, in _raise_linalgerror_lstsq
raise LinAlgError("SVD did not converge in Linear Least Squares")
numpy.linalg.LinAlgError: SVD did not converge in Linear Least Squares

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug something isnt working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants