qubiter.adv_applications.setup_autograd module¶
The purpose of this file is to install autograd and its dependencies and to provide utility functions that are used when it is used in conjunction with Qubiter.
When using autograd, one declares np to be the alias to module numpy.autograd. If another file later declares np to be alias to numpy, all sorts of error messages start cropping up. What I’ve done to avoid this is to change the statements import numpy as np in some (not all, just the ones called while using autograd) files by
import sys if ‘autograd.numpy’ not in sys.modules:
import numpy as np
 else:
 import autograd.numpy as np
References
 https://github.com/HIPS/autograd/blob/master/docs/tutorial.md
 https://github.com/HIPS/autograd/blob/master/docs/updateguide.md

qubiter.adv_applications.setup_autograd.
d_auto_pu2
(dwrt, *tlist)[source]¶ Returns the automatic derivative of pu2. We have defined things so that this derivative is stipulated analytically a priori rather than being calculated by autograd from def of u2.
Parameters:  dwrt (int) – stands for ‘derivative with respect to’. int in range(4)
 tlist (list[float]) – len = 4
Returns: shape=(2,2)
Return type: np.ndarray

qubiter.adv_applications.setup_autograd.
d_auto_u2
(dwrt, *tlist)[source]¶ Returns the automatic (computed by backprop) derivative of 2dim matrix UnitaryMat.u2_alt. UnitaryMat.u2_alt is an alternative to OneBitGates.u2. Both functions return same answer for identical input ( input is 4 real parameters in tlist).
Parameters:  dwrt (int) – stands for ‘derivative with respect to’. int in range(4)
 tlist (list[float]) – len = 4
Returns: shape=(2,2)
Return type: np.ndarray

qubiter.adv_applications.setup_autograd.
d_u2
(dwrt, *tlist)[source]¶ tlist is a list of 4 floats, and dwrt (which stands for “derivative with respect to”) is in range(4). This method returns the analytical (not numerical, in terms of closed functions) derivative of u2(*tlist) with respect to tlist[dwrt].
The output of this method has been verified by comparing it to same derivatives calculated numerically with autograd.
Parameters:  dwrt (int) –
 tlist (list[float]) –
Returns: shape = (2, 2)
Return type: np.ndarray

qubiter.adv_applications.setup_autograd.
pu2
(*tlist)[source]¶ Returns primitive u2 as (primitive real part of u2) + j*(primtive imaginary part of u2).
Parameters: tlist (list[float]) – len = 4 Returns: shape=(2,2) Return type: np.ndarray

qubiter.adv_applications.setup_autograd.
pu2i
(*tlist)[source]¶ Returns imaginary part of u2, and registers it as being primitive.
Primitive means that its derivative will be provided in a defvjp ( def of vectorjacobianproduct) so no need for autograd to calculate it from the u2 definition.
Parameters: tlist (list[float]) – len = 4 Returns: shape=(2,2) Return type: np.ndarray

qubiter.adv_applications.setup_autograd.
pu2r
(*tlist)[source]¶ Returns real part of u2, and registers it as being primitive.
Primitive means that its derivative will be provided in a defvjp ( def of vectorjacobianproduct) so no need for autograd to calculate it from the u2 definition.
Parameters: tlist (list[float]) – len = 4 Returns: shape=(2,2) Return type: np.ndarray