Skip to content

Commit

Permalink
introduce second order formula
Browse files Browse the repository at this point in the history
  • Loading branch information
shangtai committed Jun 3, 2024
1 parent bf28529 commit 92cb06a
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/boostvqe/compiling_XXZ.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,57 @@ def nqubit_XXZ_decomposition(nqubits,t,delta=0.5,steps=1):
for _step in range(steps):
multi_layer += circuit
return multi_layer


def nqubit_XXZ_decomposition_second_order(nqubits, t, delta=0.5, steps=1):
"""
Constructs an XXZ model circuit for n qubits, given by:
.. math::
H = \\sum_{i=0}^{N-1} \\left( X_i X_{i+1} + Y_i Y_{i+1} + \\delta Z_i Z_{i+1} \\right)
This function decomposes the time evolution operator of the XXZ model
into a sequence of quantum gates applied to a quantum circuit using second order formula
Args:
nqubits (int): Number of qubits.
t (float): Total evolution time.
delta (float): Coefficient for the Z component (default 0.5).
steps (int): Number of time steps (default 1).
Returns:
Circuit: The final multi-layer circuit.
Example:
.. testcode::
from boostvqe.compiling_XXZ_utils import *
# Create circuit to decompose 6 qubits XXZ with 3 decomposition steps
circ = nqubit_XXZ_decomposition_second_order(nqubits=6,t=0.01,delta=0.5,steps=3)
print(circ.draw())
"""
circuit = Circuit(nqubits=nqubits)

# Create lists of even and odd qubit indices
even_numbers = [num for num in range(nqubits) if num % 2 == 0]
odd_numbers = [num for num in range(nqubits) if num % 2 == 1]

if nqubits % 2 == 0:
# Handle even number of qubits
even_numbers_end_0 = [num for num in range(1, nqubits) if num % 2 == 0]
even_numbers_end_0.append(0)
circuit = _add_gates(circuit, odd_numbers, even_numbers_end_0, t/2, delta, steps)
circuit = _add_gates(circuit, even_numbers, odd_numbers, t, delta, steps)
circuit = _add_gates(circuit, odd_numbers, even_numbers_end_0, t/2, delta, steps)
elif nqubits % 2 == 1:
# Handle odd number of qubits (since XXZ model has periodic boundary conditions)
circuit = _add_gates(circuit, odd_numbers, even_numbers[1:], t/2, delta, steps)
circuit = _add_gates(circuit, [nqubits - 1], [0], t/2, delta, steps)
circuit = _add_gates(circuit, even_numbers[:-1], odd_numbers, t, delta, steps)
circuit = _add_gates(circuit, odd_numbers, even_numbers[1:], t/2, delta, steps)
circuit = _add_gates(circuit, [nqubits - 1], [0], t/2, delta, steps)

# Create a multi-layer circuit with the time evolution steps
multi_layer = Circuit(nqubits=nqubits)
for _step in range(steps):
multi_layer += circuit
return multi_layer

0 comments on commit 92cb06a

Please sign in to comment.