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

Integration into the current PL device ecosys #6684

Open
wants to merge 314 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 176 commits
Commits
Show all changes
314 commits
Select commit Hold shift + click to select a range
e763a1d
Update pennylane/devices/qubit_mixed/measure.py
JerryChen97 Nov 29, 2024
102b267
Merge branch 'master' into add-qubit_mixed/measure
JerryChen97 Nov 29, 2024
c49a66e
Merge branch 'master' into add-qubit_mixed/measure
JerryChen97 Nov 29, 2024
75c46ee
Init this branch
JerryChen97 Nov 26, 2024
ca1e5c7
copy-paste from qutrit with minimal mod
JerryChen97 Nov 28, 2024
0c75708
Merge branch 'add-qubit_mixed/sampling' of https://github.com/PennyLa…
JerryChen97 Nov 29, 2024
4d23fe5
export to the init
JerryChen97 Nov 29, 2024
aaf4796
add tests
JerryChen97 Nov 29, 2024
1fd2c5a
add list
JerryChen97 Nov 29, 2024
c8e05d8
fix match issue
JerryChen97 Nov 29, 2024
35c80bb
fix coverage
JerryChen97 Nov 29, 2024
ee7ee2d
silence the formmater
JerryChen97 Nov 29, 2024
d80046d
forgot the second line...
JerryChen97 Nov 29, 2024
f3f26ec
fix some merge issue
JerryChen97 Nov 29, 2024
da9e8af
another
JerryChen97 Nov 29, 2024
f8437da
Merge branch 'master' into add-analytic-simulate-for-mixed-new-api
JerryChen97 Dec 2, 2024
47ebfec
Add measurement process for shadow in qubit mixed.
JerryChen97 Dec 2, 2024
eca2efd
correct log
JerryChen97 Dec 2, 2024
ae7f314
revert some unnecessary change for now in absence of execution PR
JerryChen97 Dec 2, 2024
8d7b5fa
revert an implicit merge conflict
JerryChen97 Dec 2, 2024
8877ec1
revert unnecessary mod
JerryChen97 Dec 2, 2024
6f35a7b
Merge branch 'master' into add-qubit_mixed/sampling
JerryChen97 Dec 2, 2024
74bc094
tr -> b
JerryChen97 Dec 2, 2024
5aba100
raise NotImplemented for finite shots along with tests
JerryChen97 Dec 2, 2024
3405308
fix docstr
JerryChen97 Dec 2, 2024
01de04f
fix changelog
JerryChen97 Dec 2, 2024
fe9e329
re-arrange
JerryChen97 Dec 2, 2024
5d90d04
debug a potential bug
JerryChen97 Dec 2, 2024
a3453bc
reuse qubit sample probs
JerryChen97 Dec 2, 2024
1db7078
cancel exporting of sample_probs
JerryChen97 Dec 2, 2024
514fb7c
simplify logics
JerryChen97 Dec 2, 2024
7227b93
Merge branch 'add-qubit_mixed/sampling' into add-qubit_mixed/shadow
JerryChen97 Dec 3, 2024
b00d86e
add snapshot operation
JerryChen97 Dec 3, 2024
8464658
Update pennylane/devices/qubit_mixed/measure.py
JerryChen97 Dec 3, 2024
a4d4fc1
Update pennylane/devices/qubit_mixed/sampling.py
JerryChen97 Dec 3, 2024
eedc419
Update pennylane/devices/qubit_mixed/sampling.py
JerryChen97 Dec 3, 2024
a10e5c6
add to changelog
JerryChen97 Dec 3, 2024
4718055
Update pennylane/devices/qubit_mixed/measure.py
JerryChen97 Dec 3, 2024
86398ae
imporve the CountsMP process logic
JerryChen97 Dec 3, 2024
5c08c07
rename the _process_single_shot to _process_single_shot_copy
JerryChen97 Dec 3, 2024
2b0eecc
rm pylint/black blockers
JerryChen97 Dec 3, 2024
b423027
rm non from interface dict
JerryChen97 Dec 3, 2024
06ac221
Merge branch 'master' into add-qubit_mixed/sampling
JerryChen97 Dec 3, 2024
e3022fd
Merge branch 'add-qubit_mixed/sampling' into add-finite-shot-simulate…
JerryChen97 Dec 3, 2024
6845621
add finite shot branch
JerryChen97 Dec 3, 2024
0a38d29
add test suite
JerryChen97 Dec 3, 2024
6cddf64
remove too few shots test
JerryChen97 Dec 3, 2024
99324a0
Merge branch 'add-qubit_mixed/sampling' into add-qubit_mixed/shadow
JerryChen97 Dec 3, 2024
7fbf373
Update pennylane/devices/qubit_mixed/apply_operation.py
JerryChen97 Dec 3, 2024
7954f54
Update pennylane/devices/qubit_mixed/apply_operation.py
JerryChen97 Dec 3, 2024
68dfc7a
Update pennylane/devices/qubit_mixed/apply_operation.py
JerryChen97 Dec 3, 2024
7d53cde
Update pennylane/devices/qubit_mixed/apply_operation.py
JerryChen97 Dec 3, 2024
9aea67d
Update pennylane/devices/qubit_mixed/apply_operation.py
JerryChen97 Dec 3, 2024
b216945
Update tests/devices/qubit_mixed/test_qubit_mixed_apply_operation.py
JerryChen97 Dec 3, 2024
2f2af93
add shot snapshot test with xfails
JerryChen97 Dec 3, 2024
a91c0d5
Merge branch 'add-qubit_mixed/shadow' of https://github.com/PennyLane…
JerryChen97 Dec 3, 2024
e58b049
debug
JerryChen97 Dec 4, 2024
a7577f7
add default values [skip-ci]
JerryChen97 Dec 4, 2024
481b734
positional default [skip-ci]
JerryChen97 Dec 4, 2024
bdb47ac
Merge branch 'master' into add-qubit_mixed/shadow
JerryChen97 Dec 4, 2024
e1c6791
Merge branch 'master' into add-finite-shot-simulate-mixed
JerryChen97 Dec 5, 2024
fde2738
Merge branch 'master' into add-qubit_mixed/shadow
JerryChen97 Dec 5, 2024
b9433ae
revert changes made to master
JerryChen97 Dec 5, 2024
39f324e
Revert "revert changes made to master"
JerryChen97 Dec 5, 2024
99a2f37
clean changelog (just respect master)
JerryChen97 Dec 5, 2024
3efebb1
respect the master branch changelog
JerryChen97 Dec 5, 2024
f85659b
improve test details: lower the bar
JerryChen97 Dec 5, 2024
8a02976
Merge branch 'master' into add-finite-shot-simulate-mixed
JerryChen97 Dec 5, 2024
d3d4a5d
rm subspace
JerryChen97 Dec 5, 2024
bf25524
improve all these MC tests
JerryChen97 Dec 5, 2024
14bee3e
format
JerryChen97 Dec 5, 2024
297ea2f
mod changelog
JerryChen97 Dec 5, 2024
758b39d
debug the test
JerryChen97 Dec 5, 2024
8b72440
add tests for jax
JerryChen97 Dec 6, 2024
34eb4f3
del notimplemented raise
JerryChen97 Dec 6, 2024
408694b
Integration into the current PL device ecosys
JerryChen97 Dec 6, 2024
cdd5d34
[skip-ci] add a blank class for integration tests.
JerryChen97 Dec 6, 2024
0296f93
update docstr of init file
JerryChen97 Dec 6, 2024
be115cf
rename `operations_mixed` -> `operations`
JerryChen97 Dec 6, 2024
eb7438b
draft a chnagelog
JerryChen97 Dec 6, 2024
0da1c68
rename DefaultMixed to DefaultMixedLegacy, DefaultMixedNewAPI to Defa…
JerryChen97 Dec 6, 2024
5c6ba21
docs
JerryChen97 Dec 6, 2024
e0ec3da
renmae previous test codes with legacy suffix
JerryChen97 Dec 6, 2024
9522b4c
Update doc/releases/changelog-dev.md
JerryChen97 Dec 9, 2024
1a90318
Update tests/devices/qubit_mixed/test_qubit_mixed_simulate.py
JerryChen97 Dec 9, 2024
9e61126
rm flaky
JerryChen97 Dec 9, 2024
54257e6
rm flaky import
JerryChen97 Dec 9, 2024
7596d35
rm numerical correctness checks; instead test only the shapes https:/…
JerryChen97 Dec 9, 2024
d5c3753
Merge branch 'master' into add-finite-shot-simulate-mixed
JerryChen97 Dec 9, 2024
5452060
Merge branch 'add-finite-shot-simulate-mixed' into add-qubit_mixed/in…
JerryChen97 Dec 9, 2024
7fbde22
debug: del unused test
JerryChen97 Dec 9, 2024
40715c2
[skip-ci]
JerryChen97 Dec 9, 2024
ecd20e6
Merge branch 'master' into add-finite-shot-simulate-mixed
JerryChen97 Dec 9, 2024
d0d2c03
Merge branch 'add-finite-shot-simulate-mixed' into add-qubit_mixed/in…
JerryChen97 Dec 9, 2024
33ce26d
Merge branch 'add-finite-shot-simulate-mixed' into add-qubit_mixed/sh…
JerryChen97 Dec 9, 2024
b371601
Merge branch 'master' into add-qubit_mixed/shadow
JerryChen97 Dec 9, 2024
6309b45
Merge branch 'master' into add-qubit_mixed/shadow
JerryChen97 Dec 9, 2024
6b641c3
Merge branch 'master' into add-qubit_mixed/integration
JerryChen97 Dec 9, 2024
f2365d8
Merge branch 'add-qubit_mixed/shadow' into add-qubit_mixed/integration
JerryChen97 Dec 9, 2024
c2e84ce
debug snapshot test
JerryChen97 Dec 9, 2024
4cc44e4
Merge branch 'add-qubit_mixed/shadow' into add-qubit_mixed/integration
JerryChen97 Dec 9, 2024
009b01e
improve interface get
JerryChen97 Dec 10, 2024
113f389
add life-savers for all forgotten MP
JerryChen97 Dec 10, 2024
ef99ec5
Merge branch 'master' into add-qubit_mixed/integration
JerryChen97 Dec 10, 2024
68d58c1
use default.mixed.legacy in test_legacy_device.py
JerryChen97 Dec 11, 2024
2e665af
use legacy in test_legacy_facade
JerryChen97 Dec 11, 2024
b352f98
use legacy in test_qubit_device.py
JerryChen97 Dec 11, 2024
36e2e0e
deleted unused legacy default mix tests
JerryChen97 Dec 11, 2024
b8d2f0d
Merge branch 'master' into add-qubit_mixed/integration
JerryChen97 Dec 11, 2024
e68f0cf
Merge branch 'master' into add-qubit_mixed/integration
JerryChen97 Dec 11, 2024
42d1e37
squash all the entries into a single one
JerryChen97 Dec 11, 2024
89c5b53
rm the test specifically for a legacy default mixed
JerryChen97 Dec 11, 2024
2709c2b
sync with master
JerryChen97 Dec 11, 2024
b6d5b3f
Merge branch 'master' into add-qubit_mixed/integration
JerryChen97 Dec 11, 2024
f8c2d93
Update doc/releases/changelog-dev.md
JerryChen97 Dec 11, 2024
1479819
import Interface; pylint, black [skip-ci]
JerryChen97 Dec 11, 2024
bb9a37c
Merge branch 'master' into add-qubit_mixed/integration
JerryChen97 Dec 11, 2024
232890e
correct file locations
JerryChen97 Dec 11, 2024
ef9d9bc
del test return types legacy (legacy default mixed only)
JerryChen97 Dec 11, 2024
39df9e1
[skip-ci] reformat
JerryChen97 Dec 11, 2024
8ea28cc
some minor adjust to the workflow test with too high accuracy demand
JerryChen97 Dec 11, 2024
f0daad7
rm legacy test since the legacy src will disappear soon
JerryChen97 Dec 11, 2024
5413b5e
rm workflow legacy tests
JerryChen97 Dec 11, 2024
dd44fcc
[skip-ci] some intermediate edit
JerryChen97 Dec 12, 2024
f9b174e
improvement
JerryChen97 Dec 12, 2024
5ecc22e
not supporting qml.state()
JerryChen97 Dec 12, 2024
8501bd3
black
JerryChen97 Dec 12, 2024
b9887fd
..
JerryChen97 Dec 12, 2024
2b60df1
reformatting
JerryChen97 Dec 12, 2024
7239ea4
add process_density_matrix for custom state measurement
JerryChen97 Dec 12, 2024
711ea6a
omit phaseflip0
JerryChen97 Dec 12, 2024
a09be94
isort
JerryChen97 Dec 12, 2024
4642564
silent pylint
JerryChen97 Dec 12, 2024
c967693
debug snapshot test
JerryChen97 Dec 12, 2024
a824fcb
debug MP treatment
JerryChen97 Dec 12, 2024
a2ff9a3
format smapoling
JerryChen97 Dec 12, 2024
8f70a81
del legacy test
JerryChen97 Dec 12, 2024
2e977f8
marked purity torch, tf, jax xfails with finite diff
JerryChen97 Dec 12, 2024
de7b7d4
sphinx
JerryChen97 Dec 12, 2024
3d4a3dc
fix interface
JerryChen97 Dec 13, 2024
bff73b2
change default.mixed -> default.mixed.legacy in workflow
JerryChen97 Dec 13, 2024
5bca45d
fix measurement test
JerryChen97 Dec 13, 2024
d50c0aa
rm legacy usage
JerryChen97 Dec 13, 2024
9f470a4
debug multiple interface issue
JerryChen97 Dec 13, 2024
636c351
reverse xfailed from https://github.com/PennyLaneAI/pennylane/pull/66…
JerryChen97 Dec 13, 2024
dcf62bb
skip mixed
JerryChen97 Dec 13, 2024
5a03c2e
include SparseHamiltonian
JerryChen97 Dec 14, 2024
759583f
black
JerryChen97 Dec 14, 2024
04eec82
fix doc sphinx
JerryChen97 Dec 14, 2024
461120d
black apply op
JerryChen97 Dec 14, 2024
06c6aeb
implemented apply_density_matrix
JerryChen97 Dec 14, 2024
90adfde
reformatted
JerryChen97 Dec 14, 2024
62d814e
Del the finite-shot DMMP: it makes no sense
JerryChen97 Dec 14, 2024
4528583
add param evo branch
JerryChen97 Dec 14, 2024
09b28b4
f
JerryChen97 Dec 14, 2024
2395b63
add register
JerryChen97 Dec 14, 2024
71b3611
del legacy tests
JerryChen97 Dec 14, 2024
5bcd5ac
del legacy test
JerryChen97 Dec 14, 2024
c321af0
del legacy test
JerryChen97 Dec 14, 2024
7cdb821
add docs [skip-ci]
JerryChen97 Dec 16, 2024
b371786
Merge branch 'master' into add-qubit_mixed/integration
JerryChen97 Dec 16, 2024
16878c5
improve stateprep; make test mitigate compatible
JerryChen97 Dec 16, 2024
eb7b6dc
deubg transpile test for new default mixed
JerryChen97 Dec 16, 2024
5757dd7
remember to keep the previous behaviour of initialzer!!!!
JerryChen97 Dec 16, 2024
2d7882b
format
JerryChen97 Dec 16, 2024
28646f5
reformat
JerryChen97 Dec 16, 2024
00b896f
Merge branch 'master' into add-qubit_mixed/integration
JerryChen97 Dec 16, 2024
cf1473c
format in new fashion
JerryChen97 Dec 16, 2024
03a276e
del unnecessary register
JerryChen97 Dec 16, 2024
c1a3b7a
add back the skipped tests
JerryChen97 Dec 16, 2024
b1d4c29
fix probs
JerryChen97 Dec 16, 2024
95383bc
better sol
JerryChen97 Dec 17, 2024
ae10f9f
reverse negative for very small eps
JerryChen97 Dec 17, 2024
3a7ad90
del unused sampling helpers
JerryChen97 Dec 17, 2024
42e9e4f
https://github.com/PennyLaneAI/pennylane/pull/6684#discussion_r188897…
JerryChen97 Dec 17, 2024
09ee6d3
del all the legacy (#6728)
JerryChen97 Dec 17, 2024
a4a5012
Merge branch 'add-qubit_mixed/integration' of https://github.com/Penn…
JerryChen97 Dec 17, 2024
1ae1d2c
https://github.com/PennyLaneAI/pennylane/pull/6684#discussion_r188898…
JerryChen97 Dec 17, 2024
717b5fb
https://github.com/PennyLaneAI/pennylane/pull/6684#discussion_r188898…
JerryChen97 Dec 17, 2024
3d41822
revert the probs change due to raised convern https://github.com/Penn…
JerryChen97 Dec 18, 2024
7a7713a
Merge remote-tracking branch upstream/master into add-qubit_mixed/int…
JerryChen97 Dec 18, 2024
2f89734
xfails
JerryChen97 Dec 18, 2024
18fd044
remove legacy usage
JerryChen97 Dec 18, 2024
5505250
comment improvement https://github.com/PennyLaneAI/pennylane/pull/668…
JerryChen97 Dec 18, 2024
42787cb
comment improvement https://github.com/PennyLaneAI/pennylane/pull/668…
JerryChen97 Dec 18, 2024
cf02861
Update tests/devices/qubit_mixed/test_qubit_mixed_measure.py
JerryChen97 Dec 18, 2024
bed0b3b
Merge branch 'add-qubit_mixed/integration' of https://github.com/Penn…
JerryChen97 Dec 18, 2024
0267dd4
add skip info
JerryChen97 Dec 19, 2024
6b9098d
add tests for measure to cover more branch
JerryChen97 Dec 19, 2024
acf1578
improve apply_density_matrix along with tests covering it
JerryChen97 Dec 19, 2024
08464fd
del unnecessary condition that only works for postselection
JerryChen97 Dec 19, 2024
4bd7bee
cure torch tests by splitting dtype into anotehr line
JerryChen97 Dec 19, 2024
91ac548
del re-imported measure
JerryChen97 Dec 19, 2024
df4d6fd
cover sparseH branch
JerryChen97 Dec 19, 2024
8df5c45
cover sampling partitioned shots
JerryChen97 Dec 19, 2024
fa1792c
cover simulate state_cache
JerryChen97 Dec 19, 2024
9d1f338
Apply suggestions from code review
JerryChen97 Dec 19, 2024
fc44256
pnp->np https://github.com/PennyLaneAI/pennylane/pull/6684#discussion…
JerryChen97 Dec 19, 2024
413f1c4
rm legacy word from commet
JerryChen97 Dec 19, 2024
b3a7b85
revert an unnecessary change
JerryChen97 Dec 19, 2024
3769eea
replace with DefaultQubitLegacy https://github.com/PennyLaneAI/pennyl…
JerryChen97 Dec 19, 2024
fd5be6b
revert an unnecessary change
JerryChen97 Dec 19, 2024
74a0d53
replace with DefaultQubitLegacy https://github.com/PennyLaneAI/pennyl…
JerryChen97 Dec 19, 2024
6d695dd
bring back the legacy meas tests and replace with DefaultQubitLegacy …
JerryChen97 Dec 19, 2024
b41911f
Merge branch 'master' into add-qubit_mixed/integration
JerryChen97 Dec 20, 2024
f1befce
revert the deletion. https://github.com/PennyLaneAI/pennylane/pull/66…
JerryChen97 Dec 20, 2024
dbb8e7d
https://github.com/PennyLaneAI/pennylane/pull/6684#discussion_r189299…
JerryChen97 Dec 20, 2024
bfd1370
https://github.com/PennyLaneAI/pennylane/pull/6684#discussion_r188902…
JerryChen97 Dec 20, 2024
be4e309
https://github.com/PennyLaneAI/pennylane/pull/6684#discussion_r188903…
JerryChen97 Dec 20, 2024
f8ef937
https://github.com/PennyLaneAI/pennylane/pull/6684#discussion_r189299…
JerryChen97 Dec 20, 2024
f9da8a1
get final state docstr https://github.com/PennyLaneAI/pennylane/pull/…
JerryChen97 Dec 20, 2024
78728e2
docstr https://github.com/PennyLaneAI/pennylane/pull/6684#discussion_…
JerryChen97 Dec 20, 2024
caa9123
simulate docstr https://github.com/PennyLaneAI/pennylane/pull/6684#di…
JerryChen97 Dec 20, 2024
3aa89fe
debug return types legacy
JerryChen97 Dec 20, 2024
8bd6c6e
https://github.com/PennyLaneAI/pennylane/pull/6684#discussion_r189307…
JerryChen97 Dec 20, 2024
c81f535
https://github.com/PennyLaneAI/pennylane/pull/6684#discussion_r189307…
JerryChen97 Dec 20, 2024
8a9b984
https://github.com/PennyLaneAI/pennylane/pull/6684#discussion_r189307…
JerryChen97 Dec 20, 2024
1aa735a
formatting
JerryChen97 Dec 20, 2024
57d8fba
no skip
JerryChen97 Dec 20, 2024
7324d40
res
JerryChen97 Dec 20, 2024
a0a1fc8
debugged https://github.com/PennyLaneAI/pennylane/pull/6684#discussio…
JerryChen97 Dec 20, 2024
d7aa59b
bug fixing
JerryChen97 Dec 20, 2024
6c8109e
Merge branch 'master' into add-qubit_mixed/integration
JerryChen97 Dec 20, 2024
00b7d66
Apply suggestions from code review
JerryChen97 Dec 20, 2024
a6db255
add tests to patch missing branch
JerryChen97 Dec 20, 2024
d61bca1
format
JerryChen97 Dec 20, 2024
b23ee95
pnp -> np. Debug.
JerryChen97 Dec 20, 2024
3eb1857
fix torch
JerryChen97 Dec 20, 2024
e434ead
cover default mixed
JerryChen97 Dec 20, 2024
600cc5c
Merge branch 'master' into add-qubit_mixed/integration
JerryChen97 Dec 20, 2024
3af37d5
format
JerryChen97 Dec 20, 2024
1e71547
format
JerryChen97 Dec 20, 2024
3505b95
Merge branch 'master' into add-qubit_mixed/integration
JerryChen97 Dec 30, 2024
04d202f
initial draft for new classical shadow
JerryChen97 Dec 30, 2024
dcb362d
Merge remote-tracking branch 'origin/add-qubit_mixed/integration' int…
JerryChen97 Dec 30, 2024
ac6d536
format
JerryChen97 Dec 30, 2024
8d71a5b
del unnecessary...
JerryChen97 Dec 30, 2024
6fb8b73
tol=0 for assert not allclose
JerryChen97 Dec 30, 2024
3cffe67
formated
JerryChen97 Dec 30, 2024
535b7d0
add partitioned test
JerryChen97 Dec 30, 2024
085ca40
format
JerryChen97 Dec 30, 2024
69ab7cf
recover the (mistakenly deleted) default mixed tests
JerryChen97 Dec 30, 2024
af9be8f
name..
JerryChen97 Dec 30, 2024
af26cf4
bring back the missing tests
JerryChen97 Dec 30, 2024
d7c3199
del re-import
JerryChen97 Dec 30, 2024
7a412fe
add test for legacy_device
JerryChen97 Dec 30, 2024
aa92c0e
silence pylint
JerryChen97 Dec 30, 2024
62426a7
pylint
JerryChen97 Dec 30, 2024
0f0ccf2
Merge branch 'master' into add-qubit_mixed/integration
JerryChen97 Dec 30, 2024
1272150
Merge branch 'master' into add-qubit_mixed/integration
JerryChen97 Dec 31, 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
33 changes: 5 additions & 28 deletions doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,43 +133,20 @@
[(#6396)](https://github.com/PennyLaneAI/pennylane/pull/6396)


<h4>New API for Qubit Mixed</h4>

* Added `qml.devices.qubit_mixed` module for mixed-state qubit device support [(#6379)](https://github.com/PennyLaneAI/pennylane/pull/6379). This module introduces an `apply_operation` helper function that features:

* Two density matrix contraction methods using `einsum` and `tensordot`

* Optimized handling of special cases including: Diagonal operators, Identity operators, CX (controlled-X), Multi-controlled X gates, Grover operators

* Added submodule 'initialize_state' featuring a `create_initial_state` function for initializing a density matrix from `qml.StatePrep` operations or `qml.QubitDensityMatrix` operations.
[(#6503)](https://github.com/PennyLaneAI/pennylane/pull/6503)

* Added support for constructing `BoseWord` and `BoseSentence`, similar to `FermiWord` and `FermiSentence`.
[(#6518)](https://github.com/PennyLaneAI/pennylane/pull/6518)

* Added method `preprocess` to the `QubitMixed` device class to preprocess the quantum circuit before execution. Necessary non-intrusive interfaces changes to class init method were made along the way to the `QubitMixed` device class to support new API feature.
* New API for `default_mixed`: migrate the old `DefaultMixed` to follow our new device API standard. Basically, previous class `qml.devices.default_mixed.DefaultMixed` was refactored. Users will not experience any differences in principle, but for some users who delved deep into PennyLane codebase and happened to use certain deprecated methods or properties of the legacy code this might introduce breaking changes.
JerryChen97 marked this conversation as resolved.
Show resolved Hide resolved
[(#6379)](https://github.com/PennyLaneAI/pennylane/pull/6379)
[(#6503)](https://github.com/PennyLaneAI/pennylane/pull/6503)
[(#6601)](https://github.com/PennyLaneAI/pennylane/pull/6601)

* Added a second class `DefaultMixedNewAPI` to the `qml.devices.qubit_mixed` module, which is to be the replacement of legacy `DefaultMixed` which for now to hold the implementations of `preprocess` and `execute` methods.
[(#6607)](https://github.com/PennyLaneAI/pennylane/pull/6607)

* Added submodule `devices.qubit_mixed.measure` as a necessary step for the new API, featuring a `measure` function for measuring qubits in mixed-state devices.
[(#6637)](https://github.com/PennyLaneAI/pennylane/pull/6637)

* Added submodule `devices.qubit_mixed.simulate` as a necessary step for the new API,
featuring a `simulate` function for simulating mixed states in analytic mode.
[(#6618)](https://github.com/PennyLaneAI/pennylane/pull/6618)

* Added submodule `devices.qubit_mixed.sampling` as a necessary step for the new API, featuring functions `sample_state`, `measure_with_samples` and `sample_probs` for sampling qubits in mixed-state devices.
[(#6639)](https://github.com/PennyLaneAI/pennylane/pull/6639)

* Added support `qml.Snapshot` operation in `qml.devices.qubit_mixed.apply_operation`.
[(#6659)](https://github.com/PennyLaneAI/pennylane/pull/6659)

* Implemented the finite-shot branch of `devices.qubit_mixed.simulate`. Now, the
new device API of `default_mixed` should be able to take the stochastic arguments
such as `shots`, `rng` and `prng_key`.
[(#6665)](https://github.com/PennyLaneAI/pennylane/pull/6665)
[(#6665)](https://github.com/PennyLaneAI/pennylane/pull/6665)
[(#6684)](https://github.com/PennyLaneAI/pennylane/pull/6684)

* Added `christiansen_mapping()` function to map `BoseWord` and `BoseSentence` to qubit operators, using christiansen mapping.
[(#6623)](https://github.com/PennyLaneAI/pennylane/pull/6623)
Expand Down
10 changes: 9 additions & 1 deletion pennylane/devices/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
ExecutionConfig
MCMConfig
Device
DefaultMixed
DefaultQubit
DefaultTensor
NullQubit
Expand Down Expand Up @@ -134,6 +135,13 @@ def execute(self, circuits, execution_config = qml.devices.DefaultExecutionConfi
.. automodule:: pennylane.devices.qubit


Qubit Mixed-State Simulation Tools
----------------------

.. currentmodule:: pennylane.devices.qubit_mixed
.. automodule:: pennylane.devices.qubit_mixed


Qutrit Mixed-State Simulation Tools
-----------------------------------

Expand All @@ -153,7 +161,7 @@ def execute(self, circuits, execution_config = qml.devices.DefaultExecutionConfi
# DefaultTensor is not imported here to avoid warnings
# from quimb in case it is installed on the system.
from .default_gaussian import DefaultGaussian
from .default_mixed import DefaultMixed
from .default_mixed import DefaultMixed, DefaultMixedLegacy
from .default_clifford import DefaultClifford
from .default_tensor import DefaultTensor
from .null_qubit import NullQubit
Expand Down
4 changes: 2 additions & 2 deletions pennylane/devices/_legacy_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ class _LegacyMeta(abc.ABCMeta):
checking the instance of a device against a Legacy device type.

To illustrate, if "dev" is of type LegacyDeviceFacade, and a user is
checking "isinstance(dev, qml.devices.DefaultMixed)", the overridden
checking "isinstance(dev, qml.devices.DefaultMixedLegacy)", the overridden
"__instancecheck__" will look behind the facade, and will evaluate instead
"isinstance(dev.target_device, qml.devices.DefaultMixed)"
"isinstance(dev.target_device, qml.devices.DefaultMixedLegacy)"
"""

def __instancecheck__(cls, instance):
Expand Down
26 changes: 13 additions & 13 deletions pennylane/devices/default_mixed.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"Sum",
}

operations_mixed = {
operations = {
"Identity",
"Snapshot",
"BasisState",
Expand Down Expand Up @@ -175,7 +175,7 @@

def stopping_condition(op: qml.operation.Operator) -> bool:
"""Specify whether an Operator object is supported by the device."""
expected_set = operations_mixed | {"Snapshot"} | channels
expected_set = operations | {"Snapshot"} | channels
return op.name in expected_set


Expand Down Expand Up @@ -204,8 +204,7 @@
tolerance = 1e-10


# !TODO: when removing this class, rename operations_mixed back to operations
class DefaultMixed(QubitDevice):
class DefaultMixedLegacy(QubitDevice):
"""Default qubit device for performing mixed-state computations in PennyLane.

.. warning::
Expand Down Expand Up @@ -235,12 +234,13 @@
"""

name = "Default mixed-state qubit PennyLane plugin"
short_name = "default.mixed"
short_name = "default.mixed.legacy"
pennylane_requires = __version__
version = __version__
author = "Xanadu Inc."

operations = operations_mixed
# copy the operations from external
operations = operations.copy()

_reshape = staticmethod(qnp.reshape)
_flatten = staticmethod(qnp.flatten)
Expand Down Expand Up @@ -325,10 +325,10 @@
capabilities.update(
returns_state=True,
passthru_devices={
"autograd": "default.mixed",
"tf": "default.mixed",
"torch": "default.mixed",
"jax": "default.mixed",
"autograd": "default.mixed.legacy",
"tf": "default.mixed.legacy",
"torch": "default.mixed.legacy",
"jax": "default.mixed.legacy",
},
)
return capabilities
Expand Down Expand Up @@ -731,7 +731,7 @@

else:
raise qml.DeviceError(
f"Snapshots of {type(measurement)} are not yet supported on default.mixed"
f"Snapshots of {type(measurement)} are not yet supported on default.mixed.legacy"
)

self._state = pre_rotated_state
Expand Down Expand Up @@ -853,7 +853,7 @@
return super().execute(circuit, **kwargs)

@debug_logger
def apply(self, operations, rotations=None, **kwargs):

Check notice on line 856 in pennylane/devices/default_mixed.py

View check run for this annotation

codefactor.io / CodeFactor

pennylane/devices/default_mixed.py#L856

Redefining name 'operations' from outer scope (line 94) (redefined-outer-name)
rotations = rotations or []

# apply the circuit operations
Expand Down Expand Up @@ -882,7 +882,7 @@

@simulator_tracking
@single_tape_support
class DefaultMixedNewAPI(Device):
class DefaultMixed(Device):
r"""A PennyLane Python-based device for mixed-state qubit simulation.

Args:
Expand Down Expand Up @@ -918,7 +918,7 @@
wires=None,
shots=None,
seed="global",
# The following parameters are inherited from DefaultMixed
# The following parameters are inherited from DefaultMixedLegacy
readout_prob=None,
) -> None:

Expand Down
4 changes: 2 additions & 2 deletions pennylane/devices/legacy_facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ class LegacyDeviceFacade(Device):
Args:
device (qml.device.LegacyDevice): a device that follows the legacy device interface.

>>> from pennylane.devices import DefaultMixed, LegacyDeviceFacade
>>> legacy_dev = DefaultMixed(wires=2)
>>> from pennylane.devices import DefaultMixedLegacy, LegacyDeviceFacade
>>> legacy_dev = DefaultMixedLegacy(wires=2)
>>> new_dev = LegacyDeviceFacade(legacy_dev)
>>> new_dev.preprocess()
(TransformProgram(legacy_device_batch_transform, legacy_device_expand_fn, defer_measurements),
JerryChen97 marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
2 changes: 1 addition & 1 deletion pennylane/devices/qubit_mixed/apply_operation.py
JerryChen97 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def apply_operation_tensordot(
kraus = [mat]
kraus = [math.reshape(k, kraus_shape) for k in kraus]
kraus = math.array(kraus) # Necessary for Jax
# Small trick: following the same logic as in the legacy DefaultMixed._apply_channel_tensordot, here for the contraction on the right side we also directly contract the col ids of channel instead of rows for simplicity. This can also save a step of transposing the kraus operators.
# Small trick: following the same logic as in the legacy DefaultMixedLegacy._apply_channel_tensordot, here for the contraction on the right side we also directly contract the col ids of channel instead of rows for simplicity. This can also save a step of transposing the kraus operators.
JerryChen97 marked this conversation as resolved.
Show resolved Hide resolved
row_wires_list = [w + is_state_batched for w in channel_wires.tolist()]
col_wires_list = [w + num_wires for w in row_wires_list]
channel_col_ids = list(range(-num_ch_wires, 0))
Expand Down
28 changes: 28 additions & 0 deletions pennylane/devices/qubit_mixed/measure.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,38 @@ def get_measurement_function(
return calculate_probability
if isinstance(measurementprocess, VarianceMP):
return calculate_variance
return state_diagonalizing_gates

raise NotImplementedError


def state_diagonalizing_gates( # pylint: disable=unused-argument
measurementprocess: StateMeasurement,
state: TensorLike,
is_state_batched: bool = False,
readout_errors: list[Callable] = None,
) -> TensorLike:
"""Apply a measurement to state when the measurement process has an observable with diagonalizing gates.

Args:
measurementprocess (StateMeasurement): measurement to apply to the state
state (TensorLike): state to apply the measurement to
is_state_batched (bool): whether the state is batched or not
readout_errors (List[Callable]): List of channels to apply to each wire being measured
to simulate readout errors.

Returns:
TensorLike: the result of the measurement
"""
for op in measurementprocess.diagonalizing_gates():
state = apply_operation(op, state, is_state_batched=is_state_batched)

num_wires = _get_num_wires(state, is_state_batched)
wires = Wires(range(num_wires))
flattened_state = _reshape_state_as_matrix(state, num_wires)
return measurementprocess.process_density_matrix(flattened_state, wires)


def measure(
measurementprocess: MeasurementProcess,
state: TensorLike,
Expand Down
23 changes: 3 additions & 20 deletions pennylane/devices/qubit_mixed/simulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,14 @@
from numpy.random import default_rng

import pennylane as qml
from pennylane.math.interface_utils import get_canonical_interface_name
from pennylane.typing import Result

from .apply_operation import apply_operation
from .initialize_state import create_initial_state
from .measure import measure
from .sampling import measure_with_samples

INTERFACE_TO_LIKE = {
# map interfaces known by autoray to themselves
"numpy": "numpy",
"autograd": "autograd",
"jax": "jax",
"torch": "torch",
"tensorflow": "tensorflow",
# map non-standard interfaces to those known by autoray
"auto": None,
"scipy": "numpy",
"jax-jit": "jax",
"jax-python": "jax",
"JAX": "jax",
"pytorch": "torch",
"tf": "tensorflow",
"tensorflow-autograph": "tensorflow",
"tf-autograph": "tensorflow",
}


def get_final_state(circuit, debugger=None, interface=None, **kwargs):
"""
Expand All @@ -65,8 +47,9 @@ def get_final_state(circuit, debugger=None, interface=None, **kwargs):
if len(circuit) > 0 and isinstance(circuit[0], qml.operation.StatePrepBase):
prep = circuit[0]

interface = get_canonical_interface_name(interface)
state = create_initial_state(
sorted(circuit.op_wires), prep, like=INTERFACE_TO_LIKE[interface] if interface else None
sorted(circuit.op_wires), prep, like=interface.get_like()
)

# initial state is batched only if the state preparation (if it exists) is batched
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"default.qubit = pennylane.devices:DefaultQubit",
"default.gaussian = pennylane.devices:DefaultGaussian",
"default.mixed = pennylane.devices.default_mixed:DefaultMixed",
"default.mixed.legacy = pennylane.devices.default_mixed:DefaultMixedLegacy",
"reference.qubit = pennylane.devices.reference_qubit:ReferenceQubit",
"null.qubit = pennylane.devices.null_qubit:NullQubit",
"default.qutrit = pennylane.devices.default_qutrit:DefaultQutrit",
Expand Down
2 changes: 1 addition & 1 deletion tests/devices/modifiers/test_all_modifiers.py
PietropaoloFrisoni marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_error_on_old_interface(self, modifier):
"""Test that a ValueError is raised is called on something that is not a subclass of Device."""

with pytest.raises(ValueError, match=f"{modifier.__name__} only accepts"):
modifier(qml.devices.DefaultMixed)
modifier(qml.devices.DefaultMixedLegacy)

def test_adds_to_applied_modifiers_private_property(self, modifier):
"""Test that the modifier is added to the `_applied_modifiers` property."""
Expand Down
Loading