-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c18ff5
commit 8d6a78e
Showing
4 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
"""Generate random orthonormal basis.""" | ||
import numpy as np | ||
|
||
from toqito.matrix_props import is_orthonormal | ||
from toqito.rand import random_unitary | ||
|
||
|
||
def random_orthonormal_basis(dim: int) -> list[np.ndarray]: | ||
r"""Generate a real random orthonormal basis of given dimension $d$. | ||
The basis is generated from the columns of a random unitary matrix of the same dimension | ||
as the columns of a unitary matrix typically form an orthonormal basis :cite:`SE_1688950`. | ||
Examples | ||
========== | ||
To generate a random orthonormal basis of dimension 4, | ||
>>> from toqito.rand import random_orthonormal_basis | ||
>>> random_orthonormal_basis(4) # doctest: +SKIP | ||
[array([0.52188745, 0.4983613 , 0.69049811, 0.04981832]), | ||
array([-0.48670459, 0.58756912, -0.10226756, 0.63829658]), | ||
array([ 0.23965404, -0.58538248, 0.187136 , 0.75158061]), | ||
array([ 0.658269 , 0.25243989, -0.69118291, 0.158815 ])] | ||
References | ||
========== | ||
.. bibliography:: | ||
:filter: docname in docnames | ||
dim: int | ||
Number of elements in the random orthonormal basis. | ||
""" | ||
random_mat = random_unitary(dim, is_real=True) | ||
|
||
rand_orth_basis = [random_mat[:, i] for i in range(dim)] | ||
|
||
if not is_orthonormal(np.array(rand_orth_basis)): | ||
raise ValueError("Random orthonormal basis could not constructed.") | ||
|
||
return rand_orth_basis | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Tests for random orthonormal basis.""" |