From e5718c02e1eaee1c56358846eed43b09806784d9 Mon Sep 17 00:00:00 2001 From: Kirill Pushkarev <71515921+kirill-push@users.noreply.github.com> Date: Wed, 18 Oct 2023 15:25:57 +0000 Subject: [PATCH 1/6] fixes #1835 --- covalent/_workflow/electron.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/covalent/_workflow/electron.py b/covalent/_workflow/electron.py index cfe45f485..854fb1248 100644 --- a/covalent/_workflow/electron.py +++ b/covalent/_workflow/electron.py @@ -154,6 +154,7 @@ def get_op_function( "-": operator.sub, "*": operator.mul, "/": operator.truediv, + "**": operator.pow, } def rename(op1: Any, op: str, op2: Any) -> Callable: @@ -242,6 +243,9 @@ def __truediv__(self, other): def __rtruediv__(self, other): return self.get_op_function(other, self, "/") + def __pow__(self, other): + return self.get_op_function(self, other, "**") + def __int__(self): return int() From 53c4d5ed5b72f1f7de2bb28dcb4c81e0a31b1454 Mon Sep 17 00:00:00 2001 From: Kirill Pushkarev <71515921+kirill-push@users.noreply.github.com> Date: Wed, 18 Oct 2023 15:55:51 +0000 Subject: [PATCH 2/6] Add Electron __pow__ method --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 323c3a90f..55132ffdb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Documentation and test cases for database triggers. +- Added the `__pow__` method to the `Electron` class ### Docs From 20f8e92a92073ce8090db6c0341a4e2e2cb4e3b8 Mon Sep 17 00:00:00 2001 From: Kirill Pushkarev <71515921+kirill-push@users.noreply.github.com> Date: Wed, 18 Oct 2023 16:27:55 +0000 Subject: [PATCH 3/6] add tests to Electron __pow__ method --- .../covalent_tests/workflow/electron_test.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/covalent_tests/workflow/electron_test.py b/tests/covalent_tests/workflow/electron_test.py index 00d79ab61..d287cd93e 100644 --- a/tests/covalent_tests/workflow/electron_test.py +++ b/tests/covalent_tests/workflow/electron_test.py @@ -643,3 +643,22 @@ def workflow(x): assert ( workflow.transport_graph.get_node_value(0, "status") == RESULT_STATUS.PENDING_REPLACEMENT ) + + +def test_electron_pow_method(): + electron = Electron(function=None) + assert hasattr(electron, "__pow__") + + +def test_workflow(): + @ct.electron + def g(x): + return 42 * x + + @ct.lattice + def workflow(x): + res = g(x) + return res**2 + + result = workflow(2) + assert result == 7056 # Expected result for (42 * 2) ** 2 From 8b67cbbcff2f2cbb5720e15a995bac7f72ed595c Mon Sep 17 00:00:00 2001 From: Kirill Pushkarev <71515921+kirill-push@users.noreply.github.com> Date: Thu, 19 Oct 2023 12:16:09 +0000 Subject: [PATCH 4/6] current version of test_electron_pow_method --- tests/covalent_tests/workflow/electron_test.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/tests/covalent_tests/workflow/electron_test.py b/tests/covalent_tests/workflow/electron_test.py index d287cd93e..b96a076f6 100644 --- a/tests/covalent_tests/workflow/electron_test.py +++ b/tests/covalent_tests/workflow/electron_test.py @@ -645,12 +645,14 @@ def workflow(x): ) -def test_electron_pow_method(): - electron = Electron(function=None) - assert hasattr(electron, "__pow__") - +def test_electron_pow_method(mocker): + mock_electron_get_op_function = mocker.patch.object( + Electron, "get_op_function", return_value=Electron + ) + # mock_electron_pow = mocker.patch.object( + # Electron, "__pow__", return_value=Electron + # ) -def test_workflow(): @ct.electron def g(x): return 42 * x @@ -660,5 +662,7 @@ def workflow(x): res = g(x) return res**2 - result = workflow(2) - assert result == 7056 # Expected result for (42 * 2) ** 2 + workflow.build_graph(2) + + mock_electron_get_op_function.assert_called_once() + # mock_electron_pow.assert_called_once() From 59ce1ee9a55cac77c14fd14aea618adf38d2a959 Mon Sep 17 00:00:00 2001 From: Kirill Pushkarev <71515921+kirill-push@users.noreply.github.com> Date: Thu, 19 Oct 2023 18:41:46 +0000 Subject: [PATCH 5/6] fixing test_electron_pow after a change request --- tests/covalent_tests/workflow/electron_test.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/tests/covalent_tests/workflow/electron_test.py b/tests/covalent_tests/workflow/electron_test.py index b96a076f6..70cdc84d6 100644 --- a/tests/covalent_tests/workflow/electron_test.py +++ b/tests/covalent_tests/workflow/electron_test.py @@ -17,7 +17,7 @@ """Unit tests for electron""" import json -from unittest.mock import MagicMock +from unittest.mock import ANY, MagicMock import pytest @@ -649,9 +649,6 @@ def test_electron_pow_method(mocker): mock_electron_get_op_function = mocker.patch.object( Electron, "get_op_function", return_value=Electron ) - # mock_electron_pow = mocker.patch.object( - # Electron, "__pow__", return_value=Electron - # ) @ct.electron def g(x): @@ -664,5 +661,4 @@ def workflow(x): workflow.build_graph(2) - mock_electron_get_op_function.assert_called_once() - # mock_electron_pow.assert_called_once() + mock_electron_get_op_function.assert_called_with(ANY, 2, "**") From 3853946c320beb713ae177b44be77a63939b25bf Mon Sep 17 00:00:00 2001 From: Kirill Pushkarev <71515921+kirill-push@users.noreply.github.com> Date: Thu, 19 Oct 2023 20:02:15 +0000 Subject: [PATCH 6/6] Empty commit