Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
apchytr committed Oct 8, 2024
1 parent a79284a commit d5f9f3a
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions mrmustard/lab_dev/circuit_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ def bargmann_triple(
"""
return self._representation.bargmann_triple(batched)

def fock(self, shape: int | Sequence[int] | None = None, batched=False) -> ComplexTensor:
def fock_array(self, shape: int | Sequence[int] | None = None, batched=False) -> ComplexTensor:
r"""
Returns an array representation of this component in the Fock basis with the given shape.
If the shape is not given, it defaults to the ``auto_shape`` of the component if it is
Expand All @@ -477,7 +477,7 @@ def fock(self, shape: int | Sequence[int] | None = None, batched=False) -> Compl
Returns:
array: The Fock representation of this component.
"""
return self._representation.fock(shape or self.auto_shape(), batched)
return self._representation.fock_array(shape or self.auto_shape(), batched)

def on(self, modes: Sequence[int]) -> CircuitComponent:
r"""
Expand Down
2 changes: 1 addition & 1 deletion mrmustard/lab_dev/states/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def fock_distribution(self, cutoff: int) -> ComplexTensor:
Returns:
The Fock distribution.
"""
fock_array = self.fock(cutoff)
fock_array = self.fock_array(cutoff)
if isinstance(self, Ket):
probs = (
math.astensor(
Expand Down
4 changes: 2 additions & 2 deletions mrmustard/lab_dev/transformations/dgate.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def __init__(
self.wires,
)

def fock(self, shape: int | Sequence[int] = None, batched=False) -> ComplexTensor:
def fock_array(self, shape: int | Sequence[int] = None, batched=False) -> ComplexTensor:
r"""
Returns the unitary representation of the Displacement gate using the Laguerre polynomials.
If the shape is not given, it defaults to the ``auto_shape`` of the component if it is
Expand Down Expand Up @@ -145,7 +145,7 @@ def fock(self, shape: int | Sequence[int] = None, batched=False) -> ComplexTenso
return arrays

def to_fock(self, shape: int | Sequence[int] | None = None) -> Dgate:
fock = ArrayAnsatz(self.fock(shape, batched=True), batched=True)
fock = ArrayAnsatz(self.fock_array(shape, batched=True), batched=True)
fock._original_abc_data = self.ansatz.triple
ret = self._getitem_builtin(self.modes)
ret._representation = Representation(fock, self.wires)
Expand Down
8 changes: 4 additions & 4 deletions mrmustard/physics/representations.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def bargmann_triple(
except AttributeError as e:
raise AttributeError("No Bargmann data for this component.") from e

def fock(self, shape: int | Sequence[int], batched=False) -> ComplexTensor:
def fock_array(self, shape: int | Sequence[int], batched=False) -> ComplexTensor:
r"""
Returns an array representation of this component in the Fock basis with the given shape.
If the shape is not given, it defaults to the ``auto_shape`` of the component if it is
Expand Down Expand Up @@ -172,7 +172,7 @@ def fock(self, shape: int | Sequence[int], batched=False) -> ComplexTensor:

def to_bargmann(self) -> Representation:
r"""
Returns a new circuit component with the same attributes as this and a ``Bargmann`` representation.
Converts this representation to a Bargmann representation.
"""
if isinstance(self.ansatz, PolyExpAnsatz):
return self
Expand All @@ -187,14 +187,14 @@ def to_bargmann(self) -> Representation:

def to_fock(self, shape: int | Sequence[int]) -> Representation:
r"""
Returns a new representation with an ``ArrayAnsatz``.
Converts this representation to a Fock representation.
Args:
shape: The shape of the returned representation. If ``shape``is given as
an ``int``, it is broadcasted to all the dimensions. If ``None``, it
defaults to the value of ``AUTOSHAPE_MAX`` in the settings.
"""
fock = ArrayAnsatz(self.fock(shape, batched=True), batched=True)
fock = ArrayAnsatz(self.fock_array(shape, batched=True), batched=True)
try:
if self.ansatz.polynomial_shape[0] == 0:
fock._original_abc_data = self.ansatz.triple
Expand Down
2 changes: 1 addition & 1 deletion tests/test_lab_dev/test_circuit_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ def test_to_fock_keeps_bargmann(self):
def test_fock_component_no_bargmann(self):
"tests that a fock component doesn't have a bargmann representation by default"
coh = Coherent([0], x=1.0)
CC = Ket.from_fock([0], coh.fock(20), batched=False)
CC = Ket.from_fock([0], coh.fock_array(20), batched=False)
with pytest.raises(AttributeError):
CC.bargmann_triple() # pylint: disable=pointless-statement

Expand Down
6 changes: 3 additions & 3 deletions tests/test_lab_dev/test_states/test_states_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def test_normalize(self, modes, x, y, coeff):
def test_to_from_fock(self, modes):
state_in = Coherent(modes, x=1, y=2)
state_in_fock = state_in.to_fock(5)
array_in = state_in.fock(5, batched=True)
array_in = state_in.fock_array(5, batched=True)

assert math.allclose(array_in, state_in_fock.ansatz.array)

Expand Down Expand Up @@ -522,7 +522,7 @@ def test_from_fock_error(self):
state01 = Coherent([0, 1], 1).dm()
state01 = state01.to_fock(2)
with pytest.raises(ValueError):
DM.from_fock([0], state01.fock(5), "my_dm", True)
DM.from_fock([0], state01.fock_array(5), "my_dm", True)

def test_bargmann_Abc_to_phasespace_cov_means(self):
# The init state cov and means comes from the random state 'state = Gaussian(1) >> Dgate([0.2], [0.3])'
Expand Down Expand Up @@ -596,7 +596,7 @@ def test_normalize(self, modes, x, y, coeff):
def test_to_from_fock(self, modes):
state_in = Coherent(modes, x=1, y=2) >> Attenuator([modes[0]], 0.8)
state_in_fock = state_in.to_fock(5)
array_in = state_in.fock(5, batched=True)
array_in = state_in.fock_array(5, batched=True)

assert math.allclose(array_in, state_in_fock.ansatz.array)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_lab_dev/test_transformations/test_dgate.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_to_fock_method(self):
# displacement gate in fock representation for large displacement
dgate = Dgate([0], x=10.0).to_fock(150)
assert (state.to_fock() >> dgate).probability < 1
assert np.all(math.abs(dgate.fock(150)) < 1)
assert np.all(math.abs(dgate.fock_array(150)) < 1)

def test_representation(self):
rep1 = Dgate(modes=[0], x=0.1, y=0.1).ansatz
Expand Down
8 changes: 4 additions & 4 deletions tests/test_math/test_lattice.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,14 @@ def test_diagonalbatchNumba_vs_diagonalNumba(batch_size):

def test_bs_schwinger():
"test that the schwinger method to apply a BS works correctly"
G = mmld.Ket.random([0, 1]).fock([20, 20])
G = mmld.Ket.random([0, 1]).fock_array([20, 20])
G = math.asnumpy(G)
BS = beamsplitter((20, 20, 20, 20), 1.0, 1.0)
manual = np.einsum("ab, cdab", G, BS)
G = apply_BS_schwinger(1.0, 1.0, 0, 1, G)
assert np.allclose(manual, G)

Gg = mmld.Unitary.random([0, 1]).fock([20, 20, 20, 20])
Gg = mmld.Unitary.random([0, 1]).fock_array([20, 20, 20, 20])
Gg = math.asnumpy(Gg)
BS = beamsplitter((20, 20, 20, 20), 2.0, -1.0)
manual = np.einsum("cdab, abef", BS, Gg)
Expand Down Expand Up @@ -157,10 +157,10 @@ def test_vanilla_stable():
"tests the vanilla stable against other known stable methods"
settings.STABLE_FOCK_CONVERSION = True
assert np.allclose(
mmld.Dgate([0], x=4.0, y=4.0).fock([1000, 1000]),
mmld.Dgate([0], x=4.0, y=4.0).fock_array([1000, 1000]),
displacement((1000, 1000), 4.0 + 4.0j),
)
sgate = mmld.Sgate([0], r=4.0, phi=2.0).fock([1000, 1000])
sgate = mmld.Sgate([0], r=4.0, phi=2.0).fock_array([1000, 1000])
assert np.max(np.abs(sgate)) < 1
settings.STABLE_FOCK_CONVERSION = False

Expand Down

0 comments on commit d5f9f3a

Please sign in to comment.