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

Open
wants to merge 51 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 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
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
1 change: 0 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,4 @@ jobs:
- name: Check that the docs build (linux only)
if: matrix.config.doc == 1
run: |
pip install sphinx
make -j 4 -C doc SPHINXOPTS="-W --keep-going" html
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,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 @@ -9,7 +9,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.6.9
hooks:
Expand Down
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,18 @@ lint: ## Run ruff linting
.PHONY: format
format: ## Run ruff formatting
@ruff format refl1d/ tests/ setup.py

.PHONY: clean
clean: ## Delete some cruft from builds/testing/etc.
rm -f `find . -type f -name '*.py[co]'`
rm -rf `find . -name __pycache__ -o -name "*.egg-info"` \
`find . -name 'output-*'` \
.coverage build dist \
doc/_build doc/api doc/tutorial \
.pytest_cache \
.ruff_cache
glass-ships marked this conversation as resolved.
Show resolved Hide resolved

.PHONY: test
test: ## Run pytest and doc tests
pytest -v
python check_examples.py --chisq
14 changes: 8 additions & 6 deletions compareopt/slabs.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
from __future__ import print_function

import sys
from random import getrandbits
from numpy.random import uniform
from refl1d.names import *

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

from refl1d.models 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
1 change: 1 addition & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
collect_ignore = [
"doc/guide/toffset.py",
"refl1d/wx_gui/",
"tests/refl1d/Q_probe_oversample.py",
# "tests/refl1d/snsdata_test.py",
]
8 changes: 5 additions & 3 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import sys, os
import os
import sys

print("python %s" % sys.executable)

Expand All @@ -36,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.models.bumps_interface import fitplugin

bumps.cli.install_plugin(fitplugin)

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

Expand Down
2 changes: 1 addition & 1 deletion doc/examples/TOF/du53.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from refl1d.names import *
from refl1d.models import *

instrument = SNS.Liquids(Tlo=0.3, slits_at_Tlo=0.2, TOF_range=(12000, 40000))
probes = [
Expand Down
9 changes: 6 additions & 3 deletions doc/examples/distribution/dist-example.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import sys, os
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
from refl1d.models import *
from refl1d.models.dist import Weights, DistributionExperiment

# Materials
nickel = Material("Ni", fitby="relative_density")
Expand Down
8 changes: 5 additions & 3 deletions doc/examples/eiv/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
an error-in-variables fit.
"""

from refl1d.names import *
import numpy as np

from refl1d.models 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.models 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
4 changes: 3 additions & 1 deletion doc/examples/ex1/nifilm-back.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
#
# We set up the example as before.

from refl1d.names import *
import numpy

from refl1d.models import *

nickel = Material("Ni")
sample = silicon(0, 25) | nickel(100, 5) | air
Expand Down
8 changes: 4 additions & 4 deletions doc/examples/ex1/nifilm-data.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@

# The sample and instrument definition is the same as before:

from refl1d.names import *
from refl1d.models import *

nickel = Material("Ni")
sample = silicon(0, 5) | nickel(100, 5) | air

instrument = SNS.Liquids()

# In this case we are loading multiple data sets into the same
# :class:`ProbeSet <refl1d.probe.ProbeSet>` object. If your
# :class:`ProbeSet <refl1d.models.probe.probe.ProbeSet>` object. If your
# reduction program stitches together the data for you, then you can simply
# use ``probe=instrument.load('file')``.

files = ["nifilm-tof-%d.dat" % d for d in (1, 2, 3, 4)]
probe = ProbeSet(instrument.load(f) for f in files)

# The data and sample are combined into an
# :class:`Experiment <refl1d.experiment.Experiment>`,
# :class:`Experiment <refl1d.models.experiment.Experiment>`,
# which again is bundled as a
# :class:`FitProblem <refl1d.fitter.FitProblem>`
# :class:`FitProblem <refl1d.models.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-fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# We use the usual sample definition, except we set the thickness of the
# nickel layer to 125 |Ang| so that the model does not match the data:

from refl1d.names import *
from refl1d.models import *

# Turn off resolution bars in plots. Only do this after you have plotted the
# data with resolution bars so you know it looks reasonable, and you are not
Expand Down
2 changes: 1 addition & 1 deletion doc/examples/ex1/nifilm-mixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# it does demonstrate a way to form a mixture of two materials by volume
# :download:`nifilm-mixture.py <nifilm-mixture.py>`:

from refl1d.names import *
from refl1d.models import *

# Here is the mixture formula. We are giving the mass density along with the
# chemical formula for each part, followed by the percentage for that part.
Expand Down
4 changes: 2 additions & 2 deletions doc/examples/ex1/nifilm-tof.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#
# The sample definition is the same:

from refl1d.names import *
from refl1d.models import *

nickel = Material("Ni")
sample = silicon(0, 5) | nickel(100, 5) | air
Expand All @@ -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.models.probe.instrument.Pulsed.simulate>` for details
# on all simulation parameters.

# Finally, we bundle the simulated measurement as a fit problem which
Expand Down
10 changes: 8 additions & 2 deletions 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.models, and we can import them as follows:

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

# Alternatively, you can import them all, using:
from refl1d.models 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
4 changes: 2 additions & 2 deletions doc/examples/four_column/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

# The following is copied directly from the spin value example

from refl1d.names import *
from refl1d.models import *

Si = SLD(name="Si", rho=2.0737, irho=2.376e-5)
Cu = SLD(name="Cu", rho=6.5535, irho=8.925e-4)
Expand Down 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.models.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
4 changes: 2 additions & 2 deletions doc/examples/freemag/pmf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from refl1d.names import *
from copy import copy
import numpy
from refl1d.models import *

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

from refl1d.names import *
import numpy
from refl1d.models 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.models import *

numpy.random.seed(1)

# Start with an SiOx layer of pure silicon so there is no contrast match.
Expand Down
4 changes: 3 additions & 1 deletion doc/examples/interface/model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from refl1d.names import *
import numpy

from refl1d.models import *


sharp = FreeInterface(below=silicon, above=gold, dz=[0.01, 1, 0.01], dp=[0.01, 1, 0.01])
Expand Down
4 changes: 3 additions & 1 deletion doc/examples/magrough/model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from refl1d.names import *
import numpy

from refl1d.models import *

nickel = Material("Ni")
copper = Material("Cu")
Expand Down
4 changes: 3 additions & 1 deletion doc/examples/mixed/mixed.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
# Since silicon and air are defined, the only material we need to
# define is nickel.

from refl1d.names import *
import numpy

from refl1d.models import *

nickel = Material("Ni")

Expand Down
4 changes: 3 additions & 1 deletion doc/examples/mixed/mixed_magnetic.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from refl1d.names import *
import numpy

from refl1d.models import *

nickel = Material("Ni")

Expand Down
2 changes: 1 addition & 1 deletion doc/examples/polymer/freeform.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# freeform interface which varies the density between layers using a
# cubic spline interface.

from refl1d.names import *
from refl1d.models import *
from copy import copy

# Materials used
Expand Down
6 changes: 3 additions & 3 deletions doc/examples/polymer/tethered.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# We first need to define the materials

from refl1d.names import *
from refl1d.models import *
from copy import copy

# === Materials ===
Expand All @@ -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.models.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.models.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
Loading
Loading