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

Update ParticleType repr #1766

Merged
merged 5 commits into from
Nov 20, 2024
Merged
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
13 changes: 12 additions & 1 deletion docs/examples/example_dask_chunk_OCMs.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,18 @@ def test_ofam_3D(mode, chunk_mode):

@pytest.mark.parametrize("mode", ["jit"])
@pytest.mark.parametrize(
"chunk_mode", [False, "auto", "specific_same", "specific_different"]
"chunk_mode",
[
False,
pytest.param(
"auto",
marks=pytest.mark.xfail(
reason="Dask v2024.11.0 caused auto chunking to fail. See #1762"
),
),
"specific_same",
"specific_different",
],
)
@pytest.mark.parametrize("using_add_field", [False, True])
def test_mitgcm(mode, chunk_mode, using_add_field):
Expand Down
131 changes: 67 additions & 64 deletions docs/examples/parcels_tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -183,27 +183,28 @@
"output_type": "stream",
"text": [
"<ParticleSet>\n",
" fieldset : <FieldSet>\n",
" fields:\n",
" <Field>\n",
" name : 'U'\n",
" grid : RectilinearZGrid(lon=array([ 0.00, 2010.05, 4020.10, ..., 395979.91, 397989.94, 400000.00], dtype=float32), lat=array([ 0.00, 2005.73, 4011.46, ..., 695988.56, 697994.25, 700000.00], dtype=float32), time=array([ 0.00, 86400.00]), time_origin=0.0, mesh='flat')\n",
" extrapolate time: False\n",
" time_periodic : False\n",
" gridindexingtype: 'nemo'\n",
" to_write : False\n",
" <Field>\n",
" name : 'V'\n",
" grid : RectilinearZGrid(lon=array([ 0.00, 2010.05, 4020.10, ..., 395979.91, 397989.94, 400000.00], dtype=float32), lat=array([ 0.00, 2005.73, 4011.46, ..., 695988.56, 697994.25, 700000.00], dtype=float32), time=array([ 0.00, 86400.00]), time_origin=0.0, mesh='flat')\n",
" extrapolate time: False\n",
" time_periodic : False\n",
" gridindexingtype: 'nemo'\n",
" to_write : False\n",
" <VectorField>\n",
" name: 'UV'\n",
" U: <parcels.field.Field object at 0x1580e0980>\n",
" V: <parcels.field.Field object at 0x1585d8920>\n",
" W: None\n",
" fieldset :\n",
" <FieldSet>\n",
" fields:\n",
" <Field>\n",
" name : 'U'\n",
" grid : RectilinearZGrid(lon=array([ 0.00, 2010.05, 4020.10, ..., 395979.91, 397989.94, 400000.00], dtype=float32), lat=array([ 0.00, 2005.73, 4011.46, ..., 695988.56, 697994.25, 700000.00], dtype=float32), time=array([ 0.00, 86400.00]), time_origin=0.0, mesh='flat')\n",
" extrapolate time: False\n",
" time_periodic : False\n",
" gridindexingtype: 'nemo'\n",
" to_write : False\n",
" <Field>\n",
" name : 'V'\n",
" grid : RectilinearZGrid(lon=array([ 0.00, 2010.05, 4020.10, ..., 395979.91, 397989.94, 400000.00], dtype=float32), lat=array([ 0.00, 2005.73, 4011.46, ..., 695988.56, 697994.25, 700000.00], dtype=float32), time=array([ 0.00, 86400.00]), time_origin=0.0, mesh='flat')\n",
" extrapolate time: False\n",
" time_periodic : False\n",
" gridindexingtype: 'nemo'\n",
" to_write : False\n",
" <VectorField>\n",
" name: 'UV'\n",
" U: <parcels.field.Field object at 0x164112020>\n",
" V: <parcels.field.Field object at 0x164111a80>\n",
" W: None\n",
" pclass : <class 'parcels.particle.JITParticle'>\n",
" repeatdt : None\n",
" # particles: 2\n",
Expand Down Expand Up @@ -338,27 +339,28 @@
"output_type": "stream",
"text": [
"<ParticleSet>\n",
" fieldset : <FieldSet>\n",
" fields:\n",
" <Field>\n",
" name : 'U'\n",
" grid : RectilinearZGrid(lon=array([ 0.00, 2010.05, 4020.10, ..., 395979.91, 397989.94, 400000.00], dtype=float32), lat=array([ 0.00, 2005.73, 4011.46, ..., 695988.56, 697994.25, 700000.00], dtype=float32), time=array([ 432000.00, 518400.00]), time_origin=0.0, mesh='flat')\n",
" extrapolate time: False\n",
" time_periodic : False\n",
" gridindexingtype: 'nemo'\n",
" to_write : False\n",
" <Field>\n",
" name : 'V'\n",
" grid : RectilinearZGrid(lon=array([ 0.00, 2010.05, 4020.10, ..., 395979.91, 397989.94, 400000.00], dtype=float32), lat=array([ 0.00, 2005.73, 4011.46, ..., 695988.56, 697994.25, 700000.00], dtype=float32), time=array([ 432000.00, 518400.00]), time_origin=0.0, mesh='flat')\n",
" extrapolate time: False\n",
" time_periodic : False\n",
" gridindexingtype: 'nemo'\n",
" to_write : False\n",
" <VectorField>\n",
" name: 'UV'\n",
" U: <parcels.field.Field object at 0x1580e0980>\n",
" V: <parcels.field.Field object at 0x1585d8920>\n",
" W: None\n",
" fieldset :\n",
" <FieldSet>\n",
" fields:\n",
" <Field>\n",
" name : 'U'\n",
" grid : RectilinearZGrid(lon=array([ 0.00, 2010.05, 4020.10, ..., 395979.91, 397989.94, 400000.00], dtype=float32), lat=array([ 0.00, 2005.73, 4011.46, ..., 695988.56, 697994.25, 700000.00], dtype=float32), time=array([ 432000.00, 518400.00]), time_origin=0.0, mesh='flat')\n",
" extrapolate time: False\n",
" time_periodic : False\n",
" gridindexingtype: 'nemo'\n",
" to_write : False\n",
" <Field>\n",
" name : 'V'\n",
" grid : RectilinearZGrid(lon=array([ 0.00, 2010.05, 4020.10, ..., 395979.91, 397989.94, 400000.00], dtype=float32), lat=array([ 0.00, 2005.73, 4011.46, ..., 695988.56, 697994.25, 700000.00], dtype=float32), time=array([ 432000.00, 518400.00]), time_origin=0.0, mesh='flat')\n",
" extrapolate time: False\n",
" time_periodic : False\n",
" gridindexingtype: 'nemo'\n",
" to_write : False\n",
" <VectorField>\n",
" name: 'UV'\n",
" U: <parcels.field.Field object at 0x164112020>\n",
" V: <parcels.field.Field object at 0x164111a80>\n",
" W: None\n",
" pclass : <class 'parcels.particle.JITParticle'>\n",
" repeatdt : None\n",
" # particles: 2\n",
Expand Down Expand Up @@ -13338,27 +13340,28 @@
"output_type": "stream",
"text": [
"<ParticleSet>\n",
" fieldset : <FieldSet>\n",
" fields:\n",
" <Field>\n",
" name : 'U'\n",
" grid : RectilinearZGrid(lon=array([ 0.00, 2010.05, 4020.10, ..., 395979.91, 397989.94, 400000.00], dtype=float32), lat=array([ 0.00, 2005.73, 4011.46, ..., 695988.56, 697994.25, 700000.00], dtype=float32), time=array([ 0.00, 86400.00]), time_origin=0.0, mesh='flat')\n",
" extrapolate time: False\n",
" time_periodic : False\n",
" gridindexingtype: 'nemo'\n",
" to_write : False\n",
" <Field>\n",
" name : 'V'\n",
" grid : RectilinearZGrid(lon=array([ 0.00, 2010.05, 4020.10, ..., 395979.91, 397989.94, 400000.00], dtype=float32), lat=array([ 0.00, 2005.73, 4011.46, ..., 695988.56, 697994.25, 700000.00], dtype=float32), time=array([ 0.00, 86400.00]), time_origin=0.0, mesh='flat')\n",
" extrapolate time: False\n",
" time_periodic : False\n",
" gridindexingtype: 'nemo'\n",
" to_write : False\n",
" <VectorField>\n",
" name: 'UV'\n",
" U: <parcels.field.Field object at 0x1580e0980>\n",
" V: <parcels.field.Field object at 0x1585d8920>\n",
" W: None\n",
" fieldset :\n",
" <FieldSet>\n",
" fields:\n",
" <Field>\n",
" name : 'U'\n",
" grid : RectilinearZGrid(lon=array([ 0.00, 2010.05, 4020.10, ..., 395979.91, 397989.94, 400000.00], dtype=float32), lat=array([ 0.00, 2005.73, 4011.46, ..., 695988.56, 697994.25, 700000.00], dtype=float32), time=array([ 0.00, 86400.00]), time_origin=0.0, mesh='flat')\n",
" extrapolate time: False\n",
" time_periodic : False\n",
" gridindexingtype: 'nemo'\n",
" to_write : False\n",
" <Field>\n",
" name : 'V'\n",
" grid : RectilinearZGrid(lon=array([ 0.00, 2010.05, 4020.10, ..., 395979.91, 397989.94, 400000.00], dtype=float32), lat=array([ 0.00, 2005.73, 4011.46, ..., 695988.56, 697994.25, 700000.00], dtype=float32), time=array([ 0.00, 86400.00]), time_origin=0.0, mesh='flat')\n",
" extrapolate time: False\n",
" time_periodic : False\n",
" gridindexingtype: 'nemo'\n",
" to_write : False\n",
" <VectorField>\n",
" name: 'UV'\n",
" U: <parcels.field.Field object at 0x164112020>\n",
" V: <parcels.field.Field object at 0x164111a80>\n",
" W: None\n",
" pclass : <class 'parcels.particle.JITParticle'>\n",
" repeatdt : None\n",
" # particles: 2\n",
Expand Down Expand Up @@ -13818,7 +13821,7 @@
},
{
"cell_type": "code",
"execution_count": 27,
"execution_count": 28,
"metadata": {},
"outputs": [
{
Expand Down
3 changes: 1 addition & 2 deletions parcels/compilation/codegenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import math
import random
import warnings
from abc import ABC
from copy import copy

import cgen as c
Expand Down Expand Up @@ -412,7 +411,7 @@ def visit_Assign(self, node):
return node


class KernelGenerator(ABC, ast.NodeVisitor):
class KernelGenerator(ast.NodeVisitor):
"""Code generator class that translates simple Python kernel functions into C functions.

Works by populating and accessing the `ccode` attribute on nodes in the Python AST.
Expand Down
2 changes: 1 addition & 1 deletion parcels/particle.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def __init__(self, pclass):
self.variables = [v for v in self.variables if v.is64bit()] + [v for v in self.variables if not v.is64bit()]

def __repr__(self):
return f"PType<{self.name}>::{self.variables}"
return f"{type(self).__name__}(pclass={self.name})"

def __getitem__(self, item):
for v in self.variables:
Expand Down
3 changes: 2 additions & 1 deletion parcels/tools/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@
particles = [repr(pset[i]) for i in range(7)] + ["..."]

out = f"""<{type(pset).__name__}>
fieldset : {pset.fieldset}
fieldset :
{textwrap.indent(repr(pset.fieldset), " " * 8)}

Check warning on line 119 in parcels/tools/_helpers.py

View check run for this annotation

Codecov / codecov/patch

parcels/tools/_helpers.py#L119

Added line #L119 was not covered by tests
pclass : {pset.pclass}
repeatdt : {pset.repeatdt}
# particles: {len(pset)}
Expand Down
5 changes: 5 additions & 0 deletions tests/test_reprs.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ def test_check_indentation():
assert not valid_indentation(invalid)


def test_particletype_repr():
kwargs = dict(pclass=parcels.JITParticle)
assert_simple_repr(parcels.particle.ParticleType, kwargs)


def test_grid_repr():
"""Test arguments are in the repr of a Grid object"""
kwargs = dict(
Expand Down
Loading