Skip to content

Fix: align NumPy/PyTorch backends with C++ backend for dI/dV - #69

Open
GianmarcoMidena wants to merge 9 commits into
masterfrom
66-numpy-and-pytorch-backends-diverge-from-official-c-backend-for-didv-on-4n-coronene-examples
Open

Fix: align NumPy/PyTorch backends with C++ backend for dI/dV#69
GianmarcoMidena wants to merge 9 commits into
masterfrom
66-numpy-and-pytorch-backends-diverge-from-official-c-backend-for-didv-on-4n-coronene-examples

Conversation

@GianmarcoMidena

Copy link
Copy Markdown
Contributor

Closes #66

Add py, px, dyz, dxz orbital types to verify consistency between C++ and other backends in dI/dV calculations.
Body:
- checks C++ vs alternative dI/dV backends
- covers single-orbital tip/sample pairs for the intended sp/spd combinations
Correct bugs in NumPy and PyTorch backends that caused incorrect results when computing dI/dV for px/py tip orbitals with d-orbital samples.
@GianmarcoMidena GianmarcoMidena linked an issue Aug 7, 2026 that may be closed by this pull request
10 tasks
WF (float): Work function
eta (float): Broadening parameter (energy smearing)
eig (np.ndarray): Eigenvalues array, shape (n_o,)
eig (np.ndarray): Eigenvalues array, shape (n_e,)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a comment - n_o -> n_e means from number of orbitals to number of electrons?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

number of eigenvalues or eigenstates

_N_D = math.sqrt(15)
_N_D2 = math.sqrt(5) * 0.5
_I_3 = 0.3333333
_I_3 = 1/3

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you have found a way, how to make it precise and in agreement with previous calculations, which are not as precise on this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the exact fraction 1/3 lets the numerical backend (NumPy/PyTorch) use its own precision management.

wf = np.float32(WF)
eta = np.float32(eta)
self._tip_coes = self._to_float(tip_coes) # shape (9,)
eig = self._to_float(eig) # shape (n_e,)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is here this "_to_float"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"_to_float" moves tensors to single-precision floating-point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NumPy and PyTorch backends diverge from official C++ backend for dI/dV

2 participants