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

New parameter and numpy2 #209

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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: 1 addition & 1 deletion .github/workflows/documentation-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: 3.11
- name: Install Pandoc, repo and dependencies
run: |
sudo apt install pandoc
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/python-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
strategy:
max-parallel: 4
matrix:
python-version: ['3.9', '3.10', '3.11', '3.12']
python-version: ['3.10', '3.11', '3.12']
os: [ubuntu-latest, macos-latest, windows-latest]

runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -74,7 +74,7 @@ jobs:

- uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: 3.11

- name: Install dependencies and build
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.9', '3.10', '3.11']
python-version: ['3.10', '3.11','3.12']
if: "!contains(github.event.head_commit.message, '[ci skip]')"

steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:

- uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: 3.10

- name: Install dependencies and build
run: |
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Before you submit a pull request, check that it meets these guidelines:
2. If the pull request adds functionality, the docs should be updated. Put
your new functionality into a function with a docstring, and add the
feature to the list in README.md.
3. The pull request should work for Python 3.9, 3.10, and 3.11, and for PyPy. Check
3. The pull request should work for Python, 3.10, 3.11 and 3.12, and for PyPy. Check
https://travis-ci.com/easyScience/EasyReflectometryLib/pull_requests
and make sure that the tests pass for all supported Python versions.

Expand Down
11 changes: 4 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,18 @@ classifiers = [
"Topic :: Scientific/Engineering",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Development Status :: 3 - Alpha"
]
requires-python = ">=3.9,<3.13"
requires-python = ">=3.10,<3.13"
dependencies = [
"easyscience>=1.2.0",
"easyscience @git+https://github.com/EasyScience/EasyScience@develop",
"scipp>=23.12.0",
"refnx>=0.1.15",
"refl1d",
"refl1d[webview]==1.0.0a12",
"orsopy>=0.0.4",
"pint==0.23", # Only to ensure that unit is reported as dimensionless rather than empty string
"xhtml2pdf>=0.2.16"
]

Expand Down Expand Up @@ -131,10 +129,9 @@ force-single-line = true
legacy_tox_ini = """
[tox]
isolated_build = True
envlist = py{3.9,3.10,3.11,3.12}
envlist = py{3.10,3.11,3.12}
[gh-actions]
python =
3.9: py39
3.10: py310
3.11: py311
3.12: py312
Expand Down
18 changes: 9 additions & 9 deletions src/easyreflectometry/calculators/refl1d/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from typing import Tuple

import numpy as np
from refl1d import model
from refl1d import names
from refl1d.sample.layers import Repeat

from easyreflectometry.model import PercentageFwhm

Expand Down Expand Up @@ -34,16 +34,16 @@ def create_layer(self, name: str):
magnetism = names.Magnetism(rhoM=0.0, thetaM=0.0)
else:
magnetism = None
self.storage['layer'][name] = model.Slab(name=str(name), magnetism=magnetism)
self.storage['layer'][name] = names.Slab(name=str(name), magnetism=magnetism)

def create_item(self, name: str):
"""
Create an item using Repeat.

:param name: The name of the item
"""
self.storage['item'][name] = model.Repeat(
model.Stack(model.Slab(names.SLD(), thickness=0, interface=0)), name=str(name)
self.storage['item'][name] = Repeat(
names.Stack(names.Slab(names.SLD(), thickness=0, interface=0)), name=str(name)
)
del self.storage['item'][name].stack[0]

Expand All @@ -66,7 +66,7 @@ def get_layer_value(self, name: str, key: str) -> float:
:param key: The given value keys
"""
if key in ['magnetism_rhoM', 'magnetism_thetaM']:
return getattr(self.storage['layer'][name].magnetism, key.split('_')[-1])
return getattr(self.storage['layer'][name].magnetism, key.split('_')[-1]).value #TODO: check if we want to return the raw value or the full Parameter # noqa: E501
return super().get_layer_value(name, key)

