Skip to content

Commit 8dd1d33

Browse files
Merge pull request #1342 from qiboteam/dbi_gci_third_order
DBI 3rd order GCI
2 parents a92347f + 89c2e29 commit 8dd1d33

File tree

4 files changed

+36
-124
lines changed

4 files changed

+36
-124
lines changed

doc/source/code-examples/applications-by-algorithm.rst

-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ Diagonalization Algorithms
8080

8181
tutorials/dbi/dbi_cost_functions.ipynb
8282
tutorials/dbi/dbi_gradient_descent_strategies.ipynb
83-
tutorials/dbi/dbi_group_commutator_tests.ipynb
8483
tutorials/dbi/dbi_scheduling.ipynb
8584
tutorials/dbi/dbi_strategies_compare.ipynb
8685
tutorials/dbi/dbi_strategy_Ising_model.ipynb

examples/dbi/dbi_group_commutator_tests.ipynb

-122
This file was deleted.

src/qibo/models/dbi/double_bracket.py

+17-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ class DoubleBracketGeneratorType(Enum):
2323
"""Use single commutator."""
2424
group_commutator = auto()
2525
"""Use group commutator approximation"""
26-
# TODO: add double commutator (does it converge?)
26+
group_commutator_third_order = auto()
27+
"""Implements: $e^{\frac{\\sqrt{5}-1}{2}isH}e^{\frac{\\sqrt{5}-1}{2}isD}e^{-isH}e^{isD}e^{\frac{3-\\sqrt{5}}{2}isH}e^{isD}
28+
\approx e^{-s^2[H,D]} + O(s^4)$
29+
which is equation (8) in https://arxiv.org/abs/2111.12177]
30+
s must be taken as $\\sqrt{s}$ to approximate the flow using the commutator
31+
"""
2732

2833

2934
class DoubleBracketCostFunction(str, Enum):
@@ -125,6 +130,17 @@ def __call__(
125130
@ self.h.exp(step)
126131
@ self.backend.calculate_matrix_exp(step, d)
127132
)
133+
elif mode is DoubleBracketGeneratorType.group_commutator_third_order:
134+
if d is None:
135+
d = self.diagonal_h_matrix
136+
operator = (
137+
self.h.exp(-step * (np.sqrt(5) - 1) / 2)
138+
@ self.backend.calculate_matrix_exp(-step * (np.sqrt(5) - 1) / 2, d)
139+
@ self.h.exp(step)
140+
@ self.backend.calculate_matrix_exp(step * (np.sqrt(5) + 1) / 2, d)
141+
@ self.h.exp(-step * (3 - np.sqrt(5)) / 2)
142+
@ self.backend.calculate_matrix_exp(-step, d)
143+
)
128144
operator_dagger = self.backend.cast(
129145
np.array(np.matrix(self.backend.to_numpy(operator)).getH())
130146
)

tests/test_models_dbi.py

+19
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,25 @@ def test_double_bracket_iteration_group_commutator(backend, nqubits):
5858
assert initial_off_diagonal_norm > dbi.off_diagonal_norm
5959

6060

61+
@pytest.mark.parametrize("nqubits", [1, 2])
62+
def test_double_bracket_iteration_group_commutator_3rd_order(backend, nqubits):
63+
"""Check 3rd order group commutator mode."""
64+
h0 = random_hermitian(2**nqubits, backend=backend, seed=seed)
65+
d = backend.cast(np.diag(np.diag(backend.to_numpy(h0))))
66+
dbi = DoubleBracketIteration(
67+
Hamiltonian(nqubits, h0, backend=backend),
68+
mode=DoubleBracketGeneratorType.group_commutator_third_order,
69+
)
70+
initial_off_diagonal_norm = dbi.off_diagonal_norm
71+
72+
# test first iteration with default d
73+
dbi(mode=DoubleBracketGeneratorType.group_commutator_third_order, step=0.01)
74+
for _ in range(NSTEPS):
75+
dbi(step=0.01, d=d)
76+
77+
assert initial_off_diagonal_norm > dbi.off_diagonal_norm
78+
79+
6180
@pytest.mark.parametrize("nqubits", [1, 2])
6281
def test_double_bracket_iteration_single_commutator(backend, nqubits):
6382
"""Check single commutator mode."""

0 commit comments

Comments
 (0)