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

Double bracket iterations #1047

Merged
merged 79 commits into from
Nov 29, 2023
Merged

Double bracket iterations #1047

merged 79 commits into from
Nov 29, 2023

Conversation

Edoardo-Pedicillo
Copy link
Contributor

@Edoardo-Pedicillo Edoardo-Pedicillo commented Oct 16, 2023

This PR implements a DoubleBracket class and solves #1034.

TODO

Checklist:

  • Reviewers confirm new code works as expected.
  • Tests are passing.
  • Coverage does not decrease.
  • Documentation is updated.

@Edoardo-Pedicillo
Copy link
Contributor Author

Edoardo-Pedicillo commented Oct 16, 2023

A small working example is provided in the documentation, now the algorithm does not converge because the step is not optimized.

@scarrazza now the DoubleBracket class is in qibo/hamiltonians folder, let me know if I should move it in qibo/models

@andrea-pasquale @MatteoRobbiati feel free to open PRs on top of this branch to contribute :)

@codecov
Copy link

codecov bot commented Oct 16, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (7f9f663) 100.00% compared to head (5046e3b) 100.00%.
Report is 29 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #1047   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           63        64    +1     
  Lines         8865      8936   +71     
=========================================
+ Hits          8865      8936   +71     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@MatteoRobbiati
Copy link
Contributor

Thanks a lot @Edoardo-Pedicillo for this.

@scarrazza now the DoubleBracket class is in qibo/hamiltonians folder, let me know if I should move it in qibo/models

I think it should be better to have it as a model in Qibo.

@scarrazza
Copy link
Member

scarrazza commented Oct 16, 2023

Thanks @Edoardo-Pedicillo, I agree with @MatteoRobbiati , better to move in models. Could you please proceed and include some basic tests?

@andrea-pasquale
Copy link
Contributor

I've moved the class to models and I've also added a few minimal tests.
I've tested the implementation on all CPU backends and it seems to be working, I need to check if on GPU everything is working correctly.
Feel free to review/add suggestions :)
Here is a quick example:

from qibo.models.double_bracket import DoubleBracketFlow, DoubleBracketFlowMode
from qibo import set_backend
import numpy as np
from qibo.hamiltonians.hamiltonians import Hamiltonian
from qibo.quantum_info import random_hermitian
import matplotlib.pyplot as plt

set_backend("numpy")

NSTEPS=100
nqubits = 4
h0 = random_hermitian(2**nqubits)

# define DBF
dbf = DoubleBracketFlow(Hamiltonian(nqubits=nqubits, matrix=h0))
for i in range(NSTEPS):
    # evolution under canonical commutator
    dbf(0.01, DoubleBracketFlowMode.canonical)

# plot matrix
plt.imshow(np.absolute(dbf.h.matrix), cmap='hot', interpolation='nearest')

download

I will proceed with the TODOs.

@andrea-pasquale andrea-pasquale added the enhancement New feature or request label Nov 3, 2023
@andrea-pasquale andrea-pasquale linked an issue Nov 3, 2023 that may be closed by this pull request
@andrea-pasquale
Copy link
Contributor

@Edoardo-Pedicillo @andrea-pasquale
I commented a review of the DBI conventions change by @MatteoRobbiati and suggested that the enum generator type will better be called DoubleBracketGeneratorType and not IterationGeneratorType which makes sense in the DBI context but will surely confuse somebody working elsewhere in QIBO if it shows up as an available class

Thanks @marekgluza for the feedback.
I just changed IterationGeneratorType to DoubleBracketGeneratorType as you suggested.

@MatteoRobbiati
Copy link
Contributor

@Edoardo-Pedicillo @andrea-pasquale I commented a review of the DBI conventions change by @MatteoRobbiati and suggested that the enum generator type will better be called DoubleBracketGeneratorType and not IterationGeneratorType which makes sense in the DBI context but will surely confuse somebody working elsewhere in QIBO if it shows up as an available class

Thanks @marekgluza for the feedback, it is a good idea. And thanks @andrea-pasquale for the fast fix.

@andrea-pasquale andrea-pasquale changed the title [WIP] Double bracket flow Double bracket iterations Nov 25, 2023
@Edoardo-Pedicillo
Copy link
Contributor Author

Edoardo-Pedicillo commented Nov 28, 2023

@Sam-XiaoyueLi could you move your commit in a new branch and open a PR pointing to dbf branch ?
Look here
https://stackoverflow.com/questions/1628563/move-the-most-recent-commits-to-a-new-branch-with-git#:~:text=Moving%20to%20a,branch%2C%20e.g%3A (instead of master you have to use dbf).

I suggest installing pre-commit https://pre-commit.com/#:~:text=eslint%20without%20root.-,Installation,-%C2%B6

@MatteoRobbiati MatteoRobbiati merged commit 5d0c55d into master Nov 29, 2023
21 checks passed
@scarrazza scarrazza deleted the dbf branch December 4, 2023 07:27
@marekgluza
Copy link
Contributor

For currently the first checkbox the point number 3 which is Hamiltonian simulation from primitive gates in #1034 can now be linked with #1138 for a more detailed discussion. @Edoardo-Pedicillo, can you split the box first checkbox and for the 3rd point link the issue #1138 and tag @shangtai?

I will write a more detailed description of point number 2 in #1034 which is about transpiling DBIs. This will be in two stages DBI - > Hamiltonian simulation and Hamiltonian simulation -> primitive gates

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Double-bracket iterations
6 participants