Comments (3)
I think that's right. It basically comes down to what we think the semantics of the three operations are. The solution above works if we think the semantics are:
pause_anotation()
- unconditionally switch off annotation.
continue_annotation()
- unconditionally switch on annotation.
stop_annotation()
- cease annotation inside the context manager and return to the previous annotation state afterwards.
I confess that that doesn't quite line up with the names "pause" and "continue", but I think that that's how those functions are actually used. I also don't think there is a sane way of having "pause" and "continue" have state. I think the current mess probably results from an attempt to have them do so.
As an aside, even this isn't really safe in the context of multiple tapes, but I think that is something which should be fixed elsewhere (basically, the annotation state should be stored on the tape and switching tapes should have the corresponding effect on the annotation state).
from pyadjoint.
This isn't my code, but I think that what is going on here is an attempt to make the following code work correctly:
from pyadjoint.tape import continue_annotation, annotate_tape, stop_annotating
pause_annotation()
with stop_annotating():
pass
assert not annotate_tape() # raises an error
This explains why a plain boolean isn't sufficient. However, what is currently being done is abusing an integer as an incorrectly implemented stack. It would be better to have an actual stack. The easiest way to implement this would probably be to have the stop_annotation
context manager keep the state of annotation before it executes and restore that.
from pyadjoint.
This explains why a plain boolean isn't sufficient. However, what is currently being done is abusing an integer as an incorrectly implemented stack. It would be better to have an actual stack. The easiest way to implement this would probably be to have the
stop_annotation
context manager keep the state of annotation before it executes and restore that.
I can see how something like
class stop_annotating:
def __enter__(self):
global _annotation_enabled
_annotation_enabled = False
def __exit__(self, *args):
global _annotation_enabled
_annotation_enabled = True # not always the right thing to do
would be wrong. Are you suggesting instead that everything would work if we had something like
class stop_annotating:
def __enter__(self):
global _annotation_enabled
self._orig_annotation_enabled = _annotation_enabled
_annotation_enabled = False
def __exit__(self, *args):
global _annotation_enabled
_annotation_enabled = self._orig_annotation_enabled
I just want to be clear that when you say "have an actual stack" you don't mean to use a list or similar to pop and push from. The state awareness of the context manager is sufficient.
from pyadjoint.
Related Issues (20)
- Adjoint variables kept around longer than necessary
- Ipopt import error on pyadjoint:latest docker image
- No graph is built for visualization HOT 2
- RuntimeError with ROL solver HOT 1
- Support for taping non-scalar outputs: ReducedFunction HOT 1
- Typo: Overoaded -> Overloaded
- optimization problem by use IPOPTSolver,the range of guessed value is very close to the target value.
- Remove FEniCS tests and add regression tests on cricleci
- Error when running heat-equation.py example
- Create PYPI package HOT 4
- Import Error in: from pyadjoint import ipopt # noqa: F401 in examples/poisson-topology.py HOT 1
- Wrong recomputation results with delegated checkpoints HOT 1
- Bound constraint possibly incorrect for higher order discretization
- `derivative_options` argument to `minimize` is likely incorrect HOT 2
- Pyadjoint uses np.float_ which was removed in numpy 2
- pyadjoint version was not updated in __init__.py after the 2023.0.0 release
- `ReducedFunctional` should provide dual space derivatives
- Add `_ad_new` and `_ad_new_dual` methods to `OverloadedType`
- `minimize_scipy_generic` does not check for success
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyadjoint.