forked from Budapest-Quantum-Computing-Group/piquasso
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The calculation of the Wigner function has been implemented under `GaussianState`. Since the implementation got too large, the core of the calcutation got moved to `functions.py` in the same folder. The `gaussian_wigner_function` accepts not only a single canonical coordinate vector, but a list of vectors. **Note** The `.flake8` file got extended with exclusions, because `flake8` ran on those folders as well.
- Loading branch information
1 parent
09deb93
commit 08d4b3d
Showing
5 changed files
with
151 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
[flake8] | ||
# Longer line-length is more convenient for math | ||
max-line-length = 88 | ||
exclude = .tox,pennylane | ||
extend-ignore = W605, # Ignoring latex syntax in docstrings | ||
E201 # Ignoring whitespace after '(' or '[' for matrices |
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,29 @@ | ||
# | ||
# Copyright (C) 2020 by TODO - All rights reserved. | ||
# | ||
|
||
import numpy as np | ||
|
||
|
||
def gaussian_wigner_function(quadrature_matrix, *, d, mean, cov): | ||
assert len(quadrature_matrix[0]) == len(mean), ( | ||
"'quadrature_matrix' elements should have the same dimension as 'mean': " | ||
f"dim(quadrature_matrix[0])={len(quadrature_matrix[0])}, dim(mean)={len(mean)}." | ||
) | ||
|
||
return [ | ||
_gaussian_wigner_function_for_scalar(quadrature_array, d=d, mean=mean, cov=cov) | ||
for quadrature_array in quadrature_matrix | ||
] | ||
|
||
|
||
def _gaussian_wigner_function_for_scalar(X, *, d, mean, cov): | ||
return ( | ||
(1 / (np.pi ** d)) | ||
* np.sqrt((1 / np.linalg.det(cov))) | ||
* np.exp( | ||
- (X - mean) | ||
@ np.linalg.inv(cov) | ||
@ (X - mean) | ||
) | ||
).real |
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,64 @@ | ||
# | ||
# Copyright (C) 2020 by TODO - All rights reserved. | ||
# | ||
|
||
import pytest | ||
import numpy as np | ||
|
||
from piquasso import functions | ||
|
||
|
||
@pytest.fixture | ||
def d(): | ||
return 1 | ||
|
||
|
||
@pytest.fixture | ||
def mean(): | ||
return np.array([1, 2]) | ||
|
||
|
||
@pytest.fixture | ||
def cov(): | ||
return np.array( | ||
[ | ||
[1, 2], | ||
[-3, 4], | ||
] | ||
) | ||
|
||
|
||
def test_wigner_function_at_scalar(d, mean, cov): | ||
quadrature_array = np.array([1, 2]) | ||
|
||
expected = 0.10065842420897406 | ||
|
||
actual = functions._gaussian_wigner_function_for_scalar( | ||
X=quadrature_array, d=d, mean=mean, cov=cov | ||
) | ||
|
||
assert np.allclose(expected, actual) | ||
|
||
|
||
def test_gaussian_wigner_function_handles_vectors(d, mean, cov): | ||
quadrature_matrix = np.array( | ||
[ | ||
[1, 2], | ||
[3, 4], | ||
[5, 6], | ||
] | ||
) | ||
|
||
expected = np.array( | ||
[ | ||
0.10065842420897406, | ||
0.009131526225575573, | ||
6.81746788883418e-06, | ||
], | ||
) | ||
|
||
actual = functions.gaussian_wigner_function( | ||
quadrature_matrix, d=d, mean=mean, cov=cov | ||
) | ||
|
||
assert np.allclose(expected, actual) |