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

Tutorials for lab_dev and physics #392

Open
wants to merge 92 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
5937525
added func
SamFerracin Apr 15, 2024
be61862
done
SamFerracin Apr 16, 2024
046af14
done
SamFerracin Apr 16, 2024
ee13a6c
test trace out
SamFerracin Apr 16, 2024
1ff349c
tests
SamFerracin Apr 16, 2024
7934dae
more progress
SamFerracin Apr 17, 2024
4316359
tests
SamFerracin Apr 17, 2024
7fdfd39
done
SamFerracin Apr 17, 2024
56e4467
done
SamFerracin Apr 17, 2024
59019a0
ugh
SamFerracin Apr 17, 2024
375d260
Merge branch 'develop' of https://github.com/XanaduAI/MrMustard into …
SamFerracin Apr 17, 2024
91a9678
done
SamFerracin Apr 17, 2024
55df8d1
Merge branch 'develop' of https://github.com/XanaduAI/MrMustard into …
SamFerracin Apr 19, 2024
decc3d0
need to fix things
SamFerracin Apr 19, 2024
7b642a1
Merge branch 'develop' into exp-val
ziofil Apr 19, 2024
d133ecc
Update mrmustard/lab_dev/states/base.py
Apr 22, 2024
f479998
Update mrmustard/lab_dev/states/base.py
Apr 22, 2024
90161ef
some progress
SamFerracin Apr 22, 2024
6e7de41
etsts pass
SamFerracin Apr 22, 2024
a3ab903
done?
SamFerracin Apr 22, 2024
8e80056
Update mrmustard/lab_dev/states/base.py
Apr 22, 2024
6198a17
Update mrmustard/lab_dev/states/base.py
Apr 22, 2024
397d251
bl
SamFerracin Apr 22, 2024
665bc82
odc
SamFerracin Apr 22, 2024
076f2f0
done
SamFerracin Apr 25, 2024
2a4b1c7
ll
SamFerracin Apr 25, 2024
0eeb99f
bug
SamFerracin Apr 25, 2024
cc38e05
Update mrmustard/lab_dev/states/base.py
Apr 25, 2024
36b66eb
Update mrmustard/lab_dev/states/base.py
Apr 25, 2024
d25e6bb
Update mrmustard/lab_dev/states/base.py
Apr 25, 2024
66a90de
Update mrmustard/lab_dev/states/base.py
Apr 25, 2024
9513299
Merge branch 'exp-val' of https://github.com/XanaduAI/MrMustard into …
SamFerracin Apr 25, 2024
b073f0a
Merge branch 'develop' of https://github.com/XanaduAI/MrMustard into …
SamFerracin Apr 25, 2024
d31eaa8
ds
SamFerracin Apr 25, 2024
562295e
revert
SamFerracin Apr 25, 2024
a78ea14
cr
SamFerracin Apr 26, 2024
010b732
gaussian integrals
SamFerracin Apr 26, 2024
7dc4088
more
SamFerracin Apr 26, 2024
f6b1cf5
Merge branch 'exp-val' of https://github.com/XanaduAI/MrMustard into …
SamFerracin Apr 26, 2024
c673986
..
SamFerracin Apr 29, 2024
a5fe7a3
..
SamFerracin Apr 29, 2024
09aa175
..
SamFerracin Apr 29, 2024
013abdb
..
SamFerracin Apr 29, 2024
e45ccd8
..
SamFerracin Apr 29, 2024
bc01a51
progress
SamFerracin Apr 29, 2024
e52d85f
yuan
SamFerracin May 3, 2024
9122fc0
progress
SamFerracin May 3, 2024
f8a6357
add docs for init physics
sylviemonet May 3, 2024
9815b93
add more docs
sylviemonet May 3, 2024
02a9249
add docs
sylviemonet May 3, 2024
3b2c366
add anstaz docs
sylviemonet May 3, 2024
fc95c68
Merge branch 'develop' into tutorials
sylviemonet May 3, 2024
f254561
bargmann theory docs
sylviemonet May 3, 2024
e5bd587
test acs|| diagram
sylviemonet May 6, 2024
110f959
converters doc
sylviemonet May 6, 2024
b6e6c08
moved phys funcs
sylviemonet May 7, 2024
a220c98
oops
sylviemonet May 7, 2024
e3b8822
add diagram and fix codefactor
sylviemonet May 7, 2024
0ab8fd3
fix code block converters
sylviemonet May 7, 2024
a25f9db
s
SamFerracin May 7, 2024
5d2e3d3
docs in converters
sylviemonet May 7, 2024
c020208
fix the structure
sylviemonet May 7, 2024
a7cb003
fix the structure again
sylviemonet May 7, 2024
6660ea4
big changes in structure in physics
sylviemonet May 7, 2024
fd4cdda
try again
sylviemonet May 7, 2024
387c0c3
try to fix errors with math
sylviemonet May 7, 2024
190a526
states
SamFerracin May 7, 2024
9d79fb7
Merge branch 'tutorials' of https://github.com/XanaduAI/MrMustard int…
SamFerracin May 7, 2024
5626f27
bargmann docs
sylviemonet May 7, 2024
e8fbe74
bargmamnn docs
sylviemonet May 7, 2024
a0be9ab
fix bugs in cc
sylviemonet May 7, 2024
d6b3dd7
julia
SamFerracin May 7, 2024
51238fa
Merge branch 'tutorials' of https://github.com/XanaduAI/MrMustard int…
SamFerracin May 7, 2024
e46d9a9
the docs in bargmann
sylviemonet May 7, 2024
0acd882
fix diagrams
sylviemonet May 7, 2024
39089af
bargmann docs goooo
sylviemonet May 7, 2024
17f9b31
fix diagrams
sylviemonet May 7, 2024
9c339a2
add docs in fock
sylviemonet May 7, 2024
1fbc022
add the docs for ansatze
sylviemonet May 8, 2024
5d54544
gaussian integral docs
sylviemonet May 8, 2024
42f5273
progress
SamFerracin May 9, 2024
d7a5a67
fix bugs in docs
sylviemonet May 9, 2024
d887eaa
add comments
sylviemonet May 9, 2024
7122176
Merge branch 'tutorials' of https://github.com/XanaduAI/MrMustard int…
SamFerracin May 9, 2024
c9e9189
oops
SamFerracin May 10, 2024
2586020
Merge branch 'develop' into tutorials
sylviemonet May 13, 2024
0c02cee
Merge branch 'develop' into tutorials
sylviemonet May 15, 2024
ea7333e
Update mrmustard/lab_dev/circuit_components.py
sylviemonet May 15, 2024
f4889f8
fix bugs from kasper's comments
sylviemonet May 15, 2024
fea110a
fix codefactor
sylviemonet May 15, 2024
da55f30
blacked
sylviemonet May 15, 2024
248bc1b
Merge branch 'develop' into tutorials
sylviemonet May 15, 2024
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
14 changes: 7 additions & 7 deletions mrmustard/lab_dev/states/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,10 +703,10 @@ def expectation(self, operator: CircuitComponent):
if op_type is OperatorType.INVALID_TYPE:
raise ValueError(msg)

