Skip to content

Commit 1726ba4

Browse files
committed
docstring cleanup
1 parent f6f612f commit 1726ba4

File tree

7 files changed

+35
-44
lines changed

7 files changed

+35
-44
lines changed

src/isotropic/e2.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""This module contains functions for generating the vector e_2."""
1+
"""This module contains functions for generating the vector $e_2$."""
22

33
from typing import Callable, Tuple
44

@@ -13,7 +13,7 @@
1313

1414
def F_j(theta_j: float, j: int, d: int) -> Array:
1515
"""
16-
Calculate the function F_j for the given angle theta_j and index j in dimension d.
16+
Calculate the function $F_j$ for the given angle $\\theta_j$ and index $j$ in dimension $d$.
1717
1818
Parameters
1919
----------
@@ -27,7 +27,7 @@ def F_j(theta_j: float, j: int, d: int) -> Array:
2727
Returns
2828
-------
2929
Array
30-
The value of the function F_j evaluated at theta_j.
30+
The value of the function $F_j$ evaluated at $\\theta_j$.
3131
"""
3232
dj = d - j
3333
numoverden = double_factorial_ratio_scipy(dj - 2, dj - 1)
@@ -84,23 +84,24 @@ def get_e2_coeffs(
8484
d: int, F_j: Callable, key: ArrayLike = random.PRNGKey(0)
8585
) -> Tuple[Array, Array]:
8686
"""
87-
Generate the vector e_2 in R^d.
87+
Generate the coefficients of the vector $e_2$.
8888
8989
Parameters
9090
----------
9191
d : int
9292
Dimension of the space.
9393
F_j : Callable
94-
Function to compute F_j for the given angle, dimension and index.
94+
Function to compute $F_j$ for the given angle, dimension and index.
9595
key : ArrayLike, optional
9696
Random key for reproducibility, by default random.PRNGKey(0).
9797
9898
Returns
9999
-------
100100
Tuple[Array, Array]
101101
A tuple containing:
102-
- theta: Array of angles used to construct e_2.
103-
- e2: Array representing the vector e_2 in R^d.
102+
103+
- theta: Array of angles used to construct $e_2$.
104+
- e2: Array representing the coefficients of the vector $e_2$.
104105
"""
105106
theta: Array = jnp.zeros(d - 1)
106107

src/isotropic/orthonormal.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99

1010
def get_orthonormal_basis(Phi: ArrayLike) -> Array:
1111
"""
12-
Construct an orthonormal basis given a point Φ on a unit sphere.
12+
Construct an orthonormal basis given a point $\\Phi$ on a unit sphere.
1313
14-
The point Φ is given by a d+1 dimensional vector and the orthonormal basis consists of d vectors
15-
each of dimension d+1, which are orthogonal to Φ and to each other.
14+
The point $\\Phi$ is given by a d+1 dimensional vector and the orthonormal basis consists of d vectors
15+
each of dimension d+1, which are orthogonal to $\\Phi$ and to each other.
1616
1717
Parameters
1818
----------

src/isotropic/thetazero.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,22 @@
1212

1313
def get_theta_zero(x: ArrayLike, g: Callable) -> float:
1414
"""
15-
Calculate the inverse angle theta_0 with a normal distribution given a value x.
15+
Calculate the inverse angle $\\theta_0$ with a normal distribution given a value x.
1616
17-
This function finds the angle theta_0 such that the integral of g from 0 to theta_0 equals x.
17+
This function finds the angle $\\theta_0$ such that the integral of g from 0 to $\\theta_0$ equals x.
1818
It uses Simpson's rule for numerical integration and a bisection method to find the root.
1919
2020
Parameters
2121
----------
2222
x : ArrayLike
23-
Value for which to find the inverse, should be uniformly distributed in [0, 1].
23+
Value for which to find the inverse, should be uniformly distributed in $[0, 1]$.
2424
g : Callable
25-
Function g(theta) that is integrated to calculate F(theta).
25+
Function $g(\\theta)$ that is integrated to calculate $F(\\theta)$.
2626
2727
Returns
2828
-------
2929
float
30-
Value of theta_0.
30+
Value of $\\theta_0$.
3131
"""
3232

3333
# We wrap the function g into a callable F that integrates g from 0 to theta.

