Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making S2gate of lab and lab_dev the same #548

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Install black formatter
run: |
python -m pip install --upgrade pip
pip install black
pip install black==22.12.0

- name: Check formatting
run: |
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 24.3.0
rev: 22.12.0
hooks:
- id: black
2 changes: 1 addition & 1 deletion mrmustard/lab_dev/states/two_mode_squeezed_vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class TwoModeSqueezedVacuum(Ket):
>>> from mrmustard.lab_dev import TwoModeSqueezedVacuum, S2gate, Vacuum

>>> state = TwoModeSqueezedVacuum(modes=[0, 1], r=0.3, phi=0.2)
>>> assert state == Vacuum([0, 1]) >> S2gate([0, 1], r=0.3, phi=0.2)
>>> assert state == Vacuum([0, 1]) >> S2gate([0, 1], r=-0.3, phi=0.2)


Args:
Expand Down
4 changes: 2 additions & 2 deletions mrmustard/lab_dev/transformations/s2gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ class S2gate(Unitary):
A = \begin{bmatrix}
O & e^{i\phi}\tanh(r) & \sech(r) & 0 \\
e^{i\phi}\tanh(r) & 0 & 0 & \sech(r) \\
\sech(r) & & 0 & 0 e^{i\phi}\tanh(r) \\
O & \sech(r) & e^{i\phi}\tanh(r) & 0
\sech(r) & & 0 & 0 -e^{i\phi}\tanh(r) \\
O & \sech(r) & -e^{i\phi}\tanh(r) & 0
\end{bmatrix} \text{, }
b = O_{4} \text{, and }
c = \sech(r)
Expand Down
4 changes: 2 additions & 2 deletions mrmustard/physics/triples.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,9 +526,9 @@ def twomode_squeezing_gate_Abc(
tanhr = math.diag(math.exp(1j * phi) * math.sinh(r) / math.cosh(r))
sechr = math.diag(1 / math.cosh(r))

A_block1 = math.block([[O, -tanhr], [-tanhr, O]])
A_block1 = math.block([[O, tanhr], [tanhr, O]])

A_block2 = math.block([[O, math.conj(tanhr)], [math.conj(tanhr), O]])
A_block2 = math.block([[O, -math.conj(tanhr)], [-math.conj(tanhr), O]])

A_block3 = math.block([[sechr, O], [O, sechr]])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import pytest

from mrmustard import math
from mrmustard.lab_dev.states import SqueezedVacuum, TwoModeSqueezedVacuum, Vacuum
from mrmustard.lab_dev.transformations import S2gate

Expand Down Expand Up @@ -62,7 +63,7 @@ def test_trainable_parameters(self):
@pytest.mark.parametrize("modes,r,phi", zip(modes, r, phi))
def test_representation(self, modes, r, phi):
rep = TwoModeSqueezedVacuum(modes, r, phi).ansatz
exp = (Vacuum(modes) >> S2gate(modes, r, phi)).ansatz
exp = (Vacuum(modes) >> S2gate(modes, -math.astensor(r), phi)).ansatz
assert rep == exp

def test_representation_error(self):
Expand Down
10 changes: 5 additions & 5 deletions tests/test_lab_dev/test_transformations/test_s2gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ def test_representation(self):

A_exp = [
[
[0, -tanhr, sechr, 0],
[-tanhr, 0, 0, sechr],
[sechr, 0, 0, np.conj(tanhr)],
[0, sechr, np.conj(tanhr), 0],
[0, tanhr, sechr, 0],
[tanhr, 0, 0, sechr],
[sechr, 0, 0, -np.conj(tanhr)],
[0, sechr, -np.conj(tanhr), 0],
]
]
assert math.allclose(rep1.A, A_exp)
Expand All @@ -77,7 +77,7 @@ def test_trainable_parameters(self):
assert gate3.parameters.phi.value == 2

def test_operation(self):
rep1 = (Vacuum([0]) >> Vacuum([1]) >> S2gate(modes=[0, 1], r=1, phi=0.5)).ansatz
rep1 = (Vacuum([0]) >> Vacuum([1]) >> S2gate(modes=[0, 1], r=-1, phi=0.5)).ansatz
rep2 = (TwoModeSqueezedVacuum(modes=[0, 1], r=1, phi=0.5)).ansatz

assert math.allclose(rep1.A, rep2.A)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_training/test_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import tensorflow as tf

from mrmustard import math, settings
from mrmustard.lab_dev import Circuit, BSgate, S2gate, Vacuum
from mrmustard.lab_dev import BSgate, Circuit, S2gate, Vacuum
from mrmustard.training import Optimizer, TensorboardCallback

from ..conftest import skip_np
Expand Down
20 changes: 10 additions & 10 deletions tests/test_training/test_opt_lab_dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,24 @@

from mrmustard import math, settings
from mrmustard.lab_dev import (
Circuit,
Sgate,
S2gate,
Vacuum,
BSgate,
Ggate,
Interferometer,
Rgate,
Circuit,
Dgate,
RealInterferometer,
DisplacedSqueezed,
SqueezedVacuum,
Ggate,
GKet,
Interferometer,
Number,
RealInterferometer,
Rgate,
S2gate,
Sgate,
SqueezedVacuum,
TwoModeSqueezedVacuum,
Vacuum,
)
from mrmustard.math.parameters import Variable, update_euclidean
from mrmustard.physics.gaussian import von_neumann_entropy, number_means
from mrmustard.physics.gaussian import number_means, von_neumann_entropy
from mrmustard.training import Optimizer
from mrmustard.training.callbacks import Callback

Expand Down
2 changes: 1 addition & 1 deletion tests/test_training/test_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
except ImportError:
ray_available = False

from mrmustard.lab_dev import Dgate, GKet, Ggate, Vacuum
from mrmustard.lab_dev import Dgate, Ggate, GKet, Vacuum
from mrmustard.training import Optimizer
from mrmustard.training.trainer import map_trainer, train_device, update_pop

Expand Down
Loading