From ab2d0d059db0e15597619e65a316a2d1a5e1bbeb Mon Sep 17 00:00:00 2001 From: Vecko <36369090+VeckoTheGecko@users.noreply.github.com> Date: Wed, 13 Nov 2024 19:58:05 +0800 Subject: [PATCH 1/5] cleanup pointless abc inheritence --- parcels/compilation/codegenerator.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/parcels/compilation/codegenerator.py b/parcels/compilation/codegenerator.py index 3038f2340..33351ac6c 100644 --- a/parcels/compilation/codegenerator.py +++ b/parcels/compilation/codegenerator.py @@ -3,7 +3,6 @@ import math import random import warnings -from abc import ABC from copy import copy import cgen as c @@ -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. From 2fc9e19590161ad16c09d0d089a7b9d7a87e72fa Mon Sep 17 00:00:00 2001 From: Vecko <36369090+VeckoTheGecko@users.noreply.github.com> Date: Thu, 14 Nov 2024 14:33:49 +0800 Subject: [PATCH 2/5] patch pset repr fieldset indentation --- parcels/tools/_helpers.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/parcels/tools/_helpers.py b/parcels/tools/_helpers.py index 9078690cc..bf059c497 100644 --- a/parcels/tools/_helpers.py +++ b/parcels/tools/_helpers.py @@ -115,7 +115,8 @@ def particleset_repr(pset: ParticleSet) -> str: particles = [repr(pset[i]) for i in range(7)] + ["..."] out = f"""<{type(pset).__name__}> - fieldset : {pset.fieldset} + fieldset : +{textwrap.indent(repr(pset.fieldset), " " * 8)} pclass : {pset.pclass} repeatdt : {pset.repeatdt} # particles: {len(pset)} From 90865b157dbb32d86cef5b5dd561024041efbd02 Mon Sep 17 00:00:00 2001 From: Vecko <36369090+VeckoTheGecko@users.noreply.github.com> Date: Wed, 20 Nov 2024 11:33:51 +0800 Subject: [PATCH 3/5] Update ParticleType repr --- parcels/particle.py | 2 +- tests/test_reprs.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/parcels/particle.py b/parcels/particle.py index 87dce269f..08e46ff08 100644 --- a/parcels/particle.py +++ b/parcels/particle.py @@ -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: diff --git a/tests/test_reprs.py b/tests/test_reprs.py index bce4bce4b..18ed68a0a 100644 --- a/tests/test_reprs.py +++ b/tests/test_reprs.py @@ -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( From 677af0d10ff4d200304645269be071e69c9f53b7 Mon Sep 17 00:00:00 2001 From: Vecko <36369090+VeckoTheGecko@users.noreply.github.com> Date: Wed, 20 Nov 2024 16:02:04 +0800 Subject: [PATCH 4/5] re-run parcels_tutorial --- docs/examples/parcels_tutorial.ipynb | 131 ++++++++++++++------------- 1 file changed, 67 insertions(+), 64 deletions(-) diff --git a/docs/examples/parcels_tutorial.ipynb b/docs/examples/parcels_tutorial.ipynb index 102a87419..3077dfe57 100644 --- a/docs/examples/parcels_tutorial.ipynb +++ b/docs/examples/parcels_tutorial.ipynb @@ -183,27 +183,28 @@ "output_type": "stream", "text": [ "\n", - " fieldset :
\n", - " fields:\n", - " \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", - " \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", - " \n", - " name: 'UV'\n", - " U: \n", - " V: \n", - " W: None\n", + " fieldset :\n", + "
\n", + " fields:\n", + " \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", + " \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", + " \n", + " name: 'UV'\n", + " U: \n", + " V: \n", + " W: None\n", " pclass : \n", " repeatdt : None\n", " # particles: 2\n", @@ -338,27 +339,28 @@ "output_type": "stream", "text": [ "\n", - " fieldset :
\n", - " fields:\n", - " \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", - " \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", - " \n", - " name: 'UV'\n", - " U: \n", - " V: \n", - " W: None\n", + " fieldset :\n", + "
\n", + " fields:\n", + " \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", + " \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", + " \n", + " name: 'UV'\n", + " U: \n", + " V: \n", + " W: None\n", " pclass : \n", " repeatdt : None\n", " # particles: 2\n", @@ -13338,27 +13340,28 @@ "output_type": "stream", "text": [ "\n", - " fieldset :
\n", - " fields:\n", - " \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", - " \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", - " \n", - " name: 'UV'\n", - " U: \n", - " V: \n", - " W: None\n", + " fieldset :\n", + "
\n", + " fields:\n", + " \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", + " \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", + " \n", + " name: 'UV'\n", + " U: \n", + " V: \n", + " W: None\n", " pclass : \n", " repeatdt : None\n", " # particles: 2\n", @@ -13818,7 +13821,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 28, "metadata": {}, "outputs": [ { From cddffe8f0c035335dd2f4374f96f8c61b3f7f697 Mon Sep 17 00:00:00 2001 From: Vecko <36369090+VeckoTheGecko@users.noreply.github.com> Date: Wed, 20 Nov 2024 16:10:56 +0800 Subject: [PATCH 5/5] xfail test_mitgcm for "auto" chunk_mode --- docs/examples/example_dask_chunk_OCMs.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/docs/examples/example_dask_chunk_OCMs.py b/docs/examples/example_dask_chunk_OCMs.py index fd2b2d91a..9a4cf7f53 100644 --- a/docs/examples/example_dask_chunk_OCMs.py +++ b/docs/examples/example_dask_chunk_OCMs.py @@ -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):