-
Notifications
You must be signed in to change notification settings - Fork 61
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 scheduling #1219
Dbi scheduling #1219
Conversation
…_scheduling_polynomial; test_double_bracket_iteration_scheduling_grid_hyperopt
for more information, see https://pre-commit.ci
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dbf_migrate #1219 +/- ##
===============================================
- Coverage 100.00% 99.80% -0.20%
===============================================
Files 70 71 +1
Lines 10168 10259 +91
===============================================
+ Hits 10168 10239 +71
- Misses 0 20 +20
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Why is the default value an odd number ? I will expect to use an even order to approximate better a minimum |
def sigma(h: np.array): | ||
return h - self.backend.cast(np.diag(np.diag(self.backend.to_numpy(h)))) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already have this function
qibo/src/qibo/models/dbi/double_bracket.py
Lines 108 to 115 in e38a340
@property | |
def diagonal_h_matrix(self): | |
"""Diagonal H matrix.""" | |
return self.backend.cast(np.diag(np.diag(self.backend.to_numpy(self.h.matrix)))) | |
@property | |
def off_diag_h(self): | |
return self.h.matrix - self.diagonal_h_matrix |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but here the h
is a general Hamiltonian instead of the property h
in class DoubleBracketIteration
. Is there a good way to reduce the redundancy such that we can have both the property and a function that works for other hamiltonians?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe the property in line 115 should actually call 228?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest you define a sigma
static method inside DoubleBracketIteration
class and call it inside the property off_diag_h
and polynomial_step
.
@Sam-XiaoyueLi I think this is because if we don't go +1 degree the highest degree will be the error term? so We want to assume that @Edoardo-Pedicillo please close comment if you agree? :) |
@Edoardo-Pedicillo @marekgluza |
Can you confirm if starting from 3 or 2 or 4 makes a difference? I thought 3 is minimal? |
From the simulations I made, the third order was always the minimum order necessary (although sometimes higher terms were needed). In any case, second-order never seems to work and I think there must be an underlying reason that I couldn't obtain analytically |
Yes they make a difference, in general higher orders are better, but not necessarily the even ones. (Here |
n: int = 4, | ||
n_max: int = 5, | ||
d: np.array = None, | ||
backup_scheduling: DoubleBracketScheduling = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
backup_scheduling: DoubleBracketScheduling = None, |
For transparency, I prefer that the case of no solutions is handled in choose_step
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion, the no solution case has been moved to choose_step
. However, would you have a good solution for the problem where no additional key arguments can be supplied to the backup scheduling? Meaning that when the backup scheduling runs, only the default values can be used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe, the best approach is to remove the backup scheduling option and handle the failure of the optimization in another way, understanding better why it does not converge.
For what I have understood, the optimization algorithm fails because the polynomial has not real roots, so I suppose this could mean two things (correct me if I am wrong): either the function has no minima or the approximation is incorrect.
In the first case you should take one of the range boundaries, in the second one maybe increase the polynomial degree is enough.
Co-authored-by: Edoardo Pedicillo <[email protected]>
Checklist:
Context of the PR: given a diagonal operator$D$ , we want to know the optimal DBI duration $s$ which gives maximal diagonalization gain in one step. The monotonicity relation implies that a linear change of the cost function $||\sigma(e^{-sW}He^{sW})||$ at the beginning, but at some point it needs to turn around, because $W$ cannot diagonalize $H$ in one step. Generally, we can see a curve such as:
We will use analytical means to fit the first minimum (taylor expansion which is more sensitive to the first minimum). Other methods like hyperopt and grid_search are sensitive to the scheduling search interval and may end up in minima other than the first dip (see Fig below). Taking the first minimum may not lead to the global minimum at that iteration step, however, over many iteration steps, it seems to provide a better stability of diagonalization.
This PR is an addition to the DBI model, adding utilities in
double_bracket.py
to select scheduling (time step) strategies via classDoubleBracketScheduling
.These strategies include:
use_hyperopt
,use_grid_search
, anduse_polynomial_approximation
Within each double bracket iteration, the step is chosen with functionchoose_step
, which returns the optimal step calculated with a given scheduling strategy.While hyperopt and grid search have been implemented in previous codes, the polynomial approximation is an analytical strategy newly suggested by @wrightjandrew. However, some modifications have been made:
Note that additional parameters for each search (max_evals, etc.) can be given as key arguments in
choose_step