Skip to content

Commit

Permalink
TST: add a test demonstrating perturbation confusion handling. (#688)
Browse files Browse the repository at this point in the history
Co-authored-by: JHM Darbyshire (win11) <[email protected]>
  • Loading branch information
attack68 and attack68 authored Feb 20, 2025
1 parent 37de223 commit 4cb060b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ dev = [
"mypy>=1.13,<2.0",
"pandas-stubs>2.0,<3.0",
# doc building
"sphinx>=8.0,<9.0",
"sphinx>=8.0,<8.2",
"sphinx-automodapi>=0.16.0,<1.0",
"sphinxcontrib-googleanalytics>=0.4,<1.0",
"sphinx-tabs>=3.4,<4.0",
Expand Down
16 changes: 16 additions & 0 deletions python/tests/test_dual.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,22 @@ def test_variable_set_order() -> None:
assert isinstance(x_dual2, Dual2)


def test_perturbation_confusion() -> None:
# https://www.bcl.hamilton.ie/~barak/papers/ifl2005.pdf

# Utilised tagged variables
x = Dual(1.0, ["x"], [])
y = Dual(1.0, ["y"], [])
result = gradient(x * gradient(x + y, ["y"]), ["x"])
assert result == 1.0

# Replicates untagged variables
x = Dual(1.0, ["x"], [])
y = Dual(1.0, ["x"], [])
result = gradient(x * gradient(x + y, ["x"]), ["x"])
assert result == 2.0


# Linalg dual_solve tests


Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pytest>=8.3.2,<9.0
coverage>=7.6.1,<8.0 # for test and code monitoring

# doc building
sphinx>=8.0,<9.0
sphinx>=8.0,<8.2
sphinx-automodapi>=0.16.0,<1.0
sphinxcontrib-googleanalytics>=0.4,<1.0
sphinx-tabs>=3.4,<4.0
Expand Down

0 comments on commit 4cb060b

Please sign in to comment.