Skip to content

Add analytical dipole test - #24

Open
hejamu wants to merge 7 commits into
mainfrom
ou-dipole-test
Open

hejamu wants to merge 7 commits into
mainfrom
ou-dipole-test

Conversation

@hejamu

@hejamu hejamu commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Fixes #11

Changes made in this Pull Request:

  • Added a test that produces a dipole timeseries from a Ornstein-Uhlenbeck process, which has an analytically known spectrum.
  • Fixed factor of 2 (Maybe, should check the derivation of the test)
  • Added example showing the analytical example.

PR Checklist

  • Issue raised/referenced?

📚 Documentation preview 📚: https://spectrumkit--24.org.readthedocs.build/en/24/

@PicoCentauri PicoCentauri left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is an amazing and very good test! Thanks @hejamu and @Quewakira !

Comment thread examples/validation/debye_relaxation.py Outdated
Comment on lines +6 to +7
The test suite checks the spectrum routes against a dipole whose susceptibility is known
exactly. This example walks through that test, ``TestDebyeRelaxation`` in

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wouldn't mention the testsuite. As a user I don't care what you do in the tests and I also don't look at them.

Comment thread examples/validation/debye_relaxation.py Outdated
# \qquad \langle \xi_\alpha(t) \xi_\beta(t') \rangle
# = \delta_{\alpha \beta} \, \delta(t - t').
#
# The equation is linear and the noise is uncorrelated with the past, so multiplying by

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
# The equation is linear and the noise is uncorrelated with the past, so multiplying by
# The equation is linear and the noise is uncorrelated with the past (no memory), so multiplying by

Comment thread examples/validation/debye_relaxation.py Outdated
# \chi''(\omega) = \chi_0 \, \frac{\omega \tau}{1 + \omega^2 \tau^2}, \qquad
# \chi_0 = \frac{\langle \boldsymbol{M}^2 \rangle}{3 V \varepsilon_0 k_B T},
#
# with the loss peak at :math:`\omega \tau = 1`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe add a connecting sentence for the next paragraph. Something like we will use this simple system to validate.

Comment on lines +90 to +92
acf = np.array(
[np.mean(np.sum(dipole[: n_frames - k] * dipole[k:], axis=1)) for k in lags]
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I thought we want an acf function for this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Out of scope for this PR :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

fine for me. Maybe branch the comment our in an issue.

Comment thread examples/validation/debye_relaxation.py Outdated
# :func:`~spectrumkit.dielectricspectrum.calculate_spectrum_from_dipole` works on the
# dipole, :func:`~spectrumkit.dielectricspectrum.calculate_spectrum_from_current` on the
# current :math:`\boldsymbol{J} = \dot{\boldsymbol{M}}`, here a finite difference. Both
# average the periodogram over 100 segments of 20 ps.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What is a periodogram 😆

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Basically what we do to get nicer spectra by averaging. The german Wikipedia article is quite nice https://de.wikipedia.org/wiki/Periodogramm.

We can change the wording. I think it is something only people in signal processing are familiar with.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Oh, actually what we do would be called Bartletts method, "method of averaged periodograms" https://en.wikipedia.org/wiki/Bartlett%27s_method. Lets just call it averaged power spectrum.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes I think for us stupid people averaged power spectrum is nice. we can link the exact method or name maybe both.

Comment thread examples/validation/debye_relaxation.py Outdated
# current :math:`\boldsymbol{J} = \dot{\boldsymbol{M}}`, here a finite difference. Both
# average the periodogram over 100 segments of 20 ps.

dipole_route = calculate_spectrum_from_dipole(dipole, dt, volume, temperature, segs=100)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should we import the functions in the example not in the local namespace but keep them in the spectrumkit to be better visible that these are our functions?

Suggested change
dipole_route = calculate_spectrum_from_dipole(dipole, dt, volume, temperature, segs=100)
dipole_route = spectrumkit.calculate_spectrum_from_dipole(dipole, dt, volume, temperature, segs=100)

Comment thread examples/validation/debye_relaxation.py Outdated


def debye(nu):
"""Debye susceptibility at the frequency ``nu`` in THz."""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Strictly speaking this function doesn't care about the units it is only Thz since our time units are ps

@hejamu
hejamu requested a review from PicoCentauri November 25, 2026 14:22

@PicoCentauri PicoCentauri left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice. I have two minor things you might ignore. Again very cool eample.


import spectrumkit

BLUE, ORANGE, INK, SHADE = "#2a78d6", "#eb6834", "#0b0b0b", "#e1e0d9"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I thought this is not aligned with pep8?

Suggested change
BLUE, ORANGE, INK, SHADE = "#2a78d6", "#eb6834", "#0b0b0b", "#e1e0d9"
BLUE = "#2a78d6"
ORANGE = "#eb6834"
INK = "#0b0b0b"
SHADE = "#e1e0d9"

also what is the reason against just using tab10 defaults?

Comment thread tests/data/synthetic.py
sigma: float = 1.0,
seed: int = 0,
) -> np.ndarray:
r"""Ornstein-Uhlenbeck process, e.g. a dipole with Debye relaxation.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not sure if we need such an extensive docstring in a test function. We might just refer to the example for the discussion of the motivation.

This branch has not been deployed

No deployments
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.

Replace regression tests by physical tests

2 participants