def create_model(self, name: str):
Expand Down Expand Up @@ -267,18 +267,18 @@ def _get_polarized_probe(
return names.PolarizedQProbe(xs=four_probes, name='polarized')


def _build_sample(storage: dict, model_name: str) -> model.Stack:
sample = model.Stack()
def _build_sample(storage: dict, model_name: str) -> names.Stack:
sample = names.Stack()
# -1 to reverse the order
for i in storage['model'][model_name]['items'][::-1]:
if i.repeat.value == 1:
# -1 to reverse the order
for j in range(len(i.stack))[::-1]:
sample |= i.stack[j]
else:
stack = model.Stack()
stack = names.Stack()
# -1 to reverse the order
for j in range(len(i.stack))[::-1]:
stack |= i.stack[j]
sample |= model.Repeat(stack, repeat=i.repeat.value)
sample |= Repeat(stack, repeat=i.repeat.value)
return sample
6 changes: 3 additions & 3 deletions src/easyreflectometry/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

import numpy as np
from easyscience import global_object
from easyscience.Objects.new_variable import Parameter
from easyscience.Objects.ObjectClasses import BaseObj
from easyscience.Objects.variable import Parameter

from easyreflectometry.sample import BaseAssembly
from easyreflectometry.sample import Sample
Expand All @@ -26,15 +26,15 @@
'url': 'https://github.com/reflectivity/edu_outreach/blob/master/refl_maths/paper.tex',
'value': 1.0,
'min': 0,
'max': np.Inf,
'max': np.inf,
'fixed': True,
},
'background': {
'description': 'Linear background to include in reflectometry data',
'url': 'https://github.com/reflectivity/edu_outreach/blob/master/refl_maths/paper.tex',
'value': 1e-8,
'min': 0.0,
'max': np.Inf,
'max': np.inf,
'fixed': True,
},
'resolution': {
Expand Down
2 changes: 1 addition & 1 deletion src/easyreflectometry/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from easyscience import global_object
from easyscience.fitting import AvailableMinimizers
from easyscience.fitting.fitter import DEFAULT_MINIMIZER
from easyscience.Objects.new_variable import Parameter
from easyscience.Objects.variable import Parameter
from scipp import DataGroup

from easyreflectometry.calculators import CalculatorFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Union

from easyscience import global_object
from easyscience.Objects.new_variable import Parameter
from easyscience.Objects.variable import Parameter

from easyreflectometry.utils import get_as_parameter

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from easyscience import global_object
from easyscience.Constraints import ObjConstraint
from easyscience.Objects.new_variable import Parameter
from easyscience.Objects.variable import Parameter

from ..collections.layer_collection import LayerCollection
from ..elements.layers.layer_area_per_molecule import LayerAreaPerMolecule
Expand Down
6 changes: 3 additions & 3 deletions src/easyreflectometry/sample/elements/layers/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import numpy as np
from easyscience import global_object
from easyscience.Objects.new_variable import Parameter
from easyscience.Objects.variable import Parameter

from easyreflectometry.utils import get_as_parameter

Expand All @@ -18,7 +18,7 @@
'value': 10.0,
'unit': 'angstrom',
'min': 0.0,
'max': np.Inf,
'max': np.inf,
'fixed': True,
},
'roughness': {
Expand All @@ -27,7 +27,7 @@
'value': 3.3,
'unit': 'angstrom',
'min': 0.0,
'max': np.Inf,
'max': np.inf,
'fixed': True,
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy as np
from easyscience import global_object
from easyscience.Constraints import FunctionalConstraint
from easyscience.Objects.new_variable import Parameter
from easyscience.Objects.variable import Parameter

from easyreflectometry.special.calculations import area_per_molecule_to_scattering_length_density
from easyreflectometry.special.calculations import neutron_scattering_length
Expand All @@ -31,17 +31,17 @@
'url': 'https://www.ncnr.nist.gov/resources/activation/',
'value': 4.186,
'unit': 'angstrom',
'min': -np.Inf,
'max': np.Inf,
'min': -np.inf,
'max': np.inf,
'fixed': True,
},
'isl': {
'description': 'The real scattering length for a molecule formula in angstrom.',
'url': 'https://www.ncnr.nist.gov/resources/activation/',
'value': 0.0,
'unit': 'angstrom',
'min': -np.Inf,
'max': np.Inf,
'min': -np.inf,
'max': np.inf,
'fixed': True,
},
}
Expand Down
10 changes: 5 additions & 5 deletions src/easyreflectometry/sample/elements/materials/material.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import numpy as np
from easyscience import global_object
from easyscience.Objects.new_variable import Parameter
from easyscience.Objects.variable import Parameter

from easyreflectometry.utils import get_as_parameter