# check that the operator is defined on valid modes
# check that the returned component is still a `DM`
if not operator.wires.modes.issubset(self.wires.modes):
msg = f"Expected an observable defined for modes `{self.modes}` or a subset thereof, "
msg += f"found one defined for modes `{operator.modes}.`"
msg = f"Expected an operator defined on a subset of modes `{self.modes}`, "
msg += f"found one defined on `{operator.modes}.`"
raise ValueError(msg)

if op_type is OperatorType.KET_LIKE:
Expand Down Expand Up @@ -894,18 +894,18 @@ def expectation(self, operator: CircuitComponent):
if op_type is OperatorType.INVALID_TYPE:
raise ValueError(msg)

# check that the operator is defined on valid modes
# check that the returned component is still a `Ket`
if not operator.wires.modes.issubset(self.wires.modes):
msg = f"Expected an observable defined for modes `{self.modes}` or a subset thereof, "
msg += f"found one defined for modes `{operator.modes}.`"
msg = f"Expected an operator defined on a subset of modes `{self.modes}`, "
msg += f"found one defined on `{operator.modes}.`"
raise ValueError(msg)

if op_type is OperatorType.KET_LIKE:
result = self @ operator.dual
elif op_type is OperatorType.DM_LIKE:
result = self @ self.adjoint @ operator.dual
else:
result = (self @ operator @ self.dual).representation
result = (self @ operator @ self.dual)

rep = result.representation
return rep.array if isinstance(rep, Fock) else rep.c
Expand Down
46 changes: 23 additions & 23 deletions tests/test_lab_dev/test_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ def test_expectation_bargmann(self):
dm1 = Coherent([1], x=1, y=3).dm()
dm01 = Coherent([0, 1], x=1, y=[2, 3]).dm()

res_dm0 = (ket @ ket.adjoint @ dm0).representation.c
res_dm1 = (ket @ ket.adjoint @ dm1).representation.c
res_dm01 = (ket @ ket.adjoint @ dm01).representation.c
res_dm0 = (ket @ ket.adjoint @ dm0.dual).representation.c
res_dm1 = (ket @ ket.adjoint @ dm1.dual).representation.c
res_dm01 = (ket @ ket.adjoint @ dm01.dual).representation.c

assert math.allclose(ket.expectation(dm0), res_dm0)
assert math.allclose(ket.expectation(dm1), res_dm1)
Expand All @@ -189,9 +189,9 @@ def test_expectation_bargmann(self):
u1 = Dgate([0], x=0.2)
u01 = Dgate([0, 1], x=[0.3, 0.4])

res_u0 = ((ket @ ket.dual @ u0) >> TraceOut(ket.modes)).representation.c
res_u1 = ((ket @ ket.dual @ u1) >> TraceOut(ket.modes)).representation.c
res_u01 = ((ket @ ket.dual @ u01) >> TraceOut(ket.modes)).representation.c
res_u0 = (ket @ u0 @ ket.dual).representation.c
res_u1 = (ket @ u1 @ ket.dual).representation.c
res_u01 = (ket @ u01 @ ket.dual).representation.c

