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

Restructure and Reorganize project #185

Merged
merged 58 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
482dd22
Begin restructuring project
glass-ships Sep 12, 2024
5aff410
fix some test imports
glass-ships Sep 12, 2024
eb5ddc5
checkpoint before merge
glass-ships Sep 12, 2024
031f5ec
merge main
glass-ships Sep 12, 2024
d1279cc
fix some imports to narrow test failures down
glass-ships Sep 12, 2024
44016b7
fix couple more imports
glass-ships Sep 12, 2024
8d236a6
update bumps, tests pass now. carrying on
glass-ships Sep 12, 2024
b1048e9
fix tests
glass-ships Sep 13, 2024
2a86674
fix docs build, update makefile, add sphinx to pyproject
glass-ships Sep 13, 2024
af0b6fa
fix makefile
glass-ships Sep 13, 2024
f91b191
Merge branch 'master' into restructure
glass-ships Sep 13, 2024
2f573f0
fix makefile again, sorry
glass-ships Sep 13, 2024
a3c6248
fix examples
glass-ships Sep 13, 2024
b19308b
fix examples for real i think
glass-ships Sep 13, 2024
0f7beec
Merge branch 'master' into restructure
glass-ships Sep 16, 2024
174b352
move backends to top level
glass-ships Sep 16, 2024
bdedb5e
fix imports in docs
glass-ships Sep 16, 2024
64a1c6b
fix imports in docs
glass-ships Sep 16, 2024
c88bcc9
fix pip install not including all dirs
glass-ships Sep 16, 2024
2d1ad5c
Merge branch 'master' into restructure
glass-ships Sep 20, 2024
da30308
working on documentation slowly but surely
glass-ships Sep 20, 2024
2fdefda
some updates
glass-ships Sep 23, 2024
8e44b4a
update osx installer section
glass-ships Sep 23, 2024
5333daf
Merge branch 'master' into restructure
glass-ships Sep 25, 2024
f1e37fd
merge master
glass-ships Oct 8, 2024
cbe9451
checkpoint restructure 2.0
glass-ships Oct 9, 2024
09e5215
cant install wx
glass-ships Oct 9, 2024
766a909
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 9, 2024
e444637
update docs, wx tests still failing
glass-ships Oct 9, 2024
7ad5853
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 9, 2024
f3c3e46
update doc tests with new layout
bmaranville Oct 9, 2024
ada6778
fix tests
glass-ships Oct 10, 2024
09d5aa1
fix examples
glass-ships Oct 10, 2024
34bb805
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 10, 2024
02ece4e
fix make docs
glass-ships Oct 10, 2024
c9be29d
merge master
glass-ships Oct 18, 2024
13735f1
Fix docs not building (workaround for now)
glass-ships Oct 18, 2024
42e54ad
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 18, 2024
e8f15ba
Put names back
glass-ships Oct 23, 2024
966937e
remove __all__ from models init
glass-ships Oct 23, 2024
c016735
Merge branch 'master' into restructure
glass-ships Oct 25, 2024
f4ac5c4
merge master
glass-ships Oct 30, 2024
dc24bd1
load4 in names.py should be function, not module
bmaranville Nov 5, 2024
16ecace
probe moved to subfolder, need to get probe.probe
bmaranville Nov 5, 2024
2124596
if refl1d api is not imported, functions don't get registered
bmaranville Nov 5, 2024
d775f34
Remove vue-json-viewer
glass-ships Nov 7, 2024
5dce7a5
merge master
glass-ships Nov 11, 2024
d11b4c2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 11, 2024
d1123ef
update references in comments, docs, and docstrings
glass-ships Nov 12, 2024
7cb850d
couple more references updated
glass-ships Nov 12, 2024
eea1067
remove reference to _MaterialStacker
glass-ships Nov 12, 2024
a16310e
merge main
glass-ships Nov 19, 2024
911fa0b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 19, 2024
d68a89b
resolve conflicts
glass-ships Nov 19, 2024
21a8cd9
minor changes
glass-ships Nov 19, 2024
9ce43e7
move subdirs to top level
glass-ships Nov 19, 2024
1bb568d
fix doc gen
glass-ships Nov 19, 2024
5ec0c54
manual merge master
glass-ships Nov 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,5 @@ venv.bak/
.idea
*.swp
*.bak

test-files/
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ repos:
args: [--allow-multiple-documents]
# - id: end-of-file-fixer
# - id: trailing-whitespace

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.2
hooks:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ format-backend: ## Run ruff formatting on python code
.PHONY: format-frontend
format-frontend: ## Run bun formatting on javascript code
cd refl1d/webview/client && \
$(FE_CMD) run format
$(FE_CMD) run format
8 changes: 5 additions & 3 deletions compareopt/slabs.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import sys
from random import getrandbits