src/isotropic/utils/bisection.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""This module contains functions for the bisection algorithm to calculate F inverse"""
1+
"""This module contains functions for the bisection algorithm to calculate $F^{-1}$"""
22

33
from typing import Callable
44

@@ -9,23 +9,13 @@ def get_theta(
99
F: Callable, a: float, b: float, x: float | ArrayLike, eps: float
1010
) -> float:
1111
"""
12-
Finds the value of theta such that F(theta) = x using the bisection method.
13-
This function assumes that F is an increasing function in the interval [a, b]
14-
and that F(a) x F(b).
12+
Finds the value of theta such that $F(\\theta) = x$ using the bisection method.
13+
This function assumes that $F$ is an increasing function in the interval $[a, b]$
14+
and that $F(a) \\leq x \\leq F(b)$.
1515
1616
The bisection method is a root-finding method that repeatedly bisects an interval
1717
and then selects a subinterval in which a root exists.
1818
19-
Bisection algorithm:
20-
Input: Function F increasing in the interval [a, b], a value x such that
21-
F(a) ≤ x ≤ F(b) and the error bound ε.
22-
Output: Value of theta such that |theta - theta^*| < ε where theta^* is the solution
23-
(F(theta^*) = x).
24-
1. Step 1: Calculate the midpoint of the interval c = a + b.
25-
2. Step 2: If F(c)≤ x, update a=c and if F(c)>x update b=c.
26-
5. Step 3: If b-a<ε, return theta_0 =c, and finish.
27-
6. Step 4: Repeat the process again.
28-
2919
Parameters
3020
----------
3121
F : Callable
@@ -42,7 +32,7 @@ def get_theta(
4232
Returns
4333
-------
4434
float
45-
The value of theta such that F(theta) = x.
35+
The value of $theta$ such that $F(\\theta) = x$.
4636
"""
4737
while b - a > eps:
4838
c = (a + b) / 2.0

src/isotropic/utils/distribution.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def double_factorial_ratio_jax(num: int, den: int) -> Array:
7777
7878
Notes
7979
-----
80-
For very large numbers, this is numerically stable only when |num - den| is ~5.
80+
For very large numbers, this is numerically stable only when |num - den| ~5.
8181
"""
8282
warnings.warn(
8383
"This is an experimental implementation. There are known issues with using this for numbers larger than 2**8",
@@ -115,7 +115,7 @@ def normal_integrand(theta: float, d: int, sigma: float) -> Array:
115115
Computes the function g(θ) that is integrated to calculate F(θ) which is the
116116
distribution function for the angle θ in a normal distribution:
117117
118-
g(θ) = [(d-1)!! * (1-σ²) * sin^(d-1)(θ)] / [π * (d-2)!! * (1+σ²-2σcos(θ))^((d+1)/2)]
118+
$$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}}$$
119119
120120
Parameters
121121
----------

src/isotropic/utils/linalg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
def jax_null_space(A: ArrayLike) -> Array:
88
"""
9-
Compute the null space of a matrix A using JAX.
9+
Compute the null space of a matrix $A$ using JAX.
1010
1111
Parameters
1212
----------

src/isotropic/utils/state_transforms.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@
1515

1616
def statevector_to_hypersphere(Phi: Array) -> Array:
1717
"""
18-
Generate the hypersphere Phi from statevector Psi
18+
Generate the hypersphere from statevector $\\Phi$
1919
2020
Parameters
2121
----------
22-
psi: ArrayLike
23-
statevector as a complex JAX array of dimension 2^n, for n-qubits
22+
Phi: ArrayLike
23+
statevector as a complex JAX array of dimension $2^n$, for n-qubits
2424
2525
Returns
2626
-------
2727
Array
28-
hypersphere as a real JAX array of dimension 2^{n+1}
28+
hypersphere as a real JAX array of dimension $2^{n+1}$
2929
"""
3030
S = jnp.zeros(int(2 ** (log(Phi.shape[0], 2) + 1)), dtype=float)
3131
for x in range(S.shape[0] // 2):
@@ -36,17 +36,17 @@ def statevector_to_hypersphere(Phi: Array) -> Array:
3636

3737
def hypersphere_to_statevector(S: Array) -> Array:
3838
"""
39-
Generate the statevector Psi from hypersphere Phi
39+
Generate the statevector $\\Phi$ from hypersphere $S$
4040
4141
Parameters
4242
----------
4343
S: ArrayLike
44-
hypersphere as a real JAX array of dimension 2^{n+1} for n qubits
44+
hypersphere as a real JAX array of dimension $2^{n+1}$ for n qubits
4545
4646
Returns
4747
-------
4848
Array
49-
statevector as a complex JAX array of dimension 2^n
49+
statevector as a complex JAX array of dimension $2^n$
5050
"""
5151
Phi = jnp.zeros(int(2 ** (log(S.shape[0], 2) - 1)), dtype=complex)
5252
for x in range(Phi.shape[0]):
@@ -56,16 +56,16 @@ def hypersphere_to_statevector(S: Array) -> Array:
5656

5757
def add_isotropic_error(Phi_sp: Array, e2: Array, theta_zero: float) -> Array:
5858
"""
59-
Add isotropic error to state Phi given e2 and theta_zero
59+
Add isotropic error to state $\\Phi$ given $e_2$ and $\\theta_0$
6060
6161
Parameters
6262
----------
6363
Phi_sp : ArrayLike
6464
state to which isotropic error is added (in spherical form)
6565
e2 : ArrayLike
66-
vector e2 in S_{d-1} with uniform distribution
66+
vector $e_2$ in $S_{d-1}$ with uniform distribution
6767
theta_zero : float
68-
angle θ_0 in [0,π] with density function f(θ_0)
68+
angle $\\theta_0$ in $[0,\\pi]$ with density function $f(\\theta_0)$
6969
7070
Returns
7171
-------
@@ -87,7 +87,7 @@ def generate_and_add_isotropic_error(
8787
Parameters
8888
----------
8989
Phi : ArrayLike
90-
The input statevector as a complex JAX array of dimension 2^n, for n-qubits.
90+
The input statevector as a complex JAX array of dimension $2^n$, for n-qubits.
9191
sigma : float, optional
9292
The standard deviation for the isotropic error, by default 0.9.
9393
key : ArrayLike, optional

0 commit comments

Comments
 (0)