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

  1. https://github.com/HIPS/autograd/blob/master/docs/tutorial.md
  2. 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 2-dim matrix UnitaryMat.u2_alt. UnitaryMat.u2_alt is an alternative to OneQubitGate.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 vector-jacobian-product) 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 vector-jacobian-product) 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.sig_all()[source]

This method returns a numpy array of shape=(2, 3, 3) which contains the 3 Pauli matrices in it. sigx = sig_all[:, :, 0], sigy = sig_all[:, :, 1], sigz = sig_all[:, :, 2],

Returns:shape = (2, 2, 3)
Return type:np.ndarray
qubiter.adv_applications.setup_autograd.u2_alt(*tlist)[source]

An alternative to OneQubitGate.u2(). Both should return identical 2-dim matrices for identical arguments.

Parameters:tlist (list[float]) – tlist = [rads0, rads1, rads2, rads3]
Returns:shape = (2, 2)
Return type:np.ndarray