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

Add tutorial for qubit tapering #413

Merged
merged 295 commits into from
May 16, 2022
Merged
Show file tree
Hide file tree
Changes from 250 commits
Commits
Show all changes
295 commits
Select commit Hold shift + click to select a range
0900693
Merge branch 'master' into dev
actions-user Aug 17, 2021
cde64b0
update requirements
josh146 Aug 17, 2021
6571592
Merge branch 'master' into dev
actions-user Aug 23, 2021
8fd0fee
Merge branch 'master' into dev
actions-user Aug 25, 2021
af0ec16
Merge branch 'master' into dev
actions-user Aug 27, 2021
404273d
Merge branch 'master' into dev
actions-user Sep 7, 2021
6ee9ad5
Update requirements.txt (#329)
antalszava Sep 8, 2021
0b1a18f
Merge branch 'master' into dev
actions-user Sep 13, 2021
81c31f6
Add more `plt.show` calls in the l2l demo (#331)
antalszava Sep 15, 2021
a160a4f
diff_method=None (#332)
antalszava Sep 15, 2021
af04b6b
Added a note to Quantum Volume Demo (#335)
Jaybsoni Sep 16, 2021
e4e3bf1
Merge branch 'master' into dev
actions-user Sep 16, 2021
a674e4e
Merge branch 'master' into dev
actions-user Sep 20, 2021
7bdc74d
Update requirements.txt
josh146 Sep 21, 2021
01608f1
Update requirements.txt
josh146 Sep 21, 2021
abd0835
Merge branch 'master' into dev
actions-user Sep 21, 2021
f533042
Add dev branch
josh146 Sep 21, 2021
9de9299
Merge branch 'master' into dev
actions-user Sep 22, 2021
9d177c8
Merge branch 'master' into dev
actions-user Sep 23, 2021
18a5e67
Update demos to make use of the new qml.sample and qml.expval(H) func…
Jaybsoni Sep 29, 2021
b285bb9
Merge branch 'master' into dev
actions-user Sep 29, 2021
a45b358
Merge branch 'master' into dev
actions-user Sep 30, 2021
95b41ad
Merge branch 'master' into dev
actions-user Oct 1, 2021
9be4a29
Merge branch 'master' into dev
actions-user Oct 4, 2021
73c01f4
Update tutorial_gbs.py (#351)
antalszava Oct 12, 2021
04d28bf
pin pyparsing (#358)
antalszava Oct 25, 2021
efe439d
Merge `master` into `dev` (#362)
antalszava Oct 28, 2021
6a67239
Update templates access and remove template decorator (#360)
rmoyard Nov 1, 2021
e18a809
Remove use of the init module everywhere (#361)
mariaschuld Nov 1, 2021
d0a8af7
Requires grad updates (#364)
antalszava Nov 2, 2021
dc465d1
requires_grad=True (#366)
antalszava Nov 3, 2021
df3f8c4
use approx='block-diag' instead of diag_approx=False (#365)
antalszava Nov 3, 2021
14ff0c8
increase the number of epochs (#368)
antalszava Nov 3, 2021
92cd1d3
last bit of requires_grad=True changes (#370)
antalszava Nov 4, 2021
5996467
Prepare `dev` to be merged into `master` (#373)
antalszava Nov 9, 2021
8d175ad
Merge branch 'master' into dev
josh146 Nov 9, 2021
ef2b4cb
Merge branch 'master' into dev
actions-user Nov 9, 2021
e22e83b
update requirements
josh146 Nov 9, 2021
84948df
Merge branch 'master' into dev
actions-user Nov 9, 2021
1e0d5d5
Merge branch 'master' into dev
actions-user Nov 10, 2021
15d3cd0
Merge branch 'master' into dev
actions-user Nov 12, 2021
ffb92ff
Merge branch 'master' into dev
actions-user Nov 16, 2021
c43afd4
Merge branch 'master' into dev
actions-user Nov 18, 2021
3dcb56b
Merge branch 'master' into dev
actions-user Nov 23, 2021
911d1ee
Merge branch 'master' into dev
actions-user Nov 23, 2021
7bb3701
Merge branch 'master' into dev
actions-user Nov 23, 2021
8c2f38b
Merge branch 'master' into dev
actions-user Nov 23, 2021
14d6a0b
Merge branch 'master' into dev
actions-user Nov 24, 2021
db1b07c
Increase cache (`dev`) (#385)
antalszava Nov 29, 2021
f66ad4c
merge master
josh146 Nov 30, 2021
e2f1ad8
Stop importing QNode from beta folder in mitigation demo (#392)
trbromley Nov 30, 2021
c259de1
Update the backprop demo to work with the latest PL master (#391)
josh146 Nov 30, 2021
d4d9f90
Fix jax demo to work with the latest version of PennyLane (#393)
josh146 Dec 1, 2021
5e289a4
Merge branch 'master' into dev
actions-user Dec 2, 2021
cdc3c5c
`dev` branch fixes (#396)
antalszava Dec 2, 2021
4d327d1
spectrum -> qnode_spectrum (#397)
antalszava Dec 7, 2021
e2af147
use plt.show for the general parameter shift demo (#400)
antalszava Dec 8, 2021
01af7b7
Fix demo diffs with PennyLane release v0.20.0 (#402)
dime10 Dec 9, 2021
7e67489
use draw_mpl method and set device expansion (#398)
albi3ro Dec 9, 2021
cabe82a
Pin qiskit==0.32.0 temporarily (`dev`) (#404)
antalszava Dec 9, 2021
1048691
Revert "Pin qiskit==0.32.0 temporarily (`dev`) (#404)" (#406)
antalszava Dec 10, 2021
45021e3
Merge branch 'master' into dev
actions-user Dec 10, 2021
9c97b23
qhack
josh146 Dec 13, 2021
327bef3
update SF dependency
josh146 Dec 13, 2021
7cdfbec
fix
josh146 Dec 13, 2021
b21d136
fix
josh146 Dec 13, 2021
4873c79
fix
josh146 Dec 13, 2021
85af5a2
fix
josh146 Dec 13, 2021
446125b
Make demos using Forest non-automatically run (#408)
antalszava Dec 13, 2021
c60af50
Update requirements.txt
josh146 Dec 14, 2021
deb1902
Merge branch 'master' into dev
actions-user Dec 14, 2021
89da2a0
Update requirements
josh146 Dec 14, 2021
199f7ed
Merge branch 'master' into dev
actions-user Dec 23, 2021
dd07ab3
add qubit tapering tutorial
soranjh Dec 23, 2021
198cdd2
add background theory
soranjh Dec 23, 2021
532168a
update rst tile
soranjh Dec 23, 2021
b1fa7aa
correct refs
soranjh Dec 23, 2021
fdac905
add optimal sector
soranjh Jan 6, 2022
0c7f089
modify introduction
soranjh Jan 7, 2022
8c586af
modify the unitary operator text
soranjh Jan 7, 2022
d942aa4
add energy calculations
soranjh Jan 7, 2022
5fa9ecb
fix build issues
soranjh Jan 7, 2022
c98f864
add ref and correct typo
soranjh Jan 7, 2022
c0dae66
add HeH cation
soranjh Jan 12, 2022
8800350
add state and HF energy
soranjh Jan 12, 2022
d6886d1
add vqe simulation
soranjh Jan 12, 2022
82168bf
correct line lengths and typos
soranjh Jan 12, 2022
6e99ca3
add section titles
soranjh Jan 12, 2022
dca801f
add image
soranjh Jan 13, 2022
24cb581
rearrange text and create intro
soranjh Jan 14, 2022
e17293b
correct equation
soranjh Jan 14, 2022
19e2f1c
correct math equation
soranjh Jan 14, 2022
682c1d1
apply suggestions from code review
soranjh Jan 19, 2022
1e39c2c
apply review comments
soranjh Jan 19, 2022
5a81978
add example to intro
soranjh Jan 20, 2022
2aebac8
modify tapering process in intro
soranjh Jan 20, 2022
92326eb
add imports
soranjh Jan 20, 2022
e26c2e1
remove qubit coupled cluster
soranjh Jan 24, 2022
a573edf
apply suggestions from code review
soranjh Jan 25, 2022
a0df2d2
explain eigenvalue sector with more details
soranjh Jan 25, 2022
d4ca3af
modify example hamiltonian
soranjh Jan 25, 2022
22c706a
correct math typo
soranjh Jan 25, 2022
4546cfd
add review comments
soranjh Jan 26, 2022
666c3cf
correct Hamiltonian symbol
soranjh Jan 26, 2022
f833052
fit line length
soranjh Jan 27, 2022
dae6b97
Merge branch 'master' into dev
actions-user Jan 27, 2022
b0f740f
merge branch 'dev' into qubit_tapering
soranjh Jan 27, 2022
ddbf35f
Merge branch 'master' into dev
actions-user Feb 1, 2022
d77c122
Specify `diff_method=None` in `tutorial_jax_transformations.py` (#418)
antalszava Feb 1, 2022
49e779f
Merge branch 'master' into dev
actions-user Feb 2, 2022
61c59de
Merge branch 'master' into dev
actions-user Feb 2, 2022
97618aa
Merge branch 'master' into dev
actions-user Feb 2, 2022
fee4d6a
Update requirements.txt
josh146 Feb 8, 2022
454d088
Update requirements.txt
josh146 Feb 8, 2022
ed2afa8
Merge branch 'master' into dev
actions-user Feb 8, 2022
088233f
update requirements
josh146 Feb 8, 2022
c40b1ab
Merge branch 'master' into dev
actions-user Feb 23, 2022
1404b35
pin markupsafe==2.0.1 (#433)
antalszava Feb 28, 2022
60f8ff2
Merge branch 'master' into dev
actions-user Feb 28, 2022
94bcda4
Updated demo to avoid the soon to be deprecated qml.finite_diff func …
Jaybsoni Feb 28, 2022
4c7376c
Merge branch 'master' into dev
actions-user Mar 1, 2022
722dc59
add review comments
soranjh Mar 1, 2022
bb51a82
Merge branch 'dev' into qubit_tapering
soranjh Mar 1, 2022
e1b46b1
Merge branch 'master' into dev
actions-user Mar 2, 2022
6d2203a
Merge branch 'master' into dev
actions-user Mar 3, 2022
3fac5e3
Change querying matrices as per the new API (#437)
antalszava Mar 7, 2022
a339213
update circuit drawing (#438)
albi3ro Mar 8, 2022
e78390d
Merge branch 'master' into dev
actions-user Mar 9, 2022
229118c
Update tutorial_vqt.py (#440)
dime10 Mar 9, 2022
41eb152
Use `cirq_pasqal` (#443)
antalszava Mar 10, 2022
cd606db
Qiskit Aer NoiseModel will be updating the .from_backend() method to …
Jaybsoni Mar 10, 2022
0a4225a
Update quantum volume Demo with instructions to configure IBM Q accou…
Jaybsoni Mar 10, 2022
d040d1f
Apply suggestions from code review
josh146 Mar 15, 2022
75984c8
Merge branch 'master' into dev
actions-user Mar 15, 2022
9131c4c
Update requirements
josh146 Mar 15, 2022
afea2b7
Merge branch 'master' into dev
actions-user Mar 18, 2022
e2de67c
Merge branch 'master' into dev
actions-user Mar 21, 2022
0a9aea6
Merge branch 'master' into dev
actions-user Mar 22, 2022
b1a25f7
Merge branch 'master' into dev
actions-user Mar 22, 2022
ef5539f
Merge branch 'master' into dev
actions-user Mar 28, 2022
e1b3517
update SF version
josh146 Mar 28, 2022
582882d
Merge branch 'master' into dev
actions-user Mar 28, 2022
94d0a8c
Merge branch 'master' into dev
actions-user Mar 29, 2022
9276fb0
Merge branch 'master' into dev
actions-user Mar 30, 2022
632e677
Update (#465)
rmoyard Apr 19, 2022
30d636c
Update `requirements.txt` (#466)
antalszava Apr 19, 2022
ec7a68c
Update quantum volume demonstration as per drawing updates (#471)
antalszava Apr 20, 2022
2978e07
Update spsa (#464)
rmoyard Apr 20, 2022
1cfe62c
Fix QChem related demo errors, get latest Lightning & pin Cirq (#467)
antalszava Apr 20, 2022
fd43868
set requires_grad as false for hamiltonian coeffs (#473)
soranjh Apr 21, 2022
f86183e
Merge branch 'dev' into qubit_tapering
soranjh Apr 21, 2022
3b32704
Merge branch 'dev' into qubit_tapering
soranjh Apr 21, 2022
828646f
use qchem
soranjh Apr 21, 2022
aa084fb
Merge branch 'qubit_tapering' of https://github.com/PennyLaneAI/qml i…
soranjh Apr 21, 2022
9e13ac5
add code review comments
soranjh Apr 22, 2022
5ef596a
Remove QChem in the text (#474)
soranjh Apr 22, 2022
5ad7254
Update mitiq demo drawing (#476)
antalszava Apr 22, 2022
0b8d5cb
stable -> latest (#477)
antalszava Apr 22, 2022
d9122c0
Merge branch 'dev' into qubit_tapering
antalszava Apr 22, 2022
81c82dc
update cross ref
soranjh Apr 22, 2022
0852d5a
Apply suggestions from code review
soranjh Apr 22, 2022
7da9f3e
use qml.eigvals
soranjh Apr 22, 2022
948c145
Update dependencies in quantum chemistry tutorial (#475)
soranjh Apr 22, 2022
eb7eff1
Merge branch 'dev' into qubit_tapering
soranjh Apr 22, 2022
b88b0a4
add new image
soranjh Apr 22, 2022
27fb62c
Apply suggestions from code review
josh146 Apr 25, 2022
ee1694b
Merge branch 'master' into dev
josh146 Apr 25, 2022
205c10c
resource class & parallel
antalszava Apr 26, 2022
02c916b
no parallel
antalszava Apr 26, 2022
1761dfa
Merge branch 'master' into dev
antalszava Apr 26, 2022
6812e39
Merge branch 'master' into dev
josh146 Apr 26, 2022
4dbc21f
increment requirements
josh146 Apr 26, 2022
fb4ec29
merge dev into qubit_tapering
soranjh Apr 26, 2022
26ee38f
correct qchem crossrefs
soranjh Apr 26, 2022
419c188
update the date
soranjh Apr 26, 2022
2d82867
update posted date
soranjh Apr 27, 2022
cb52a3a
correct links
soranjh Apr 27, 2022
7806f9b
Apply suggestions from code review
soranjh Apr 27, 2022
5481892
remove blank lines
soranjh Apr 27, 2022
8535e47
Merge branch 'dev' of github.com:PennyLaneAI/qml into dev
antalszava Apr 27, 2022
a1c5baa
modify format
soranjh Apr 29, 2022
eefbf45
add dots
soranjh Apr 29, 2022
11a0b08
Merge branch 'dev' into qubit_tapering
soranjh Apr 29, 2022
ea58da3
correct fci energy
soranjh Apr 29, 2022
33c9639
Merge branch 'qubit_tapering' of https://github.com/PennyLaneAI/qml i…
soranjh Apr 29, 2022
6e99682
correct eigvals
soranjh Apr 29, 2022
1d7e0f0
add qubit tapering tutorial
soranjh Dec 23, 2021
93ae1b1
add background theory
soranjh Dec 23, 2021
471a752
update rst tile
soranjh Dec 23, 2021
4d075cc
correct refs
soranjh Dec 23, 2021
fa5c69f
add optimal sector
soranjh Jan 6, 2022
6ec8eb8
modify introduction
soranjh Jan 7, 2022
917927e
modify the unitary operator text
soranjh Jan 7, 2022
20be896
add energy calculations
soranjh Jan 7, 2022
48164e7
fix build issues
soranjh Jan 7, 2022
7bb4e81
add ref and correct typo
soranjh Jan 7, 2022
a1dafca
add HeH cation
soranjh Jan 12, 2022
e806855
add state and HF energy
soranjh Jan 12, 2022
2195b3a
add vqe simulation
soranjh Jan 12, 2022
567facd
correct line lengths and typos
soranjh Jan 12, 2022
fb8a383
add section titles
soranjh Jan 12, 2022
424e95f
add image
soranjh Jan 13, 2022
e1da774
rearrange text and create intro
soranjh Jan 14, 2022
3284050
correct equation
soranjh Jan 14, 2022
ca4b366
correct math equation
soranjh Jan 14, 2022
58e078f
apply suggestions from code review
soranjh Jan 19, 2022
1f693d5
apply review comments
soranjh Jan 19, 2022
f084008
add example to intro
soranjh Jan 20, 2022
34df8f2
modify tapering process in intro
soranjh Jan 20, 2022
0132cfe
add imports
soranjh Jan 20, 2022
ad34b78
remove qubit coupled cluster
soranjh Jan 24, 2022
aa9949e
apply suggestions from code review
soranjh Jan 25, 2022
c34b76e
explain eigenvalue sector with more details
soranjh Jan 25, 2022
2499f1d
modify example hamiltonian
soranjh Jan 25, 2022
890fa21
correct math typo
soranjh Jan 25, 2022
7ca8c0d
add review comments
soranjh Jan 26, 2022
69c0955
correct Hamiltonian symbol
soranjh Jan 26, 2022
03b6f9f
fit line length
soranjh Jan 27, 2022
4d07b14
add review comments
soranjh Mar 1, 2022
44cbe55
use qchem
soranjh Apr 21, 2022
8abc5db
add code review comments
soranjh Apr 22, 2022
bce62c0
update cross ref
soranjh Apr 22, 2022
5bf7561
Apply suggestions from code review
soranjh Apr 22, 2022
71fe74d
use qml.eigvals
soranjh Apr 22, 2022
b7decd3
add new image
soranjh Apr 22, 2022
5fb480b
correct qchem crossrefs
soranjh Apr 26, 2022
ac23c3e
update the date
soranjh Apr 26, 2022
f004fc1
update posted date
soranjh Apr 27, 2022
8137dd6
correct links
soranjh Apr 27, 2022
3b8fd64
Apply suggestions from code review
soranjh Apr 27, 2022
7736969
remove blank lines
soranjh Apr 27, 2022
cc53bb2
modify format
soranjh Apr 29, 2022
0fea8dd
add dots
soranjh Apr 29, 2022
8bb54ad
correct fci energy
soranjh Apr 29, 2022
cbeec34
correct eigvals
soranjh Apr 29, 2022
7c53218
Merge branch 'qubit_tapering' of https://github.com/PennyLaneAI/qml i…
soranjh May 4, 2022
8ffc725
update requirements
soranjh May 4, 2022
3e8863d
Update date on demonstrations/tutorial_qubit_tapering.py
CatalinaAlbornoz May 13, 2022
f9322ac
Add Diff HF demo as related demo on demonstrations/tutorial_qubit_tap…
CatalinaAlbornoz May 13, 2022
3276225
Correct typo on demonstrations/tutorial_qubit_tapering.py
CatalinaAlbornoz May 13, 2022
3ebcecc
Add bio to demonstrations/tutorial_qubit_tapering.py
CatalinaAlbornoz May 13, 2022
5592a66
Merge branch 'master' into qubit_tapering
CatalinaAlbornoz May 13, 2022
3478711
Update "about the author" in demonstrations/tutorial_qubit_tapering.py
CatalinaAlbornoz May 13, 2022
1b2266e
Update about the author in demonstrations/tutorial_qubit_tapering.py
CatalinaAlbornoz May 13, 2022
b8f8900
Update about the author in demonstrations/tutorial_qubit_tapering.py
CatalinaAlbornoz May 13, 2022
8f0d16c
Update about the author demonstrations/tutorial_qubit_tapering.py
CatalinaAlbornoz May 13, 2022
4a7ef00
Update about the author in demonstrations/tutorial_qubit_tapering.py
CatalinaAlbornoz May 13, 2022
b6336da
Link to VQE tutorial on demonstrations/tutorial_qubit_tapering.py
CatalinaAlbornoz May 16, 2022
9406a32
Add link to molecular hamiltonian demo on demonstrations/tutorial_qub…
CatalinaAlbornoz May 16, 2022
cdfb8f6
Update author in demonstrations/tutorial_qubit_tapering.py
CatalinaAlbornoz May 16, 2022
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
Binary file added demonstrations/qubit_tapering/qubit_tapering.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
285 changes: 285 additions & 0 deletions demonstrations/tutorial_qubit_tapering.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,285 @@
r"""

Qubit tapering
==============

.. meta::
:property="og:description": Learn how to taper off qubits
:property="og:image": https://pennylane.ai/qml/_images/ qubit_tapering.png

.. related::
tutorial_quantum_chemistry Quantum chemistry with PennyLane
tutorial_vqe A brief overview of VQE
tutorial_givens_rotations Givens rotations for quantum chemistry
tutorial_adaptive_circuits Adaptive circuits for quantum chemistry

CatalinaAlbornoz marked this conversation as resolved.
Show resolved Hide resolved

*Author: PennyLane dev team. Posted: 29 April 2022. Last updated: 29 April 2022*
CatalinaAlbornoz marked this conversation as resolved.
Show resolved Hide resolved

The performance of variational quantum algorithms is considerably limited by the number of qubits
required to represent wave functions. In the context of quantum chemistry, this
limitation hinders the treatment of large molecules with algorithms such as the variational quantum
eigensolver (VQE). Several approaches have been developed to reduce the qubit requirements for
CatalinaAlbornoz marked this conversation as resolved.
Show resolved Hide resolved
quantum chemistry calculations. In this tutorial, we demonstrate the symmetry-based qubit
tapering approach which allows reducing the number of qubits required to perform molecular quantum
simulations based on the :math:`\mathbb{Z}_2` symmetries present in molecular Hamiltonians
[#bravyi2017]_ [#setia2019]_.
obliviateandsurrender marked this conversation as resolved.
Show resolved Hide resolved

A molecular Hamiltonian in the qubit basis can be expressed as a linear combination of Pauli words
as

.. math:: H = \sum_{i=1}^r h_i P_i,

where :math:`h_i` is a real coefficient and :math:`P_i` is a tensor product of Pauli and
identity operators acting on :math:`M` qubits

.. math:: P_i \in \pm \left \{ I, X, Y, Z \right \} ^ {\bigotimes M}.

The main idea in the symmetry-based qubit tapering approach is to find a unitary operator :math:`U`
that transforms :math:`H` to a new Hamiltonian :math:`H'` which has the same eigenvalues as
obliviateandsurrender marked this conversation as resolved.
Show resolved Hide resolved
:math:`H`

.. math:: H' = U^{\dagger} H U = \sum_{i=1}^r c_i \mu_i,

such that each :math:`\mu_i` term in the new Hamiltonian always acts trivially, e.g., with an
identity or a Pauli operator, on a set of qubits. This allows tapering-off those qubits from the
Hamiltonian.

For instance, consider the following Hamiltonian

.. math:: H' = Z_0 X_1 - X_1 + Y_0 X_1,

where all terms in the Hamiltonian act on the second qubit with the :math:`X` operator. It is
straightforward to show that each term in the Hamiltonian commutes with :math:`I_0 X_1` and the
ground-state eigenvector of :math:`H'` is also an eigenvector of :math:`I_0 X_1` with eigenvalues
:math:`\pm 1`. We can also rewrite the Hamiltonian as

.. math:: H' = (Z_0 I_1 - I_0 I_1 + Y_0 I_1) I_0 X_1,

which gives us

.. math:: H'|\psi \rangle = \pm1 (Z_0 I_1 - I_0 I_1 + Y_0 I_1)|\psi \rangle,

where :math:`|\psi \rangle` is an eigenvector of :math:`H'`. This means that the Hamiltonian
:math:`H` can be simplified as

.. math:: H_{tapered} = \pm1 (Z_0 - I_0 + Y_0).
soranjh marked this conversation as resolved.
Show resolved Hide resolved

The tapered Hamiltonian :math:`H_{tapered}` has the eigenvalues

.. math:: [-2.41421, 0.41421],

and

.. math:: [2.41421, -0.41421],

depending on the value of the :math:`\pm 1` prefactor. The eigenvalues of the original Hamiltonian
:math:`H` are

.. math:: [2.41421, -2.41421, 0.41421, -0.41421],

which are thus reproduced by the tapered Hamiltonian.

More generally, we can construct the unitary :math:`U` such that each :math:`\mu_i` term acts with a
Pauli-X operator on a set of qubits
:math:`\left \{ j \right \}, j \in \left \{ l, ..., k \right \}` where :math:`j` is the qubit label.
soranjh marked this conversation as resolved.
Show resolved Hide resolved
This guarantees that each term of the transformed Hamiltonian commutes with each of the Pauli-X
operators applied to the :math:`j`-th qubit:

.. math:: [H', X^j] = 0,

and the eigenvectors of the transformed Hamiltonian :math:`H'` are also eigenvectors of each of the
:math:`X^{j}` operators. Then we can factor out all of the :math:`X^{j}` operators from the
transformed Hamiltonian and replace them with their eigenvalues :math:`\pm 1`. This gives us a
set of tapered Hamiltonians depending on which eigenvalue :math:`\pm 1` we chose for each of the
:math:`X^{j}` operator. For instance, in the case of two tapered qubits, we have four eigenvalue
CatalinaAlbornoz marked this conversation as resolved.
Show resolved Hide resolved
sectors: :math:`[+1, +1]`, :math:`[-1, +1]`, :math:`[+1, -1]`, :math:`[-1, -1]`. In these tapered
Hamiltonians, the set of :math:`\left \{ j \right \}, j \in \left \{ l, ..., k \right \}` qubits
are eliminated. For tapered molecular Hamiltonians, it is possible to determine the optimal sector
of the eigenvalues that corresponds to the ground state. This is explained in more detail in the
following sections.

The unitary operator :math:`U` can be constructed as a
`Clifford <https://en.wikipedia.org/wiki/Clifford_gates>`__ operator [#bravyi2017]_

.. math:: U = \Pi_j \left [\frac{1}{\sqrt{2}} \left (X^{q(j)} + \tau_j \right) \right],

where :math:`\tau` denotes the generators of the symmetry group of :math:`H` and
:math:`X^{q}` operators act on those qubits that will be ultimately tapered off from
the Hamiltonian. The symmetry group of the Hamiltonian is defined as an Abelian group of Pauli words that commute
with each term in the Hamiltonian (excluding :math:`−I`). The
`generators <https://en.wikipedia.org/wiki/Generating_set_of_a_group>`__ of the symmetry group are
those elements of the group that can be combined, along with their inverses, to create any other
member of the group.

Let's use the qubit tapering method and obtain the ground state energy of the `Helium hydride
cation <https://en.wikipedia.org/wiki/Helium_hydride_ion>`__ :math:`\textrm{HeH}^+`.

Tapering the molecular Hamiltonian
----------------------------------

In PennyLane, a molecular Hamiltonian can be created by specifying the atomic symbols and
CatalinaAlbornoz marked this conversation as resolved.
Show resolved Hide resolved
coordinates.
CatalinaAlbornoz marked this conversation as resolved.
Show resolved Hide resolved
"""
import pennylane as qml
from pennylane import numpy as np

symbols = ["He", "H"]
geometry = np.array([[0.00000000, 0.00000000, -0.87818361],
[0.00000000, 0.00000000, 0.87818362]])

H, qubits = qml.qchem.molecular_hamiltonian(symbols, geometry, charge=1)
print(H)

##############################################################################
# This Hamiltonian contains 27 terms where each term acts on up to four qubits.
#
# We can now obtain the symmetry generators and the :math:`X^{j}` operators that are
# used to construct the unitary :math:`U` operator that transforms the :math:`\textrm{HeH}^+`
# Hamiltonian. In PennyLane, these are constructed by using the
# :func:`~.pennylane.symmetry_generators` and :func:`~.pennylane.paulix_ops` functions.

generators = qml.symmetry_generators(H)
paulixops = qml.paulix_ops(generators, qubits)

for idx, generator in enumerate(generators):
print(f'generator {idx+1}: {generator}, paulix_op: {paulixops[idx]}')

##############################################################################
# Once the operator :math:`U` is applied, each of the Hamiltonian terms will act on the qubits
# :math:`q_2, q_3` either with the identity or with a Pauli-X operator. For each of these qubits,
# we can simply replace the Pauli-X operator with one of its eigenvalues :math:`+1` or :math:`-1`.
# This results in a total number of :math:`2^k` Hamiltonians, where :math:`k` is the number of
# tapered-off qubits and each Hamiltonian corresponds to one eigenvalue sector. The optimal sector
# corresponding to the ground-state energy of the molecule can be obtained by using the
# :func:`~.pennylane.qchem.optimal_sector` function.


n_electrons = 2
paulix_sector = qml.qchem.optimal_sector(H, generators, n_electrons)
print(paulix_sector)

##############################################################################
# The optimal eigenvalues are :math:`-1, -1` for qubits :math:`q_2, q_3`, respectively. We can now
# build the tapered Hamiltonian with the :func:`~.pennylane.taper` function which
# constructs the operator :math:`U`, applies it to the Hamiltonian and finally tapers off the
soranjh marked this conversation as resolved.
Show resolved Hide resolved
# qubits :math:`q_2, q_3` by replacing the Pauli-X operators acting on those qubits with the optimal
# eigenvalues.

H_tapered = qml.taper(H, generators, paulixops, paulix_sector)
soranjh marked this conversation as resolved.
Show resolved Hide resolved
print(H_tapered)

##############################################################################
# The new Hamiltonian has only 9 non-zero terms acting on only 2 qubits! We can verify that the
soranjh marked this conversation as resolved.
Show resolved Hide resolved
soranjh marked this conversation as resolved.
Show resolved Hide resolved
# original and the tapered Hamiltonian both give the correct ground state energy of the
# :math:`\textrm{HeH}^+` cation, which is :math:`-2.862595242378` Ha computed with the full
# configuration interaction (FCI) method. In PennyLane, it's possible to build a sparse matrix
soranjh marked this conversation as resolved.
Show resolved Hide resolved
# representation of Hamiltonians. This allows us to directly diagonalize them to obtain exact values
# of the ground-state energies.

H_sparse = qml.SparseHamiltonian(qml.utils.sparse_hamiltonian(H), wires=all)
H_tapered_sparse = qml.SparseHamiltonian(qml.utils.sparse_hamiltonian(H), wires=all)

print("Eigenvalues of H:\n", qml.eigvals(H_sparse, k=16))
print("\n Eigenvalues of H_tapered:\n", qml.eigvals(H_tapered_sparse, k=4))

##############################################################################
# Tapering the reference state
# ----------------------------
# The ground state Hartree-Fock energy of :math:`\textrm{HeH}^+` can be computed by directly
# applying the Hamiltonians to the Hartree-Fock state. For the tapered Hamiltonian, this requires
# transforming the Hartree-Fock state with the same symmetries obtained for the original
# Hamiltonian. This reduces the number of qubits in the Hartree-Fock state to match that of the
# tapered Hamiltonian. It can be done with the :func:`~.pennylane.qchem.taper_hf` function.
soranjh marked this conversation as resolved.
Show resolved Hide resolved

state_tapered = qml.qchem.taper_hf(
generators, paulixops, paulix_sector, n_electrons, len(H.wires))
print(state_tapered)

##############################################################################
# Recall that the original Hartree-Fock state for the :math:`\textrm{HeH}^+` cation is
# :math:`[1 1 0 0]`. We can now generate the qubit representation of these states and compute the
# Hartree-Fock energies for each Hamiltonian.

dev = qml.device('default.qubit', wires=H.wires)
@qml.qnode(dev)
def circuit():
qml.BasisState(np.array([1, 1, 0, 0]), wires=H.wires)
return qml.state()
qubit_state = circuit()
HF_energy = qubit_state.T @ qml.utils.sparse_hamiltonian(H).toarray() @ qubit_state
print(f'HF energy: {np.real(HF_energy):.8f} Ha')

dev = qml.device('default.qubit', wires=H_tapered.wires)
@qml.qnode(dev)
def circuit():
qml.BasisState(np.array([1, 1]), wires=H_tapered.wires)
return qml.state()
qubit_state = circuit()
HF_energy = qubit_state.T @ qml.utils.sparse_hamiltonian(H_tapered).toarray() @ qubit_state
print(f'HF energy (tapered): {np.real(HF_energy):.8f} Ha')

##############################################################################
# These values are identical to the reference Hartree-Fock energy :math:`-2.8543686493` Ha.
#
# VQE simulation
# --------------
# Finally, we can use the tapered Hamiltonian and the tapered reference state to perform a VQE
# simulation and compute the ground-state energy of the :math:`\textrm{HeH}^+` cation. We use the
# tapered Hartree-Fock state to build a circuit that prepares an entangled state by applying Pauli
# rotation gates [#ryabinkin2018]_ since we cannot use the typical particle-conserving gates
# with the tapered state.

dev = qml.device('default.qubit', wires=H_tapered.wires)
@qml.qnode(dev)
def circuit(params):
qml.BasisState(state_tapered, wires=H_tapered.wires)
qml.PauliRot(params[2], 'Y', wires=[0])
qml.PauliRot(params[1], 'Y', wires=[1])
qml.PauliRot(params[0], 'YX', wires=[0, 1])
return qml.expval(H_tapered)

##############################################################################
# We define an optimizer and the initial values of the circuit parameters and optimize the circuit
# parameters with respect to the ground state energy.

optimizer = qml.GradientDescentOptimizer(stepsize=0.5)
params = np.zeros(3)

for n in range(1, 20):
params, energy = optimizer.step_and_cost(circuit, params)
if n % 2:
print(f'n: {n}, E: {energy:.8f} Ha, Params: {params}')

##############################################################################
# The computed energy matches the FCI energy, :math:`-2.862595242378` Ha, while the number of qubits
# and the number of Hamiltonian terms are significantly reduced with respect to their original
# values.
#
# Conclusions
# -----------
# Molecular Hamiltonians possess symmetries that can be leveraged to reduce the number of qubits
# required in quantum computing simulations. This tutorial introduces a PennyLane functionality that
# can be used for qubit tapering based on :math:`\mathbb{Z}_2` symmetries. The procedure includes
# obtaining tapered Hamiltonians and tapered reference states that can be used in variational
# quantum algorithms such as VQE.
#
# References
# ----------
#
# .. [#bravyi2017]
obliviateandsurrender marked this conversation as resolved.
Show resolved Hide resolved
#
# Sergey Bravyi, Jay M. Gambetta, Antonio Mezzacapo, Kristan Temme, "Tapering off qubits to
# simulate fermionic Hamiltonians". `arXiv:1701.08213 <https://arxiv.org/abs/1701.08213>`__
#
# .. [#setia2019]
#
# Kanav Setia, Richard Chen, Julia E. Rice, Antonio Mezzacapo, Marco Pistoia, James Whitfield,
# "Reducing qubit requirements for quantum simulation using molecular point group symmetries".
# `arXiv:1910.14644 <https://arxiv.org/abs/1910.14644>`__
#
# .. [#ryabinkin2018]
#
# Ilya G. Ryabinkin, Tzu-Ching Yen, Scott N. Genin, Artur F. Izmaylov, "Qubit coupled-cluster
# method: A systematic approach to quantum chemistry on a quantum computer".
# `arXiv:1809.03827 <https://arxiv.org/abs/1809.03827>`__
CatalinaAlbornoz marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 6 additions & 0 deletions demos_quantum-chemistry.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ Quantum chemistry is one the leading application areas of quantum computers. Mas
:description: :doc:`demos/vqe_parallel`
:tags: chemistry

.. customgalleryitem::
:tooltip: Qubit tapering with symmetries
:figure: demonstrations/qubit_tapering/qubit_tapering.png
:description: :doc:`demos/tutorial_qubit_tapering`
:tags: chemistry


:html:`</div></div><div style='clear:both'>`

Expand Down