utils
This module contains miscellaneous utilities useful for various steps involved in the isotropic error generation.
isotropic.utils
bisection
This module contains functions for the bisection algorithm to calculate $F^{-1}$
get_theta(F, a, b, x, eps)
Finds the value of theta such that $F(\theta) = x$ using the bisection method. This function assumes that $F$ is an increasing function in the interval $[a, b]$ and that $F(a) \leq x \leq F(b)$.
The bisection method is a root-finding method that repeatedly bisects an interval and then selects a subinterval in which a root exists.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
F
|
Callable
|
Function for which to compute the inverse. |
required |
a
|
float
|
Lower bound of the interval. |
required |
b
|
float
|
Upper bound of the interval. |
required |
x
|
float | ArrayLike
|
Value for which to find the inverse. |
required |
eps
|
float
|
Tolerance for convergence. |
required |
Returns:
Type | Description |
---|---|
float
|
The value of $theta$ such that $F(\theta) = x$. |
Source code in src/isotropic/utils/bisection.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
|
distribution
This module contains functions for relevant probability distributions
double_factorial_jax(n)
Helper function to compute double factorial:
n!! = n * (n-2) * (n-4) * ... * 1 (if n is odd) or 2 (if n is even).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n
|
int
|
The integer for which to compute the double factorial. |
required |
Returns:
Type | Description |
---|---|
Array
|
The value of the double factorial n!! |
Source code in src/isotropic/utils/distribution.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
|
double_factorial_ratio_jax(num, den)
Computes the ratio of double factorials:
num!! / den!!
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num
|
int
|
The numerator for the double factorial. |
required |
den
|
int
|
The denominator for the double factorial. |
required |
Returns:
Type | Description |
---|---|
Array
|
The value of the ratio num!! / den!! |
Notes
For very large numbers, this is numerically stable only when |num - den| ~5.
Source code in src/isotropic/utils/distribution.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
|
double_factorial_ratio_scipy(num, den)
Compute the ratio of double factorials num!! / den!!.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num
|
int
|
The numerator double factorial. |
required |
den
|
int
|
The denominator double factorial. |
required |
Returns:
Type | Description |
---|---|
float
|
The ratio of the double factorials. |
Notes
This only works for numbers up to 300.
Raises:
Type | Description |
---|---|
ValueError
|
If num or den is greater than 300. |
Source code in src/isotropic/utils/distribution.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
|
normal_integrand(theta, d, sigma)
Computes the function g(θ) that is integrated to calculate F(θ) which is the distribution function for the angle θ in a normal distribution:
$$g(\theta) = \frac{(d-1)!! \times (1-\sigma^2) \times \sin^{d-1}(\theta)}{\pi \times (d-2)!! \times (1+\sigma^2-2\sigma\cos(\theta))^{(d+1)/2}}$$
Parameters:
Name | Type | Description | Default |
---|---|---|---|
theta
|
float
|
Angle parameter(s). |
required |
d
|
int
|
Dimension parameter. |
required |
sigma
|
float
|
Sigma parameter (should be in valid range). |
required |
Returns:
Type | Description |
---|---|
Array
|
Value(s) of the function evaluated at |
Source code in src/isotropic/utils/distribution.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
|
linalg
jax_null_space(A)
Compute the null space of a matrix $A$ using JAX.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
A
|
ArrayLike
|
The input matrix for which to compute the null space. |
required |
Returns:
Type | Description |
---|---|
Array
|
The basis vectors of the null space of A. |
Notes
See also:
scipy.linalg.null_space
for the reference implementation in SciPy.- https://github.com/jax-ml/jax/pull/14486 for an old JAX implementation.
Source code in src/isotropic/utils/linalg.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
|
simpsons
This module contains functions for estimating the integral of a function using Simpson's rule.
simpsons_rule(f, a, b, C, tol)
Estimates the integral of a function using Simpson's rule.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
f
|
Callable
|
Function to integrate. |
required |
a
|
float
|
Lower limit of integration. |
required |
b
|
float
|
Upper limit of integration. |
required |
C
|
float
|
Bound on 4th derivative of f. |
required |
tol
|
float
|
Desired tolerance for the integral estimate. |
required |
Returns:
Type | Description |
---|---|
Array
|
Estimated value of the integral. |
Source code in src/isotropic/utils/simpsons.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
|
state_transforms
This module contains functions for transforming the quantum state
add_isotropic_error(Phi_sp, e2, theta_zero)
Add isotropic error to state $\Phi$ given $e_2$ and $\theta_0$
Parameters:
Name | Type | Description | Default |
---|---|---|---|
Phi_sp
|
ArrayLike
|
state to which isotropic error is added (in spherical form) |
required |
e2
|
ArrayLike
|
vector $e_2$ in $S_{d-1}$ with uniform distribution |
required |
theta_zero
|
float
|
angle $\theta_0$ in $[0,\pi]$ with density function $f(\theta_0)$ |
required |
Returns:
Type | Description |
---|---|
Array
|
statevector in spherical form after adding isotropic error |
Source code in src/isotropic/utils/state_transforms.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
|
generate_and_add_isotropic_error(Phi, sigma=0.9, key=random.PRNGKey(0))
Generate and add isotropic error to a given statevector.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
Phi
|
ArrayLike
|
The input statevector as a complex JAX array of dimension $2^n$, for n-qubits. |
required |
sigma
|
float
|
The standard deviation for the isotropic error, by default 0.9. |
0.9
|
key
|
ArrayLike
|
Random key for reproducibility, by default random.PRNGKey(0). |
PRNGKey(0)
|
Returns:
Type | Description |
---|---|
Array
|
The perturbed statevector after adding isotropic error. |
Source code in src/isotropic/utils/state_transforms.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
|
hypersphere_to_statevector(S)
Generate the statevector $\Phi$ from hypersphere $S$
Parameters:
Name | Type | Description | Default |
---|---|---|---|
S
|
Array
|
hypersphere as a real JAX array of dimension $2^{n+1}$ for n qubits |
required |
Returns:
Type | Description |
---|---|
Array
|
statevector as a complex JAX array of dimension $2^n$ |
Source code in src/isotropic/utils/state_transforms.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
|
statevector_to_hypersphere(Phi)
Generate the hypersphere from statevector $\Phi$
Parameters:
Name | Type | Description | Default |
---|---|---|---|
Phi
|
Array
|
statevector as a complex JAX array of dimension $2^n$, for n-qubits |
required |
Returns:
Type | Description |
---|---|
Array
|
hypersphere as a real JAX array of dimension $2^{n+1}$ |
Source code in src/isotropic/utils/state_transforms.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
|