import numpy as np
from bumps.parameter import summarize
from numpy.random import uniform

from refl1d.names import *
from refl1d.names import SLD, Experiment, FitProblem, NeutronProbe, air, silicon

num_layers = int(sys.argv[1])
init_file = sys.argv[2] if len(sys.argv) > 2 else "/tmp/problem"

out = open(init_file, "w")
seed = getrandbits(16)
print("seed", seed, file=out)
numpy.random.seed(int(seed))
np.random.seed(int(seed))


# CONSTRAINTS="unknown"
Expand Down Expand Up @@ -48,7 +50,7 @@ def genlayer(name):

sample = silicon(0, 5) | layers | air

T = numpy.linspace(0, 5, 100)
T = np.linspace(0, 5, 100)
probe = NeutronProbe(T=T, dT=0.01, L=4.75, dL=0.0475)

M = Experiment(probe=probe, sample=sample)
Expand Down
2 changes: 1 addition & 1 deletion conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
collect_ignore = [
"doc/guide/toffset.py",
# "refl1d/wx_gui/",
"refl1d/wx_gui/",
"tests/refl1d/Q_probe_oversample.py",
# "tests/refl1d/snsdata_test.py",
]
5 changes: 3 additions & 2 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@
print("== end path ==")

# Register the refl1d model loader
import refl1d.fitplugin
import bumps.cli

bumps.cli.install_plugin(refl1d.fitplugin)
from refl1d.bumps_interface import fitplugin

bumps.cli.install_plugin(fitplugin)

# -- General configuration -----------------------------------------------------

Expand Down
2 changes: 2 additions & 0 deletions doc/examples/distribution/dist-example.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os
import sys

import numpy

sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from refl1d.names import *
from refl1d.dist import Weights, DistributionExperiment
Expand Down
6 changes: 4 additions & 2 deletions doc/examples/eiv/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
an error-in-variables fit.
"""

import numpy as np

from refl1d.names import *

# ********** model setup **********
Expand All @@ -26,7 +28,7 @@
# n = 20
n = 400
dT, L, dL = 0.02, 4.75, 0.0475
T = numpy.linspace(0, 5, n)
T = np.linspace(0, 5, n)

# Set the motor uncertainty and the measurement uncertainty.
angle_uncertainty = 0.005
Expand Down Expand Up @@ -142,7 +144,7 @@ def residuals(self):
if self.probe.polarized:
have_data = not all(x is None or x.R is None for x in self.probe.xs)
else:
have_data = not (self.probe.R is None)
have_data = self.probe.R is not None
if not have_data:
resid = np.zeros(0)
self._cache["residuals"] = resid
Expand Down
5 changes: 3 additions & 2 deletions doc/examples/ex1/gendata.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

from numpy.random import seed
from bumps.fitproblem import load_problem
from refl1d.snsdata import write_file

from refl1d.names import SNS


def main():
seed(1)
problem = load_problem("nifilm-tof.py")
for i, p in enumerate(problem.fitness.probe.probes):
write_file("nifilm-tof-%d.dat" % (i + 1), p, title="Simulated 100 A Ni film")
SNS.write_file("nifilm-tof-%d.dat" % (i + 1), p, title="Simulated 100 A Ni film")


if __name__ == "__main__":
Expand Down
2 changes: 2 additions & 0 deletions doc/examples/ex1/nifilm-back.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#
# We set up the example as before.

import numpy

from refl1d.names import *

nickel = Material("Ni")
Expand Down
2 changes: 1 addition & 1 deletion doc/examples/ex1/nifilm-data.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# The data and sample are combined into an
# :class:`Experiment <refl1d.experiment.Experiment>`,
# which again is bundled as a
# :class:`FitProblem <refl1d.fitter.FitProblem>`
# :class:`FitProblem <refl1d.bumps_interface.fitproblem.FitProblem>`
# for the fitting program.

M = Experiment(probe=probe, sample=sample)
Expand Down
2 changes: 1 addition & 1 deletion doc/examples/ex1/nifilm-tof.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
# so much for a time-of-flight measurement, the central points will be
# measured with much better precision, and the end points will be measured
# with lower precision. See
# :meth:`Pulsed.simulate <refl1d.instrument.Pulsed.simulate>` for details
# :meth:`Pulsed.simulate <refl1d.probe.instrument.Pulsed.simulate>` for details
# on all simulation parameters.

# Finally, we bundle the simulated measurement as a fit problem which
Expand Down
8 changes: 7 additions & 1 deletion doc/examples/ex1/nifilm.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,15 @@
#
# The first step in any model is to load the names of the functions and
# data that we are going to use. These are defined in a module named
# refl1d.names, and we import them all as follows:
# refl1d.names, and we can import them as follows:

import numpy # This is the numpy library, which is used for numerical operations
from refl1d.names import Material, Experiment, NeutronProbe, FitProblem, silicon, air

# Alternatively, you can import them all, using:
from refl1d.names import *
# but this is not recommended for anything but simple scripts,
# and may cause linting issues in your IDE.

# This statement imports functions like SLD and Material for defining
# materials, Parameter, Slab and Stack for defining materials,
Expand Down
2 changes: 1 addition & 1 deletion doc/examples/four_column/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
# Here's the new loader. Much simplified since the reduction computes the
# appropriate $\Delta Q$ for the data points, and we don't need to specify
# the slit openings and distances for the data set. The options to the
# :func:`refl1d.probe.load4` function allow you to override things during
# :func:`refl1d.probe.data_loaders.load4.load4` function allow you to override things during
# load, such as the sample broadening of the resolution.

probe = load4("refl.txt")
Expand Down
2 changes: 1 addition & 1 deletion doc/examples/freemag/pmf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy
from refl1d.names import *
from copy import copy

# FIT USING REFL1D 0.6.12
# === Data files ===
Expand Down
1 change: 1 addition & 0 deletions doc/examples/ill_posed/anticor.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# Since silicon and air are defined, the only material we need to
# define is nickel.

import numpy
from refl1d.names import *

nickel = Material("Ni")
Expand Down
7 changes: 5 additions & 2 deletions doc/examples/ill_posed/tethered.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from refl1d.names import *
import periodictable
from copy import copy

import numpy
import periodictable

from refl1d.names import *

numpy.random.seed(1)

# Start with an SiOx layer of pure silicon so there is no contrast match.
Expand Down
2 changes: 2 additions & 0 deletions doc/examples/interface/model.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import numpy

from refl1d.names import *


Expand Down
2 changes: 2 additions & 0 deletions doc/examples/magrough/model.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import numpy

from refl1d.names import *

nickel = Material("Ni")
Expand Down
2 changes: 2 additions & 0 deletions doc/examples/mixed/mixed.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
# Since silicon and air are defined, the only material we need to
# define is nickel.

import numpy

from refl1d.names import *

nickel = Material("Ni")
Expand Down
2 changes: 2 additions & 0 deletions doc/examples/mixed/mixed_magnetic.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import numpy

from refl1d.names import *

nickel = Material("Ni")
Expand Down
4 changes: 2 additions & 2 deletions doc/examples/polymer/tethered.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@

# In this case we are using the neutron scattering length density as is
# standard practice in reflectivity experiments rather than the chemical
# formula and mass density. The :class:`SLD <refl1d.material.SLD>` class
# formula and mass density. The :class:`SLD <refl1d.sample.material.SLD>` class
# allows us to name the material and define the real and imaginary components
# of scattering length density $\rho$. Note that we are using the imaginary
# $\rho_i$ rather than the absorption coefficient $\mu = 2\lambda\rho_i$
# since it removes the dependence on wavelength from the calculation of
# the reflectivity.
#
# For the tethered polymer we don't use a simple slab model, but instead
# define a :class:`PolymerBrush <refl1d.polymer.PolymerBrush>`
# define a :class:`PolymerBrush <refl1d.sample.polymer.PolymerBrush>`
# layer, which understands that the system is compose of polymer plus
# solvent, and that the polymer chains tail off like:
#
Expand Down
6 changes: 3 additions & 3 deletions doc/examples/profile/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
from refl1d.names import *

# FunctionalProfile and FunctionalMagnetism are already available from
# refl1d.names, but a couple of aliases make them a little easier to access.
# refl1d.sample.flayer, but a couple of aliases make them a little easier to access.

from refl1d.flayer import FunctionalProfile as FP
from refl1d.flayer import FunctionalMagnetism as FM
from refl1d.names import FunctionalProfile as FP
from refl1d.names import FunctionalMagnetism as FM

# Define the nuclear profile function.
#
Expand Down
15 changes: 10 additions & 5 deletions doc/examples/random/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,22 @@
# Still, it is a good enough starting point, and does lead to some
# models with low contrast in neighbouring layers.

import numpy
import sys

from refl1d.names import *

# Process command line arguments to the model

n = int(sys.argv[1]) if len(sys.argv) > 1 else 2
noise = float(sys.argv[2]) if len(sys.argv) > 2 else 3.0
seed = int(sys.argv[3]) if len(sys.argv) > 3 else np.random.randint(1, 9999)
seed = int(sys.argv[3]) if len(sys.argv) > 3 else numpy.random.randint(1, 9999)

# Set the seed for the random number generator. Later we will print the
# seed, even if it was not set explicitly, so that interesting profiles
# can be regenerated.

np.random.seed(seed)
numpy.random.seed(seed)

# Set up a model with the desired number of layers. We will set the layer
# thickness and interfaces later.
Expand Down Expand Up @@ -78,17 +81,19 @@
# can work. Exponential distribution isn't suitable for single layer systems

for L in layers:
L.thickness.value = min(np.random.exponential(400.0 / np.sqrt(n)), 950) if n > 1 else np.random.uniform(5, 950)
L.thickness.value = (
min(numpy.random.exponential(400.0 / numpy.sqrt(n)), 950) if n > 1 else numpy.random.uniform(5, 950)
)

# Set interface limits based on neighbouring layer thickness, with substrate
# and surface having infinite thickness. Choose an interface of at least 1 A

interfaces = [
min(sample[i].thickness.value if i > 0 else np.inf, sample[i + 1].thickness.value if i < n else np.inf)
min(sample[i].thickness.value if i > 0 else numpy.inf, sample[i + 1].thickness.value if i < n else numpy.inf)
for i in range(n + 1)
]
for L, w in zip(sample[: n + 1], interfaces):
L.interface.value = 1 + np.random.exponential(w / 7)
L.interface.value = 1 + numpy.random.exponential(w / 7)
# Update the fit range if interface is excessively broad
if L.interface.value > 200:
L.interface.range(0, 2 * L.interface.value)
Expand Down
4 changes: 2 additions & 2 deletions doc/examples/spinvalve/n101G.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

# The materials are stacked as usual, but the layers with magnetism have
# an additional magnetism property specified. This example use
# :class:`refl1d.magnetism.Magnetism` to define a flat magnetic layer with
# :class:`refl1d.sample.magnetism.Magnetism` to define a flat magnetic layer with
# the given magnetic scattering length density *rhoM* and angle *thetaM*.
#
# The magnetism is anchored to the corresponding nuclear layer, and by
Expand All @@ -33,7 +33,7 @@
# indicates the interface above. Using *extent=2*, the single magnetism
# definition can extend over two consecutive layers.
#
# The :class:`refl1d.magnetism.MagnetismTwist` allows you to define a magnetic
# The :class:`refl1d.sample.magnetism.MagnetismTwist` allows you to define a magnetic
# layer whose values of theta and rho change linearly throughout the layer.
# There are additional magnetism types defined in :mod:`reflid.magnetism`.
# Note that the current definition of interface only transitions smoothly
Expand Down
1 change: 0 additions & 1 deletion doc/examples/staj/De2_VATR.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from refl1d.names import *
from refl1d.stajconvert import load_mlayer

# Load neutron model and data from staj file
# Layer names are ordered from substrate to surface, and defaults to
Expand Down
5 changes: 4 additions & 1 deletion doc/examples/step/tethered.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from refl1d.names import *
from copy import copy

import numpy

from refl1d.names import *

# === Materials ===
SiOx = SLD(name="SiOx", rho=3.47)
D_polystyrene = SLD(name="D-PS", rho=6.2)
Expand Down
2 changes: 2 additions & 0 deletions doc/examples/superlattice/NiTi.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

# First define the materials we will use

import numpy

from refl1d.names import *

nickel = Material("Ni")
Expand Down
2 changes: 2 additions & 0 deletions doc/examples/superlattice/PEMU.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
# Bring in all of the functions from refl1d.names so that we can use them
# in the remainder of the script.

import numpy

from refl1d.names import *

# The polymer system is deposited on a gold film with chromium as an
Expand Down
2 changes: 2 additions & 0 deletions doc/examples/superlattice/freeform.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

# The materials are straight forward:

import numpy

from refl1d.names import *

chrome = Material("Cr")
Expand Down
2 changes: 1 addition & 1 deletion doc/examples/superlattice/readme.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Superlattice Models

.. contents:: :local:

Any structure can be turned into a superlattice using a :class:`refl1d.model.Repeat`.
Any structure can be turned into a superlattice using a :class:`refl1d.sample.layer.Repeat`.

Simply form a stack as usual, then use that stack within another stack, with a
repeat modifier.
Expand Down
3 changes: 2 additions & 1 deletion doc/examples/thick/nifilm.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import numpy

from refl1d.names import *

nickel = Material("Ni")

# nickel = SLD(rho=9.4)

sample = silicon(0, 5) | nickel(10000, 5) | air
Expand Down
Loading
Loading