From ab14448284e75027d6c86e6e032174d8713ba450 Mon Sep 17 00:00:00 2001 From: Claudia Comito <39374113+ClaudiaComito@users.noreply.github.com> Date: Tue, 18 Apr 2023 12:19:34 +0200 Subject: [PATCH 1/5] implement early out for binary ops with integer term --- heat/core/_operations.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/heat/core/_operations.py b/heat/core/_operations.py index 17d8f73f28..884e536a64 100644 --- a/heat/core/_operations.py +++ b/heat/core/_operations.py @@ -84,6 +84,38 @@ def __binary_op( ) promoted_type = types.result_type(t1, t2).torch_type() + # early out for integer scalar terms + if isinstance(t2, int): + try: + result = operation(t1.larray, t2) + return DNDarray( + result, + gshape=t1.gshape, + dtype=t1.dtype, + device=t1.device, + split=t1.split, + comm=t1.comm, + balanced=t1.balanced, + ) + except AttributeError: + # t1 is a scalar + pass + elif isinstance(t1, int): + try: + result = operation(t1, t2.larray) + return DNDarray( + result, + gshape=t2.gshape, + dtype=t2.dtype, + device=t2.device, + split=t2.split, + comm=t2.comm, + balanced=t2.balanced, + ) + except AttributeError: + # t2 is a scalar + pass + # Make inputs Dndarrays if np.isscalar(t1) and np.isscalar(t2): try: From ef19e199fe14edb330fc52bde23150b4df40e174 Mon Sep 17 00:00:00 2001 From: Claudia Comito <39374113+ClaudiaComito@users.noreply.github.com> Date: Tue, 18 Apr 2023 13:18:34 +0200 Subject: [PATCH 2/5] early out for pow only --- heat/core/_operations.py | 32 -------------------------------- heat/core/arithmetics.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 32 deletions(-) diff --git a/heat/core/_operations.py b/heat/core/_operations.py index 884e536a64..17d8f73f28 100644 --- a/heat/core/_operations.py +++ b/heat/core/_operations.py @@ -84,38 +84,6 @@ def __binary_op( ) promoted_type = types.result_type(t1, t2).torch_type() - # early out for integer scalar terms - if isinstance(t2, int): - try: - result = operation(t1.larray, t2) - return DNDarray( - result, - gshape=t1.gshape, - dtype=t1.dtype, - device=t1.device, - split=t1.split, - comm=t1.comm, - balanced=t1.balanced, - ) - except AttributeError: - # t1 is a scalar - pass - elif isinstance(t1, int): - try: - result = operation(t1, t2.larray) - return DNDarray( - result, - gshape=t2.gshape, - dtype=t2.dtype, - device=t2.device, - split=t2.split, - comm=t2.comm, - balanced=t2.balanced, - ) - except AttributeError: - # t2 is a scalar - pass - # Make inputs Dndarrays if np.isscalar(t1) and np.isscalar(t2): try: diff --git a/heat/core/arithmetics.py b/heat/core/arithmetics.py index 7015388f99..bbf0066ffc 100644 --- a/heat/core/arithmetics.py +++ b/heat/core/arithmetics.py @@ -793,6 +793,37 @@ def pow(t1: Union[DNDarray, float], t2: Union[DNDarray, float]) -> DNDarray: DNDarray([[ 1., 8.], [27., 64.]], dtype=ht.float32, device=cpu:0, split=None) """ + # early exit for integer scalars + if isinstance(t2, int): + try: + result = torch.pow(t1.larray, t2) + return DNDarray( + result, + gshape=t1.gshape, + dtype=t1.dtype, + device=t1.device, + split=t1.split, + comm=t1.comm, + balanced=t1.balanced, + ) + except AttributeError: + # t1 is no DNDarray + pass + elif isinstance(t1, int): + try: + result = torch.pow(t1, t2.larray) + return DNDarray( + result, + gshape=t2.gshape, + dtype=t2.dtype, + device=t2.device, + split=t2.split, + comm=t2.comm, + balanced=t2.balanced, + ) + except AttributeError: + # t2 is no DNDarray + pass return _operations.__binary_op(torch.pow, t1, t2) From 6293ca2d8d159e675cf5bbc25242f806b3b1f887 Mon Sep 17 00:00:00 2001 From: Claudia Comito <39374113+ClaudiaComito@users.noreply.github.com> Date: Tue, 18 Apr 2023 15:47:01 +0200 Subject: [PATCH 3/5] expand tests --- heat/core/tests/test_arithmetics.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/heat/core/tests/test_arithmetics.py b/heat/core/tests/test_arithmetics.py index bea04faa2f..1037233e42 100644 --- a/heat/core/tests/test_arithmetics.py +++ b/heat/core/tests/test_arithmetics.py @@ -336,6 +336,10 @@ def test_diff(self): self.assertEqual(ht_diff.split, 1) self.assertEqual(ht_diff.dtype, ht_array.dtype) + # test n=0 + ht_diff = ht.diff(ht_array, n=0) + self.assertTrue(ht.equal(ht_diff, ht_array)) + # raises with self.assertRaises(ValueError): ht.diff(ht_array, n=-2) @@ -544,6 +548,11 @@ def test_pow(self): self.assertTrue(ht.equal(ht.pow(self.a_tensor, self.an_int_scalar), result)) self.assertTrue(ht.equal(ht.pow(self.a_split_tensor, self.a_tensor), commutated_result)) + # test scalar base and exponent + self.assertTrue(ht.equal(ht.pow(2, 3), ht.array(8))) + self.assertTrue(ht.equal(ht.pow(2, 3.5), ht.array(11.313708498984761))) + + # test exceptions with self.assertRaises(ValueError): ht.pow(self.a_tensor, self.another_vector) with self.assertRaises(TypeError): From 49dd699d782f5fb1d6112d43aabac156671f6df3 Mon Sep 17 00:00:00 2001 From: Claudia Comito <39374113+ClaudiaComito@users.noreply.github.com> Date: Mon, 24 Apr 2023 12:07:10 +0200 Subject: [PATCH 4/5] dummy commit to trigger CI --- heat/core/tests/test_arithmetics.py | 1 - 1 file changed, 1 deletion(-) diff --git a/heat/core/tests/test_arithmetics.py b/heat/core/tests/test_arithmetics.py index 1037233e42..fd81d26936 100644 --- a/heat/core/tests/test_arithmetics.py +++ b/heat/core/tests/test_arithmetics.py @@ -539,7 +539,6 @@ def test_pos(self): def test_pow(self): result = ht.array([[1.0, 4.0], [9.0, 16.0]]) commutated_result = ht.array([[2.0, 4.0], [8.0, 16.0]]) - self.assertTrue(ht.equal(ht.pow(self.a_scalar, self.a_scalar), ht.array(4.0))) self.assertTrue(ht.equal(ht.pow(self.a_tensor, self.a_scalar), result)) self.assertTrue(ht.equal(ht.pow(self.a_scalar, self.a_tensor), commutated_result)) From ed242bc5be773a9fff59339d231d0163ef9acd7e Mon Sep 17 00:00:00 2001 From: Michael Tarnawa Date: Mon, 24 Apr 2023 13:23:25 +0200 Subject: [PATCH 5/5] Update .gitlab-ci.yml --- .gitlab-ci.yml | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 591981b832..65dab87851 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -5,15 +5,16 @@ test: - x86_64 script: - apt update - - apt -y install build-essential python3-pip curl git - - "curl -X POST -H \"Accept: application/vnd.github+json\" -H \"Authorization: Bearer $GITHUB_TOKEN\" -H \"X-GitHub-Api-Version: 2022-11-28\" https://api.github.com/repos/helmholtz-analytics/heat/statuses/$CI_COMMIT_SHA -d '{\"state\":\"pending\",\"target_url\":\"https://codebase.helmholtz.cloud/haf/heat/-/jobs/$CI_JOB_ID\",\"description\":\"The build runs!\",\"context\":\"continuous-integration/codebase\"}'\n" + - apt -y install build-essential python3-pip curl git jo + - json=$(jo state="pending" target_url="https://codebase.helmholtz.cloud/haf/heat/-/jobs/$CI_JOB_ID" description="The build runs!" context="continuous-integration/codebase") + - "curl -o /dev/null -L -X POST -H \"Accept: application/vnd.github+json\" -H \"Authorization: Bearer $GITHUB_TOKEN\" -H \"X-GitHub-Api-Version: 2022-11-28\" https://api.github.com/repos/helmholtz-analytics/heat/statuses/$CI_COMMIT_SHA -d \"$json\" \n" - pip install pytest coverage - pip install .[hdf5,netcdf] - COVERAGE_FILE=report/cov/coverage1 HEAT_TEST_USE_DEVICE=cpu mpirun --allow-run-as-root -n 1 coverage run --source=heat --parallel-mode -m pytest --junitxml=report/test/report1.xml heat/ - COVERAGE_FILE=report/cov/coverage2 HEAT_TEST_USE_DEVICE=cpu mpirun --allow-run-as-root -n 2 coverage run --source=heat --parallel-mode -m pytest --junitxml=report/test/report2.xml heat/ - COVERAGE_FILE=report/cov/coverage3 HEAT_TEST_USE_DEVICE=gpu mpirun --allow-run-as-root -n 3 coverage run --source=heat --parallel-mode -m pytest --junitxml=report/test/report3.xml heat/ - COVERAGE_FILE=report/cov/coverage5 HEAT_TEST_USE_DEVICE=cpu mpirun --allow-run-as-root -n 5 coverage run --source=heat --parallel-mode -m pytest --junitxml=report/test/report5.xml heat/ - - COVERAGE_FILE=report/cov/coverage8 HEAT_TEST_USE_DEVICE=gpu mpirun --allow-run-as-root -n 6 coverage run --source=heat --parallel-mode -m pytest --junitxml=report/test/report6.xml heat/ + - COVERAGE_FILE=report/cov/coverage6 HEAT_TEST_USE_DEVICE=gpu mpirun --allow-run-as-root -n 6 coverage run --source=heat --parallel-mode -m pytest --junitxml=report/test/report6.xml heat/ - coverage combine report/cov/* - coverage report - coverage xml @@ -21,12 +22,20 @@ test: - chmod +x codecov - ./codecov -F unit -f ./coverage.xml -t $CODECOV_TOKEN -Z after_script: + - apt -y install jo - | case $CI_JOB_STATUS in - 'success') curl -X POST -H "Accept: application/vnd.github+json" -H "Authorization: Bearer $GITHUB_TOKEN" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/helmholtz-analytics/heat/statuses/$CI_COMMIT_SHA -d '{"state":"success","target_url":"https://codebase.helmholtz.cloud/haf/heat/-/jobs/$CI_JOB_ID","description":"The build succeeded!","context":"continuous-integration/codebase"}';; - 'failed') curl -X POST -H "Accept: application/vnd.github+json" -H "Authorization: Bearer $GITHUB_TOKEN" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/helmholtz-analytics/heat/statuses/$CI_COMMIT_SHA -d '{"state":"failure","target_url":"https://codebase.helmholtz.cloud/haf/heat/-/jobs/$CI_JOB_ID","description":"The build failed!","context":"continuous-integration/codebase"}';; - *) curl -X POST -H "Accept: application/vnd.github+json" -H "Authorization: Bearer $GITHUB_TOKEN" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/helmholtz-analytics/heat/statuses/$CI_COMMIT_SHA -d '{"state":"error","target_url":"https://codebase.helmholtz.cloud/haf/heat/-/jobs/$CI_JOB_ID","description":"The build errored!","context":"continuous-integration/codebase"}';; + 'success') + json=$(jo state="success" target_url="https://codebase.helmholtz.cloud/haf/heat/-/jobs/$CI_JOB_ID" description="The build succeeded!" context="continuous-integration/codebase") + ;; + 'failed') + json=$(jo state="failure" target_url="https://codebase.helmholtz.cloud/haf/heat/-/jobs/$CI_JOB_ID" description="The build failed!" context="continuous-integration/codebase") + ;; + *) + json=$(jo state="error" target_url="https://codebase.helmholtz.cloud/haf/heat/-/jobs/$CI_JOB_ID" description="The build errored!" context="continuous-integration/codebase") + ;; esac + curl -o /dev/null -L -X POST -H "Accept: application/vnd.github+json" -H "Authorization: Bearer $GITHUB_TOKEN" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/helmholtz-analytics/heat/statuses/$CI_COMMIT_SHA -d "$json" artifacts: when: always paths: