From 829c49c70be77ce36c8a197aa1111cdc6f6fcdd4 Mon Sep 17 00:00:00 2001 From: David Ham Date: Fri, 5 Jan 2024 10:57:35 +0000 Subject: [PATCH] Adjfloat block variables to print saved values. --- pyadjoint/adjfloat.py | 4 ++++ pyadjoint/block_variable.py | 2 +- pyadjoint/overloaded_type.py | 12 ++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/pyadjoint/adjfloat.py b/pyadjoint/adjfloat.py index fa639918..48ae57ba 100644 --- a/pyadjoint/adjfloat.py +++ b/pyadjoint/adjfloat.py @@ -123,6 +123,10 @@ def _ad_to_list(value): def _ad_copy(self): return self + @property + def _ad_str(self): + """Return the string of the taped value of this variable.""" + return str(self.block_variable.saved_output) _min = min _max = max diff --git a/pyadjoint/block_variable.py b/pyadjoint/block_variable.py index 86002638..d619be2d 100644 --- a/pyadjoint/block_variable.py +++ b/pyadjoint/block_variable.py @@ -68,7 +68,7 @@ def will_add_as_output(self): self.save_output(overwrite=overwrite) def __str__(self): - return str(self.output) + return str(self.output._ad_str) @property def checkpoint(self): diff --git a/pyadjoint/overloaded_type.py b/pyadjoint/overloaded_type.py index 1d286aee..a6a02f68 100644 --- a/pyadjoint/overloaded_type.py +++ b/pyadjoint/overloaded_type.py @@ -308,6 +308,18 @@ def _ad_dim(self): """ raise NotImplementedError + def _ad_str(self): + """Return the string representation of the block variable. + + For simple scalar types this might be the string representation of the + stored value. For more complex objects it is likely to be based on a + name attached to this instance. + + Returns: + str: A human readable serialisation of this variable. + """ + return str(self) + class FloatingType(OverloadedType): def __init__(self, *args, **kwargs):