-
Notifications
You must be signed in to change notification settings - Fork 2
Tfim simulation using 2 CNOT rather than 3 CNOT #94
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
1415670
9c729bf
7ad8b90
7a54540
1032637
c0a0f61
6f2854a
18a950b
bbd6928
109286b
a136991
a6aa307
4353199
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -307,3 +307,43 @@ def circuit(self, t_duration, steps=None, order=None): | |||||||||||||||||
| steps=steps, | ||||||||||||||||||
| order=order, | ||||||||||||||||||
| ) | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| @dataclass | ||||||||||||||||||
| class tfim_EvolutionOracle(EvolutionOracle): | ||||||||||||||||||
| steps: int = None | ||||||||||||||||||
| B_a: float = None | ||||||||||||||||||
|
|
||||||||||||||||||
| def circuit(self, a, t_duration, B_a, steps=None, order=None): | ||||||||||||||||||
|
||||||||||||||||||
| 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.
Outdated
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:
Outdated
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
Uh oh!
There was an error while loading. Please reload this page.