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

Dbi cost functions #1269

Merged
merged 135 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
135 commits
Select commit Hold shift + click to select a range
c8513f1
dbi scheduling first commit: added feature 3 options of scheduling me…
Sam-XiaoyueLi Jan 25, 2024
5fae934
Merge branch 'dbf_migrate' of https://github.com/qiboteam/qibo into d…
Sam-XiaoyueLi Jan 29, 2024
5567114
Tests for double_bracket.py scheduling: test_double_bracket_iteration…
Sam-XiaoyueLi Jan 29, 2024
9a7c9f8
Merge branch 'dbf_migrate' of https://github.com/qiboteam/qibo into d…
Sam-XiaoyueLi Jan 29, 2024
abddfae
Updated utils and Pauli-Z notebook for scheduling
Sam-XiaoyueLi Jan 29, 2024
1948c01
Notebook section shows difference of scheduling techniques in Pauli-Z…
Sam-XiaoyueLi Jan 30, 2024
2754cd2
New branch for implementing magnetic field strategy for double bracke…
Sam-XiaoyueLi Feb 13, 2024
588a02a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 15, 2024
00d7ae1
Merge branch 'dbi_scheduling' of https://github.com/qiboteam/qibo int…
Sam-XiaoyueLi Feb 15, 2024
9d663cb
Fix test random hamiltonian seed for test coverage stability
Sam-XiaoyueLi Feb 15, 2024
e38a340
Merge branch 'dbf_migrate' of https://github.com/qiboteam/qibo into d…
Sam-XiaoyueLi Feb 15, 2024
8c94e4f
Merge branch 'dbi_scheduling' of https://github.com/qiboteam/qibo int…
Sam-XiaoyueLi Feb 15, 2024
892fda4
Added functions for running gradient descent
Sam-XiaoyueLi Feb 22, 2024
ed7580e
Merge branch 'dbf_migrate' of https://github.com/qiboteam/qibo into d…
Sam-XiaoyueLi Feb 22, 2024
0eb2add
Run magnetic field strategy on TFIM
Sam-XiaoyueLi Feb 22, 2024
c3a149c
Merge branch 'master' of https://github.com/qiboteam/qibo into dbi_ma…
Sam-XiaoyueLi Feb 22, 2024
08fb837
Complete dbi_strategies_compare notebook
Sam-XiaoyueLi Feb 22, 2024
3cd9338
Fix error: missing argument d in gradient_onsite_Z
Sam-XiaoyueLi Feb 23, 2024
46ea9ad
Merge branch 'dbf_migrate' of https://github.com/qiboteam/qibo into d…
Sam-XiaoyueLi Feb 28, 2024
bfec996
Complete the merge in docstring
Sam-XiaoyueLi Feb 28, 2024
54ced5b
Remove `use` in scheduling names
Sam-XiaoyueLi Feb 28, 2024
4b9dc91
Complete docstring; set default polynomial order to even number 4.
Sam-XiaoyueLi Feb 28, 2024
9f999db
Merge branch 'dbi_scheduling' of https://github.com/qiboteam/qibo int…
Sam-XiaoyueLi Feb 28, 2024
4124519
Added documentation + test of effect of n_taylor
Sam-XiaoyueLi Feb 28, 2024
c5ab13e
Remove print line
Sam-XiaoyueLi Feb 28, 2024
3bdee0f
Test coverage for the branch
Sam-XiaoyueLi Feb 28, 2024
f35a58d
Fix error in notebook call (key arguments exchanged)
Sam-XiaoyueLi Mar 1, 2024
80d2604
Backup scheduling moved to `choose_step`
Sam-XiaoyueLi Mar 1, 2024
54a86a8
Update src/qibo/models/dbi/double_bracket.py
Sam-XiaoyueLi Mar 1, 2024
50554e3
Simplify code structure in `polynomial_step`
Sam-XiaoyueLi Mar 1, 2024
4fcdf64
Update `test_models_dbi.py`
Sam-XiaoyueLi Mar 1, 2024
4b985ac
Merge branch 'dbi_scheduling' of https://github.com/qiboteam/qibo int…
Sam-XiaoyueLi Mar 1, 2024
67701e1
Define sigma and Gamma as class function
Sam-XiaoyueLi Mar 1, 2024
ca71ffa
Modified structure: moving scheduling strategies in `utils_scheduling…
Sam-XiaoyueLi Mar 5, 2024
027dc00
Simplify backup option in `choose_step`
Sam-XiaoyueLi Mar 5, 2024
743f947
Fix test for new structure
Sam-XiaoyueLi Mar 6, 2024
00f6d8c
Test coverage for fail cases in polynomial step
Sam-XiaoyueLi Mar 6, 2024
08f8977
added new cost functions
wrightjandrew Mar 12, 2024
f2061f8
bug fix: use string of cost function
wrightjandrew Mar 12, 2024
93eb20a
added full diagonal gradients and a tutorial file
wrightjandrew Mar 15, 2024
f17eb1d
Revert "Test coverage for fail cases in polynomial step"
wrightjandrew Mar 16, 2024
b0c6958
Scheduling test
Sam-XiaoyueLi Mar 19, 2024
0326039
Initial commits for SA
Sam-XiaoyueLi Mar 19, 2024
0b241b1
Update utils_scheduling.py
wrightjandrew Mar 20, 2024
b3a5b0e
Fix lint error
Sam-XiaoyueLi Mar 25, 2024
c6749ab
Merge from scheduling_SA + added test for cost function
Sam-XiaoyueLi Mar 25, 2024
f91956b
Style changes for readability
Sam-XiaoyueLi Mar 25, 2024
9e914de
Remove verbose option for SA
Sam-XiaoyueLi Mar 25, 2024
6de7b6c
Merge branch 'master' into dbi_cost_functions
Sam-XiaoyueLi Mar 25, 2024
8d2b8fc
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 25, 2024
46c10ca
Merge branch 'dbi_cost_functions' of https://github.com/qiboteam/qibo…
Sam-XiaoyueLi Mar 26, 2024
909972e
Merge branch 'dbi_cost_functions' of https://github.com/qiboteam/qibo…
Sam-XiaoyueLi Mar 26, 2024
59a56ec
Fix errors emerged from merch
Sam-XiaoyueLi Mar 26, 2024
e8ab447
Added numerical gradient as well as Z-ansatz
wrightjandrew Mar 26, 2024
bf9d5e3
Merge branch 'dbi_cost_functions' of https://github.com/qiboteam/qibo…
wrightjandrew Mar 26, 2024
4f6fe62
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 26, 2024
f4ddcfa
Update notebook
Sam-XiaoyueLi Apr 2, 2024
0c2b149
Merge branch 'master' of https://github.com/qiboteam/qibo into dbi_co…
Sam-XiaoyueLi Apr 2, 2024
13ac293
Fix lint error
Sam-XiaoyueLi Apr 2, 2024
8cc73f6
Fix test error w energy fluctuation
Sam-XiaoyueLi Apr 2, 2024
39dbe4e
Update notebook to run
Sam-XiaoyueLi Apr 2, 2024
709dcd3
added more comments on functions
wrightjandrew Apr 2, 2024
c9f280f
Merge branch 'dbi_cost_functions' of https://github.com/qiboteam/qibo…
wrightjandrew Apr 2, 2024
573b6c9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 2, 2024
1f22e0e
Code adding Ising model to magnetic field, remaining test
Sam-XiaoyueLi Apr 4, 2024
813948d
Merge branch 'master' of https://github.com/qiboteam/qibo into dbi_ma…
Sam-XiaoyueLi Apr 4, 2024
ca0b77b
did most of Marek's comments
wrightjandrew Apr 4, 2024
a8bef3e
did most of Marek's comments
wrightjandrew Apr 4, 2024
2bbc504
Merge branch 'dbi_cost_functions' of https://github.com/qiboteam/qibo…
wrightjandrew Apr 4, 2024
d0c0ba2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 4, 2024
82d16ba
Merge branch 'master' of https://github.com/qiboteam/qibo into dbi_ma…
Sam-XiaoyueLi Apr 8, 2024
6de6003
Update notebooks to function
Sam-XiaoyueLi Apr 8, 2024
5c391b2
Update code strucutre and dependencies
Sam-XiaoyueLi Apr 8, 2024
8b96110
Import dependency (optional)
Sam-XiaoyueLi Apr 8, 2024
ecc15ad
remove circular dependency and added numpy casting on cost functions
wrightjandrew Apr 15, 2024
43ee596
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 15, 2024
6a41ccf
added group commutator tests
wrightjandrew Apr 25, 2024
24bb12d
Resolve cost function notebook issues based on commit 6a41ccf
Sam-XiaoyueLi May 2, 2024
2977f1c
added normalization option for D and projected GD
wrightjandrew May 2, 2024
dc349b4
addded D normalization and projected GD
wrightjandrew May 2, 2024
2175f11
fixed some issues of the PR
wrightjandrew May 6, 2024
a47e7e1
fixed some issues as suggested on the PR
wrightjandrew May 6, 2024
fd1737b
Fix minor errors in notebook, add new test files
Sam-XiaoyueLi May 19, 2024
b6f220a
Fix test_dbi.py with pytorch (backend.cast)
Sam-XiaoyueLi May 20, 2024
eda60e9
corrected suggestions made from the PR
wrightjandrew May 20, 2024
b3b19e4
Fix errors with pytorch: backend.cast
Sam-XiaoyueLi May 21, 2024
e54b08b
Merge branch 'dbi_cost_functions' of https://github.com/qiboteam/qibo…
Sam-XiaoyueLi May 21, 2024
48fe758
Fix names "CostFunction" for notebooks
Sam-XiaoyueLi May 21, 2024
8ced042
Merging from Ising branch: tests fixed, coverage undone; utils_gradie…
Sam-XiaoyueLi May 21, 2024
29b8745
Fix circular imports
Sam-XiaoyueLi May 21, 2024
4cc3fd7
reverted energyfluctuation for now, changed cost names
wrightjandrew May 21, 2024
103da19
Merge branch 'master' of https://github.com/qiboteam/qibo into dbi_co…
Sam-XiaoyueLi May 23, 2024
b5b457e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 23, 2024
4562145
Merge branch 'master' of https://github.com/qiboteam/qibo into dbi_co…
Sam-XiaoyueLi May 23, 2024
e2232c0
Revert current branch changes
Sam-XiaoyueLi May 23, 2024
9e1dafe
Minor simplification of scheduling
Sam-XiaoyueLi May 23, 2024
7ffd986
removed analytical gradients
wrightjandrew May 23, 2024
29c7907
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 23, 2024
f568363
Coverage for all dbi files and passing tests. TODO: fix notebooks + d…
Sam-XiaoyueLi May 24, 2024
dfb70a4
Fix hamiltonians indentation
Sam-XiaoyueLi May 27, 2024
d45cdce
change names
Sam-XiaoyueLi May 27, 2024
ca947b7
Initial commit
Sam-XiaoyueLi May 29, 2024
4d4c452
Increase pauli analytical expansion to n=5.
Sam-XiaoyueLi May 29, 2024
b867fec
doc: Add notebooks to sphinx
andrea-pasquale May 29, 2024
ab49577
Combine gradient descnet, remove unnecessary code, clean notebooks.
Sam-XiaoyueLi May 29, 2024
b3aa961
Clean notebook outputs
Sam-XiaoyueLi May 29, 2024
a82406d
Merge branch 'dbi_cost_functions' into dbi_cost_doc
andrea-pasquale May 29, 2024
4c88e60
fix: Fix energy fluctuations
andrea-pasquale May 29, 2024
7022262
tests: Code improvements and tests
andrea-pasquale May 29, 2024
30cbe29
feat: Tests passing on GPU
andrea-pasquale May 29, 2024
0e4d888
Set variational test to TFIM model
Sam-XiaoyueLi May 30, 2024
492202a
cleanup: Remove unused features
andrea-pasquale May 30, 2024
a4b52e8
Merge pull request #1340 from qiboteam/dbi_gradient_combine
Sam-XiaoyueLi May 30, 2024
5e45c38
Merge branch 'dbi_cost_functions' into dbi_cost_doc
andrea-pasquale May 30, 2024
2547b21
feat: Add symblic link to doc
andrea-pasquale May 30, 2024
fa1d2c4
Added documentation for branch
Sam-XiaoyueLi May 30, 2024
8beac7c
Merge branch 'dbi_cost_functions' into dbi_cost_doc
andrea-pasquale May 30, 2024
b3706a2
Notebooks running
Sam-XiaoyueLi May 30, 2024
4d18650
feat: Update notebooks
andrea-pasquale May 30, 2024
0fbafa6
Merge branch 'dbi_cost_functions' into dbi_cost_doc
andrea-pasquale May 30, 2024
dfbad7f
doc: Update notebooks
andrea-pasquale May 30, 2024
01c99e8
fix: Fixing documentation
andrea-pasquale May 31, 2024
8c9c610
Update README.md
marekgluza May 31, 2024
5f24028
feat: Disable progressbar for hyperopt
andrea-pasquale May 31, 2024
392f939
fix: Fix README link
andrea-pasquale May 31, 2024
6dfa80a
more about the D operators
marekgluza May 31, 2024
90fbc03
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 31, 2024
5671d03
fix: Attempt to fix CI
andrea-pasquale May 31, 2024
410dcd0
test: execute and clean all dbi notebooks
MatteoRobbiati May 31, 2024
6130d09
fix: rm old dbi notebook from doc
MatteoRobbiati May 31, 2024
c4bfc1e
chore: Add ipykernel as doc dep
andrea-pasquale Jun 1, 2024
b5a4202
chore: Clean notebook
andrea-pasquale Jun 1, 2024
21d3b35
Merge pull request #1337 from qiboteam/dbi_cost_doc
andrea-pasquale Jun 1, 2024
fdf60de
test: Improve coverage
andrea-pasquale Jun 1, 2024
0f88d7b
Preliminary description of DBR duration scheduling
marekgluza Jun 3, 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
11 changes: 10 additions & 1 deletion doc/source/code-examples/applications-by-algorithm.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,13 @@ Diagonalization Algorithms
.. toctree::
:maxdepth: 1

tutorials/dbi/dbi.ipynb
tutorials/dbi/README.md

tutorials/dbi/dbi_cost_functions.ipynb
tutorials/dbi/dbi_gradient_descent_strategies.ipynb
tutorials/dbi/dbi_group_commutator_tests.ipynb
tutorials/dbi/dbi_scheduling.ipynb
tutorials/dbi/dbi_strategies_compare.ipynb
tutorials/dbi/dbi_strategy_Ising_model.ipynb
tutorials/dbi/dbi_strategy_Pauli-Z.ipynb
tutorials/dbi/dbi_tutorial_basic_intro.ipynb
1 change: 0 additions & 1 deletion doc/source/code-examples/applications-by-topic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ Quantum Physics
tutorials/bell-variational/README.md
tutorials/falqon/README.md
tutorials/grover/README.md
tutorials/dbi/dbi.ipynb

Quantum Machine Learning
^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
2 changes: 0 additions & 2 deletions doc/source/code-examples/applications.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ Quantum Physics
tutorials/bell-variational/README.md
tutorials/falqon/README.md
tutorials/grover/README.md
tutorials/dbi/dbi.ipynb


Quantum Machine Learning
^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
1 change: 1 addition & 0 deletions doc/source/code-examples/tutorials/dbi/README.md
1 change: 0 additions & 1 deletion doc/source/code-examples/tutorials/dbi/dbi.ipynb

This file was deleted.

58 changes: 58 additions & 0 deletions examples/dbi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Double-bracket quantum algorithms

Qibo features a model implementing double-bracke quantum algorithms (DBQAs) which are helpful for approximating eigenstates based on the ability to run the evolution under the input Hamiltonian.

More specifically, given a Hamiltonian $H_0$, how can we find a circuit which after applying to the reference state (usually $|0\rangle^{\otimes L}$ for $L$ qubits) will approximate an eigenstate?

A standard way is to run variational quantum circuits. For example, Qibo already features the `VQE` model [2] which provides the implementation of the variational quantum eigensolver framework.
DBQAs allow to go beyond VQE in that they take a different approach to compiling the quantum circuit approximating the eigenstate.

## What is the unitary of DBQA?

Given $H_0$ we begin by assuming that we were given a diagonal and hermitian operator $D_0$ and a time $s_0$.
The `dbi` module provides numerical strategies for selecting them.
For any such choice we define the bracket
$$ W_0 = [D_0, H_0]$$
and the double-bracket rotation (DBR) of the input Hamiltonian to time $s$
$$H_0(s) = e^{sW} H e^{- s W}$$

### Why are double-bracket rotations useful?
We can show that the magnitude of the off-diagonal norms will decrease.
For this let us set the notation that $\sigma(A)$ is the restriction to the off-diagonal of the matrix A.
In `numpy` this can be implemented by `\sigma(A) = A-np.diag(A)`. In Qibo we implement this as
https://github.com/qiboteam/qibo/blob/8c9c610f5f2190b243dc9120a518a7612709bdbc/src/qibo/models/dbi/double_bracket.py#L145-L147
which is part of the basic `DoubleBracketIteration` class in the `dbi` module.

With this notation we next use the Hilbert-Schmidt scalar product and norm to measure the progress of diagonalization
$$||\sigma(H_0(s))||^2- ||\sigma (H_0 )||^2= -2s \langle W, [H,\sigma(H)\rangle+O(s^2)$$
This equation tells us that as long as the scalar product $\langle W, [H,\sigma(H)\rangle$ is positive then after the DBR the magnitude of the off-diagonal couplings in $H_0(s)$ is less than in $H_0$.

For the implementation of the DBR unitary $U_0(s) = e^{-s W_0}$ see
https://github.com/qiboteam/qibo/blob/363a6e5e689e5b907a7602bd1cc8d9811c60ee69/src/qibo/models/dbi/double_bracket.py#L68

### How to choose $D$?

For theoretical considerations the canonical bracket is useful.
For this we need the notation of the dephasing channel $\Delta(H)$ which is equivalent to `np.diag(h)`.
$M = [\Delta(H),\sigma(H)]= [H,\sigma(H)]= [\Delta(H),H]$
The canonical bracket appears on its own in the monotonicity relation above and gives an unconditional reduction of the magnitude of the off-diagonal terms
$$||\sigma(H_0(s))||^2- ||\sigma (H_0 )||^2= -2s ||M||^2+O(s^2)$$
- the multi qubit Pauli Z generator with $Z(\mu) = (Z_1)^{\mu_1}\ldots (Z_L)^{\mu_L}$ where we optimize over all binary strings $\mu\in \{0,1\}^L$
- the magnetic field $D = \sum_i B_i Z_i$
- the two qubit Ising model $D = \sum_i B_i Z_i + \sum_{i,j} J_{i,j} Z_i Z_j$, please follow the tutorial by Matteo and use the QIBO ising model for that with $h=0$


### How to choose s?

The theory above shows that in generic cases the DBR will have a linear diagonalization effect (as quantified by $||\sigma(H_0(s))||$).
This can be further expanded with Taylor expansion and the Qibo implementation comes with methods for fitting the first local minimum.
Additionally a grid search for the optimal step is provided for an exhaustive evaluation and hyperopt can be used for a more efficient 'unstructured' optimization; additionally simulated annealing is provided which sometimes outperforms hyperopt (and grid search), see example notebooks.
The latter methods may output DBR durations $s_k$ which correspond to secondary local minima.





[1] https://arxiv.org/abs/2206.11772

[2] https://github.com/qiboteam/vqe-sun
Loading
Loading