Enter - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

 Enter
 enter a GradientTape context
 Exit
 exit a GradientTape context

 Calling Sequence Enter( gt ) Exit( gt )

Parameters

 gt - a GradientTape object

Description

 • Enter(gt) enters the context of the GradientTape gt. All operations on watched Tensors or Variables from this point onwards will be recorded in gt for the purposes of computing derivatives.
 • Exit(gt) exits the context of the GradientTape gt. Recording of operations on watched Tensors or Variables ceases.
 Note: It is very important to remember to invoke Exit(gt) even when an error has occurred. A useful pattern is to invoke Enter within an try clause and include Exit in the associated finally clause to ensure it is always executed.

Details

 • The implementations of Enter and Exit use the similarly named methods from tf.GradientTape in the TensorFlow Python API. Consult the TensorFlow Python API documentation for tf.GradientTape for more information.

Examples

Create a GradientTape object, enter its context and compute gradients

 > $\mathrm{with}\left(\mathrm{DeepLearning}\right):$
 > $\mathrm{tape}≔\mathrm{GradientTape}\left(\right)$
 ${\mathrm{tape}}{≔}\left[\begin{array}{c}{\mathrm{DeepLearning GradientTape}}\\ {\mathrm{}}\end{array}\right]$ (1)
 > $\mathrm{Enter}\left(\mathrm{tape}\right)$
 $\left[\begin{array}{c}{\mathrm{DeepLearning GradientTape}}\\ {\mathrm{}}\end{array}\right]$ (2)
 > $x≔\mathrm{Constant}\left(\left[1.0,2.0\right]\right)$
 ${x}{≔}\left[\begin{array}{c}{\mathrm{DeepLearning Tensor}}\\ {\mathrm{Shape: \left[2\right]}}\\ {\mathrm{Data Type: float\left[4\right]}}\end{array}\right]$ (3)
 > $\mathrm{tape}:-\mathrm{Watch}\left(x\right)$
 > $y≔{x}^{2}$
 ${y}{≔}\left[\begin{array}{c}{\mathrm{DeepLearning Tensor}}\\ {\mathrm{Shape: \left[2\right]}}\\ {\mathrm{Data Type: float\left[4\right]}}\end{array}\right]$ (4)
 > $J≔\mathrm{tape}:-\mathrm{Jacobian}\left(y,x\right)$
 ${J}{≔}\left[\begin{array}{c}{\mathrm{DeepLearning Tensor}}\\ {\mathrm{Shape: \left[2, 2\right]}}\\ {\mathrm{Data Type: float\left[4\right]}}\end{array}\right]$ (5)
 > $\mathrm{Exit}\left(\mathrm{tape}\right)$
 > $\mathrm{convert}\left(J,\mathrm{Matrix}\right)$
 $\left[\begin{array}{cc}{2.}& {0.}\\ {0.}& {4.}\end{array}\right]$ (6)

Compatibility

 • The DeepLearning[GradientTape][Enter] and DeepLearning[GradientTape][Exit] commands were introduced in Maple 2022.
 • For more information on Maple 2022 changes, see Updates in Maple 2022.