-
Notifications
You must be signed in to change notification settings - Fork 1
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
Tfim simulation using 2 CNOT rather than 3 CNOT #94
base: main
Are you sure you want to change the base?
Conversation
steps: int = None | ||
B_a: float = None | ||
|
||
def circuit(self, a, t_duration, B_a, steps=None, order=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.
def circuit(self, a, t_duration, B_a, steps=None, order=None): | |
def circuit(self, t_duration, steps=None, order=None): |
This class must implement eo.circuit(0.1)
without requiring other parameters.
What is a
?
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 use the notation in the paper where a is an index and B_a is another parameter.
|
||
for _ in range(steps): | ||
# Apply time evolution for X(a) + B_a * Z(a) | ||
circuit += self._time_evolution_step(a, dt, B_a) |
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.
This is commuting so it's equivalent to
circuit += self._time_evolution_step(a, t_duration, B_a)
Once you have for a in range(self.nqubits):
(TFIM evolution oracle should be implemented for nqubits
) then you need to do the CNOTs before every dt
step here
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.
Please provide test code demonstrating the functioning of this CNOT decomposition:
- as the number of steps increase the comparison with H_TFIM_symbolic.exp(t) should be improving
- in XXZ we used 2nd order, here we should do that too
|
||
# Time evolution under the transverse field Ising model Hamiltonian | ||
# exp(-i t (X(a) + B_a * Z(a))) | ||
dt = t_duration / steps # Divide the time duration for Trotterization if needed |
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.
dt = t_duration / steps # Divide the time duration for Trotterization if needed | |
dt = t_duration / steps # Divide the time duration for Trotterization if needed | |
for a in range(nqubits: | |
circuit.add(gates.CNOT(a, a + 1)) | |
circuit += self._time_evolution_step(a, dt, B_a) | |
circuit.add(gates.CNOT(a, a + 1)) |
and then loop this over _ in range(steps)
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.
n_qubits = 3
h_coeff = 1
hamiltonian = SymbolicHamiltonian(nqubits=n_qubits)
oracle = TFIM_EvolutionOracle(h=hamiltonian, evolution_oracle_type="trotter", steps=1, B_a=0, order=2)
circuit = oracle.circuit(t_duration=1.0)
unitary = circuit.unitary()
from qibo import hamiltonians
from numpy.linalg import norm
def our_TFIM(nqubits, h: float = 0.0, dense: bool = True, backend=None):
def multikron(matrix_list):
"""Calculates Kronecker product of a list of matrices."""
return reduce(np.kron, matrix_list)
from qibo.backends import matrices
matrix = (
- multikron([matrices.X, matrices.X]) - h * multikron([matrices.Z, matrices.I])
)
terms = [hamiltonians.terms.HamiltonianTerm(matrix, i, i + 1) for i in range(nqubits - 1)]
terms.append(hamiltonians.terms.HamiltonianTerm(matrix, nqubits - 1, 0))
ham = SymbolicHamiltonian(backend=backend)
ham.terms = terms
return ham
ham = our_TFIM(nqubits=n_qubits, h=h_coeff, dense=False)
truth = ham.exp(1)
verification_norm = []
for step in range(1, 21):
oracle = TFIM_EvolutionOracle(h=hamiltonian, evolution_oracle_type="trotter", steps=step, B_a=h_coeff, order=2)
circuit = oracle.circuit(t_duration=1.0)
unitary = circuit.unitary()
#print(norm(truth-unitary))
verification_norm.append(norm(truth-unitary))
import matplotlib.pyplot as plt
x = np.array([i for i in range(1, 21)])
plt.plot(x, verification_norm, 'o')
plt.title("verification of TFIM 2 CNOT implementation")
plt.xlabel("steps")
plt.ylabel("norm of difference")
plt.show()
produces the following graph:
Co-authored-by: Marek Gluza <[email protected]>
…se of commutivity.
…ed on the looping at the boundary condition for TFIM model.
This pull request is to address issue 70 where we consider the special TFIM model:
where we can express the time evolution as