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

Manual backports to yt-4.0.x (blockers and bugfixes) #3789

Merged
merged 10 commits into from
Feb 15, 2022
Merged
48 changes: 44 additions & 4 deletions .github/workflows/wheels.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
# pinning OS versions to oldest versions available
# because forward compatibility is much easier to
# guarantee than backward compatibility
os: [
macos-latest,
windows-latest,
ubuntu-18.04, # has to be the oldest possible for manylinux
ubuntu-18.04,
windows-2019,
macos-10.15,
]
fail-fast: false

Expand All @@ -27,6 +30,8 @@ jobs:

- name: Build wheels for CPython
uses: pypa/[email protected]
with:
output-dir: dist
env:
CIBW_BUILD: "cp36-* cp37-* cp38-* cp39-* cp310-*"
CIBW_SKIP: "*-musllinux_*" # numpy doesn't have wheels for musllinux so we can't build some quickly and without bloating
Expand All @@ -40,4 +45,39 @@ jobs:
- uses: actions/upload-artifact@v2
with:
name: wheels
path: ./wheelhouse/*.whl
path: ./dist/*.whl

build_sdist:
name: Build source distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Build sdist
run: pipx run build --sdist

- uses: actions/upload-artifact@v2
with:
name: tarball
path: dist/*.tar.gz

upload_pypi:
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
# upload to PyPI on every tag starting with 'yt-'
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/yt-')
steps:
- uses: actions/download-artifact@v2
with:
name: tarball
path: dist

- uses: actions/download-artifact@v2
with:
name: wheels
path: dist

- uses: pypa/[email protected]
with:
user: __token__
password: ${{ secrets.pypi_token }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ png.cfg
rockstar.cfg
yt_updater.log
yt/frontends/artio/_artio_caller.c
yt/frontends/gamer/cfields.c
yt/analysis_modules/halo_finding/rockstar/rockstar_groupies.c
yt/analysis_modules/halo_finding/rockstar/rockstar_interface.c
yt/analysis_modules/ppv_cube/ppv_utils.c
Expand Down
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ repos:
- id: end-of-file-fixer
- id: no-commit-to-branch
args: [--branch, main]
- id: check-yaml
- repo: https:/asottile/pyupgrade
rev: v2.19.4
hooks:
Expand Down
4 changes: 2 additions & 2 deletions doc/source/developing/creating_frontend.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ If you are interested in adding a new code, be sure to drop us a line on
`yt-dev <https://mail.python.org/archives/list/[email protected]/>`_!


Boostraping a new frontend
--------------------------
Bootstrapping a new frontend
----------------------------

To get started

Expand Down
2 changes: 1 addition & 1 deletion doc/source/developing/deprecating_features.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Here's an example call.
issue_deprecation_warning(
"`old_function` is deprecated, use `replacement_function` instead."
since="4.0.0",
removal="4.1.0"
removal="4.1.0",
)
...

Expand Down
2 changes: 1 addition & 1 deletion doc/source/examining/Loading_Generic_Array_Data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
"* `mass_unit` : The unit that corresponds to `code_mass`, can be a string, tuple, or floating-point number\n",
"* `time_unit` : The unit that corresponds to `code_time`, can be a string, tuple, or floating-point number\n",
"* `velocity_unit` : The unit that corresponds to `code_velocity`\n",
"* `magnetic_unit` : The unit that corresponds to `code_magnetic`, i.e. the internal units used to represent magnetic field strengths.\n",
"* `magnetic_unit` : The unit that corresponds to `code_magnetic`, i.e. the internal units used to represent magnetic field strengths. NOTE: if you want magnetic field units to be in the SI unit system, you must specify it here, e.g. `magnetic_unit=(1.0, \"T\")`\n",
"* `periodicity` : A tuple of booleans that determines whether the data will be treated as periodic along each axis\n",
"\n",
"This example creates a yt-native dataset `ds` that will treat your array as a\n",
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ nose.plugins.0.10 =
doc =
alabaster
bottle
jupyter-client<7.0
nbconvert==5.6.1
pyregion
pyx>=0.15
Expand Down
6 changes: 4 additions & 2 deletions tests/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ answer_tests:
- yt/frontends/athena/tests/test_outputs.py:test_blast
- yt/frontends/athena/tests/test_outputs.py:test_stripping

local_athena_pp_004:
- yt/frontends/athena_pp/tests/test_outputs.py:test_disk
local_athena_pp_006:
# disabling disk test for now until we have better support
# for this dataset
#- yt/frontends/athena_pp/tests/test_outputs.py:test_disk
- yt/frontends/athena_pp/tests/test_outputs.py:test_AM06

local_chombo_005:
Expand Down
93 changes: 70 additions & 23 deletions yt/data_objects/static_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -1119,27 +1119,47 @@ def relative_refinement(self, l0, l1):
return self.refine_by ** (l1 - l0)

def _assign_unit_system(self, unit_system):
if unit_system == "cgs":
current_mks_unit = None
# we need to determine if the requested unit system
# is mks-like: i.e., it has a current with the same
# dimensions as amperes.
mks_system = False
if getattr(self, "magnetic_unit", None):
mag_dims = self.magnetic_unit.units.dimensions.free_symbols
else:
current_mks_unit = "A"
magnetic_unit = getattr(self, "magnetic_unit", None)
if magnetic_unit is not None:
if unit_system == "mks":
if current_mks not in self.magnetic_unit.units.dimensions.free_symbols:
self.magnetic_unit = self.magnetic_unit.to("gauss").to("T")
self.unit_registry.modify("code_magnetic", self.magnetic_unit.value)
else:
# if the magnetic unit is in T, we need to create the code unit
# system as an MKS-like system
if current_mks in self.magnetic_unit.units.dimensions.free_symbols:
self.magnetic_unit = self.magnetic_unit.to("T").to("gauss")
mag_dims = None
if unit_system != "code":
# if the unit system is known, we can check if it
# has a "current_mks" unit
us = unit_system_registry[str(unit_system).lower()]
mks_system = us.base_units[current_mks] is not None
elif mag_dims and current_mks in mag_dims:
# if we're using the not-yet defined code unit system,
# then we check if the magnetic field unit has a SI
# current dimension in it
mks_system = True
# Now we get to the tricky part. If we have an MKS-like system but
# we asked for a conversion to something CGS-like, or vice-versa,
# we have to convert the magnetic field
if mag_dims is not None:
if mks_system and current_mks not in mag_dims:
self.magnetic_unit = self.quan(
self.magnetic_unit.to_value("gauss") * 1.0e-4, "T"
)
# The following modification ensures that we get the conversion to
# mks correct
self.unit_registry.modify(
"code_magnetic", self.magnetic_unit.value * 1.0e3 * 0.1 ** -0.5
)
elif not mks_system and current_mks in mag_dims:
self.magnetic_unit = self.quan(
self.magnetic_unit.to_value("T") * 1.0e4, "gauss"
)
# The following modification ensures that we get the conversion to
# cgs correct
self.unit_registry.modify(
"code_magnetic", self.magnetic_unit.value * 0.1 ** 0.5
"code_magnetic", self.magnetic_unit.value * 1.0e-4
)

current_mks_unit = "A" if mks_system else None
us = create_code_unit_system(
self.unit_registry, current_mks_unit=current_mks_unit
)
Expand All @@ -1165,25 +1185,34 @@ def _create_unit_registry(self, unit_system):
# yt assumes a CGS unit system by default (for back compat reasons).
# Since unyt is MKS by default we specify the MKS values of the base
# units in the CGS system. So, for length, 1 cm = .01 m. And so on.
# Note that the values associated with the code units here will be
# modified once we actually determine what the code units are from
# the dataset
# NOTE that magnetic fields are not done here yet, see set_code_units
self.unit_registry = UnitRegistry(unit_system=unit_system)
# 1 cm = 0.01 m
self.unit_registry.add("code_length", 0.01, dimensions.length)
# 1 g = 0.001 kg
self.unit_registry.add("code_mass", 0.001, dimensions.mass)
# 1 g/cm**3 = 1000 kg/m**3
self.unit_registry.add("code_density", 1000.0, dimensions.density)
# 1 erg/g = 1.0e-4 J/kg
self.unit_registry.add(
"code_specific_energy", 1.0, dimensions.energy / dimensions.mass
"code_specific_energy", 1.0e-4, dimensions.energy / dimensions.mass
)
# 1 s = 1 s
self.unit_registry.add("code_time", 1.0, dimensions.time)
if unit_system == "mks":
self.unit_registry.add("code_magnetic", 1.0, dimensions.magnetic_field)
else:
self.unit_registry.add(
"code_magnetic", 0.1 ** 0.5, dimensions.magnetic_field_cgs
)
# 1 K = 1 K
self.unit_registry.add("code_temperature", 1.0, dimensions.temperature)
# 1 dyn/cm**2 = 0.1 N/m**2
self.unit_registry.add("code_pressure", 0.1, dimensions.pressure)
# 1 cm/s = 0.01 m/s
self.unit_registry.add("code_velocity", 0.01, dimensions.velocity)
# metallicity
self.unit_registry.add("code_metallicity", 1.0, dimensions.dimensionless)
# dimensionless hubble parameter
self.unit_registry.add("h", 1.0, dimensions.dimensionless, r"h")
# cosmological scale factor
self.unit_registry.add("a", 1.0, dimensions.dimensionless)

def set_units(self):
Expand Down Expand Up @@ -1285,6 +1314,24 @@ def set_code_units(self):
self.unit_registry.modify("code_pressure", pressure_unit)
self.unit_registry.modify("code_density", density_unit)
self.unit_registry.modify("code_specific_energy", specific_energy_unit)
# Defining code units for magnetic fields are tricky because
# they have different dimensions in different unit systems, so we have
# to handle them carefully
if hasattr(self, "magnetic_unit"):
if self.magnetic_unit.units.dimensions == dimensions.magnetic_field_cgs:
# We have to cast this explicitly to MKS base units, otherwise
# unyt will convert it automatically to Tesla
value = self.magnetic_unit.to_value("sqrt(kg)/(sqrt(m)*s)")
dims = dimensions.magnetic_field_cgs
else:
value = self.magnetic_unit.to_value("T")
dims = dimensions.magnetic_field_mks
else:
# Fallback to gauss if no magnetic unit is specified
# 1 gauss = 1 sqrt(g)/(sqrt(cm)*s) = 0.1**0.5 sqrt(kg)/(sqrt(m)*s)
value = 0.1 ** 0.5
dims = dimensions.magnetic_field_cgs
self.unit_registry.add("code_magnetic", value, dims)
# domain_width does not yet exist
if self.domain_left_edge is not None and self.domain_right_edge is not None:
DW = self.arr(self.domain_right_edge - self.domain_left_edge, "code_length")
Expand Down
2 changes: 1 addition & 1 deletion yt/fields/derived_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def get_label(self, projected=False):
units = Unit(self.units)
# Add unit label
if not units.is_dimensionless:
data_label += r"\ \ (%s)" % (units.latex_representation())
data_label += r"\ \ \left(%s\right)" % (units.latex_representation())

data_label += r"$"
return data_label
Expand Down
5 changes: 2 additions & 3 deletions yt/fields/field_info_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,8 @@ def _sanitize_sampling_type(sampling_type, particle_type=None):
acceptable_samplings = ("cell", "particle", "local")
if sampling_type not in acceptable_samplings:
raise ValueError(
"Invalid sampling type %s. Valid sampling types are %s",
sampling_type,
", ".join(acceptable_samplings),
f"Received invalid sampling type {sampling_type!r}. "
f"Expected any of {acceptable_samplings}"
)

if particle_type:
Expand Down
5 changes: 3 additions & 2 deletions yt/fields/fluid_fields.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import numpy as np

from yt.units.unit_object import Unit
from yt.units.dimensions import current_mks # type: ignore
from yt.units.unit_object import Unit # type: ignore
from yt.utilities.chemical_formulas import compute_mu
from yt.utilities.lib.misc_utilities import obtain_relative_velocity_vector

Expand Down Expand Up @@ -31,7 +32,7 @@ def setup_fluid_fields(registry, ftype="gas", slice_info=None):

unit_system = registry.ds.unit_system

if unit_system.name == "cgs":
if unit_system.base_units[current_mks] is None:
mag_units = "magnetic_field_cgs"
else:
mag_units = "magnetic_field_mks"
Expand Down
10 changes: 5 additions & 5 deletions yt/fields/tests/test_ambiguous_fields.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import warnings
from collections import defaultdict

import pytest
Expand Down Expand Up @@ -32,13 +33,12 @@ def test_ambiguous_fails():

# Test no warnings are issued for single fname access that aren't ambiguous
for fname in unambiguous_fnames:
with pytest.warns(None) as record:
with warnings.catch_warnings():
warnings.simplefilter("error")
ds.r[fname]
assert len(record) == 0

# Test no warning are issued for tuple access
for ftype, fname in ds.field_list:
with pytest.warns(None) as record:
with warnings.catch_warnings():
warnings.simplefilter("error")
ds.r[(ftype, fname)]

assert len(record) == 0
Loading