Expand All @@ -17,17 +17,17 @@
'url': 'https://www.ncnr.nist.gov/resources/activation/',
'value': 4.186,
'unit': '1 / angstrom^2',
'min': -np.Inf,
'max': np.Inf,
'min': -np.inf,
'max': np.inf,
'fixed': True,
},
'isld': {
'description': 'The imaginary scattering length density for a material in e-6 per squared angstrom.',
'url': 'https://www.ncnr.nist.gov/resources/activation/',
'value': 0.0,
'unit': '1 / angstrom^2',
'min': -np.Inf,
'max': np.Inf,
'min': -np.inf,
'max': np.inf,
'fixed': True,
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy as np
from easyscience import global_object
from easyscience.Constraints import FunctionalConstraint
from easyscience.Objects.new_variable import Parameter
from easyscience.Objects.variable import Parameter

from easyreflectometry.special.calculations import density_to_sld
from easyreflectometry.special.calculations import molecular_weight
Expand All @@ -22,16 +22,16 @@
'value': 2.33,
'unit': 'gram / centimeter ** 3',
'min': 0,
'max': np.Inf,
'max': np.inf,
'fixed': True,
},
'molecular_weight': {
'description': 'The molecular weight of a material.',
'url': 'https://en.wikipedia.org/wiki/Molecular_mass',
'value': 28.02,
'unit': 'g / mole',
'min': -np.Inf,
'max': np.Inf,
'min': -np.inf,
'max': np.inf,
'fixed': True,
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from easyscience import global_object
from easyscience.Constraints import FunctionalConstraint
from easyscience.Objects.new_variable import Parameter
from easyscience.Objects.variable import Parameter

from easyreflectometry.special.calculations import weighted_average
from easyreflectometry.utils import get_as_parameter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Union

from easyscience import global_object
from easyscience.Objects.new_variable import Parameter
from easyscience.Objects.variable import Parameter

from easyreflectometry.utils import get_as_parameter

Expand Down
2 changes: 1 addition & 1 deletion src/easyreflectometry/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import yaml
from easyscience import global_object
from easyscience.Objects.new_variable import Parameter
from easyscience.Objects.variable import Parameter


def get_as_parameter(
Expand Down
4 changes: 2 additions & 2 deletions tests/calculators/refl1d/test_refl1d_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,8 @@ def test_get_polarized_probe_polarization():
assert len(probe.xs[3].calc_Qo) == len(q)


@patch('easyreflectometry.calculators.refl1d.wrapper.model.Stack')
@patch('easyreflectometry.calculators.refl1d.wrapper.model.Repeat')
@patch('easyreflectometry.calculators.refl1d.wrapper.names.Stack')
@patch('easyreflectometry.calculators.refl1d.wrapper.Repeat')
def test_build_sample(mock_repeat, mock_stack):
# When
mock_item_1 = MagicMock()
Expand Down
8 changes: 4 additions & 4 deletions tests/model/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ def test_default(self):
assert_equal(str(p.scale.unit), 'dimensionless')
assert_equal(p.scale.value, 1.0)
assert_equal(p.scale.min, 0.0)
assert_equal(p.scale.max, np.Inf)
assert_equal(p.scale.max, np.inf)
assert_equal(p.scale.fixed, True)
assert_equal(p.background.display_name, 'background')
assert_equal(str(p.background.unit), 'dimensionless')
assert_equal(p.background.value, 1.0e-8)
assert_equal(p.background.min, 0.0)
assert_equal(p.background.max, np.Inf)
assert_equal(p.background.max, np.inf)
assert_equal(p.background.fixed, True)
assert p._resolution_function.smearing([1]) == 5.0
assert p._resolution_function.smearing([100]) == 5.0
Expand Down Expand Up @@ -73,13 +73,13 @@ def test_from_pars(self):
assert_equal(str(mod.scale.unit), 'dimensionless')
assert_equal(mod.scale.value, 2.0)
assert_equal(mod.scale.min, 0.0)
assert_equal(mod.scale.max, np.Inf)
assert_equal(mod.scale.max, np.inf)
assert_equal(mod.scale.fixed, True)
assert_equal(mod.background.display_name, 'background')
assert_equal(str(mod.background.unit), 'dimensionless')
assert_equal(mod.background.value, 1.0e-5)
assert_equal(mod.background.min, 0.0)
assert_equal(mod.background.max, np.Inf)
assert_equal(mod.background.max, np.inf)
assert_equal(mod.background.fixed, True)
assert mod._resolution_function.smearing([1]) == 2.0
assert mod._resolution_function.smearing([100]) == 2.0
Expand Down
Loading
Loading