Skip to content

Commit

Permalink
tests for bargmanneigenstate added
Browse files Browse the repository at this point in the history
  • Loading branch information
arsalan-motamedi committed Nov 8, 2024
1 parent 2ab72f0 commit d68c34c
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 5 deletions.
4 changes: 1 addition & 3 deletions mrmustard/lab_dev/states/bargmanneigenstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ def __init__(
):
super().__init__(name="BargmannEigenstate")

alphas = list(reshape_params(len(modes), alphas=alpha))
self._add_parameter(make_parameter(alpha_trainable, alphas, "alpha", alpha_bounds))
print(self.alpha.value)
self._add_parameter(make_parameter(alpha_trainable, alpha, "alpha", alpha_bounds))
self._representation = self.from_ansatz(
modes=modes,
ansatz=PolyExpAnsatz.from_function(
Expand Down
2 changes: 1 addition & 1 deletion mrmustard/lab_dev/transformations/realinterferometer.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def __init__(
num_modes = len(modes)
if orthogonal is not None and orthogonal.shape[-1] != num_modes:
raise ValueError(
f"The size of the unitary must match the number of modes: {orthogonal.shape[-1]} =/= {num_modes}"
f"The size of the orthogonal matrix must match the number of modes: {orthogonal.shape[-1]} =/= {num_modes}"
)

if orthogonal is None:
Expand Down
2 changes: 1 addition & 1 deletion mrmustard/physics/triples.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def bargmann_eigenstate_Abc(x: Union[float, Iterable[float]]) -> Union[Matrix, V
The Abc triple of a Bargmann eigenstate.
"""
x = list(_reshape(x=x))
nmodes = len(x)
nmodes = len(x[0])
A = _vacuum_A_matrix(nmodes)
b = x
c = 1
Expand Down
44 changes: 44 additions & 0 deletions tests/test_lab_dev/test_states/test_bargmanneigenstate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright 2024 Xanadu Quantum Technologies Inc.

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Tests for the BargmannEigenstate class."""

# pylint: disable=unspecified-encoding, missing-function-docstring, expression-not-assigned, pointless-statement

import pytest

from mrmustard import math
from mrmustard.lab_dev.states import BargmannEigenstate


class TestBargmannEigenstate:
r"""
Tests for the ``BargmannEigenstate`` class.
"""

def test_init(self):
"Tests the initialization."
be = BargmannEigenstate([0, 1], [0.1j, 0.2])
assert be.name == "BargmannEigenstate"
assert math.allclose(be.alpha.value, [0.1j, 0.2])
assert be.modes == [0, 1]
assert math.allclose(be.ansatz.b[0], [0.1j, 0.2])
assert math.allclose(be.ansatz.A[0], math.zeros((2, 2)))
assert be.ansatz.c[0] == 1.0

@pytest.mark.parametrize("alpha", [0.1, 0.5, 1])
def test_numerial(self, alpha):
"A numerical test."
be = BargmannEigenstate([0], alpha)
assert be >> be.dual == math.exp(complex(alpha**2))

0 comments on commit d68c34c

Please sign in to comment.