assert math.allclose(ket.expectation(u0), res_u0)
assert math.allclose(ket.expectation(u1), res_u1)
Expand All @@ -218,9 +218,9 @@ def test_expectation_fock(self):
dm1 = Coherent([1], x=1, y=3).dm()
dm01 = Coherent([0, 1], x=1, y=[2, 3]).dm()

res_dm0 = (ket @ ket.adjoint @ dm0).representation.array
res_dm1 = (ket @ ket.adjoint @ dm1).representation.array
res_dm01 = (ket @ ket.adjoint @ dm01).representation.array
res_dm0 = (ket @ ket.adjoint @ dm0.dual).representation.array
res_dm1 = (ket @ ket.adjoint @ dm1.dual).representation.array
res_dm01 = (ket @ ket.adjoint @ dm01.dual).representation.array

assert math.allclose(ket.expectation(dm0), res_dm0)
assert math.allclose(ket.expectation(dm1), res_dm1)
Expand All @@ -230,9 +230,9 @@ def test_expectation_fock(self):
u1 = Dgate([0], x=0.2)
u01 = Dgate([0, 1], x=[0.3, 0.4])

res_u0 = ((ket @ ket.dual @ u0) >> TraceOut(ket.modes)).representation.array
res_u1 = ((ket @ ket.dual @ u1) >> TraceOut(ket.modes)).representation.array
res_u01 = ((ket @ ket.dual @ u01) >> TraceOut(ket.modes)).representation.array
res_u0 = (ket @ u0 @ ket.dual).representation.array
res_u1 = (ket @ u1 @ ket.dual).representation.array
res_u01 = (ket @ u01 @ ket.dual).representation.array

assert math.allclose(ket.expectation(u0), res_u0)
assert math.allclose(ket.expectation(u1), res_u1)
Expand All @@ -252,7 +252,7 @@ def test_expectation_error(self):
ket.expectation(op2)

op3 = Dgate([2])
with pytest.raises(ValueError, match="Expected an observable defined for modes"):
with pytest.raises(ValueError, match="Expected an operator defined on"):
ket.expectation(op3)

def test_rshift(self):
Expand Down Expand Up @@ -412,9 +412,9 @@ def test_expectation_bargmann(self):
k1 = Coherent([1], x=1, y=3)
k01 = Coherent([0, 1], x=1, y=[2, 3])

res_k0 = (dm @ k0.dual @ k0.dual.adjoint).representation.array
res_k1 = (dm @ k1.dual @ k1.dual.adjoint).representation.array
res_k01 = (dm @ k01.dual @ k01.dual.adjoint).representation.array
res_k0 = (dm @ k0.dual @ k0.dual.adjoint).representation.c
res_k1 = (dm @ k1.dual @ k1.dual.adjoint).representation.c
res_k01 = (dm @ k01.dual @ k01.dual.adjoint).representation.c

assert math.allclose(dm.expectation(k0), res_k0)
assert math.allclose(dm.expectation(k1), res_k1)
Expand All @@ -424,9 +424,9 @@ def test_expectation_bargmann(self):
dm1 = Coherent([1], x=1, y=3).dm()
dm01 = Coherent([0, 1], x=1, y=[2, 3]).dm()

res_dm0 = (dm @ dm0.dual).representation.array
res_dm1 = (dm @ dm1.dual).representation.array
res_dm01 = (dm @ dm01.dual).representation.array
res_dm0 = (dm @ dm0.dual).representation.c
res_dm1 = (dm @ dm1.dual).representation.c
res_dm01 = (dm @ dm01.dual).representation.c

assert math.allclose(dm.expectation(dm0), res_dm0)
assert math.allclose(dm.expectation(dm1), res_dm1)
Expand All @@ -436,9 +436,9 @@ def test_expectation_bargmann(self):
u1 = Dgate([0], x=0.2)
u01 = Dgate([0, 1], x=[0.3, 0.4])

res_u0 = ((dm @ u0) >> TraceOut(dm.modes)).representation.array
res_u1 = ((dm @ u1) >> TraceOut(dm.modes)).representation.array
res_u01 = ((dm @ u01) >> TraceOut(dm.modes)).representation.array
res_u0 = ((dm @ u0) >> TraceOut(dm.modes)).representation.c
res_u1 = ((dm @ u1) >> TraceOut(dm.modes)).representation.c
res_u01 = ((dm @ u01) >> TraceOut(dm.modes)).representation.c

assert math.allclose(dm.expectation(u0), res_u0)
assert math.allclose(dm.expectation(u1), res_u1)
Expand Down Expand Up @@ -500,7 +500,7 @@ def test_expectation_error(self):
dm.expectation(op2)

op3 = Dgate([2])
with pytest.raises(ValueError, match="Expected an observable defined for modes"):
with pytest.raises(ValueError, match="Expected an operator defined on"):
dm.expectation(op3)

def test_rshift(self):
Expand Down