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

fixes #1835 #1837

Merged
merged 7 commits into from
Oct 19, 2023
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,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

Expand Down
4 changes: 4 additions & 0 deletions covalent/_workflow/electron.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ def get_op_function(
"-": operator.sub,
"*": operator.mul,
"/": operator.truediv,
"**": operator.pow,
}

def rename(op1: Any, op: str, op2: Any) -> Callable:
Expand Down Expand Up @@ -243,6 +244,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()

Expand Down
21 changes: 20 additions & 1 deletion tests/covalent_tests/workflow/electron_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"""Unit tests for electron"""

import json
from unittest.mock import MagicMock
from unittest.mock import ANY, MagicMock

import pytest

Expand Down Expand Up @@ -655,3 +655,22 @@ def workflow(x):
assert (
workflow.transport_graph.get_node_value(0, "status") == RESULT_STATUS.PENDING_REPLACEMENT
)


def test_electron_pow_method(mocker):
mock_electron_get_op_function = mocker.patch.object(
Electron, "get_op_function", return_value=Electron
)

@ct.electron
def g(x):
return 42 * x

@ct.lattice
def workflow(x):
res = g(x)
return res**2

workflow.build_graph(2)

mock_electron_get_op_function.assert_called_with(ANY, 2, "**")
Loading