Skip to content

Commit d315e35

Browse files
hsim13372jarrodmcc
authored andcommitted
Created generalized evolution operator for uccsd (#68)
* Adds generalized UCCSD evolution operator and abstracts singlet case to a special instance of this operator.
1 parent a6746ce commit d315e35

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

src/fermilib/utils/_unitary_cc.py

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,34 @@ def t2_ind(i, j, k, l):
209209
return uccsd_generator
210210

211211

212+
def uccsd_evolution(fermion_generator, fermion_transform=jordan_wigner):
213+
"""Create a ProjectQ evolution operator for a UCCSD circuit
214+
215+
Args:
216+
fermion_generator(FermionOperator): UCCSD generator to evolve.
217+
fermion_transform(fermilib.transform): The transformation that
218+
defines the mapping from Fermions to QubitOperator.
219+
220+
Returns:
221+
evoution_operator(projectq.ops.TimeEvolution): The unitary operator
222+
that constructs the UCCSD state.
223+
"""
224+
225+
# Transform generator to qubits
226+
qubit_generator = fermion_transform(fermion_generator)
227+
228+
# Cast to real part only for compatibility with current ProjectQ routine
229+
for key in qubit_generator.terms:
230+
qubit_generator.terms[key] = float(qubit_generator.terms[key].imag)
231+
qubit_generator.compress()
232+
233+
# Allocate wavefunction and act evolution on gate according to compilation
234+
evolution_operator = (
235+
projectq.ops.TimeEvolution(time=1., hamiltonian=qubit_generator))
236+
237+
return evolution_operator
238+
239+
212240
def uccsd_singlet_evolution(packed_amplitudes, n_qubits, n_electrons,
213241
fermion_transform=jordan_wigner):
214242
"""Create a ProjectQ evolution operator for a UCCSD singlet circuit
@@ -232,17 +260,9 @@ def uccsd_singlet_evolution(packed_amplitudes, n_qubits, n_electrons,
232260
fermion_generator = uccsd_singlet_operator(packed_amplitudes,
233261
n_qubits,
234262
n_electrons)
235-
# Transform generator to qubits
236-
qubit_generator = fermion_transform(fermion_generator)
237263

238-
# Cast to real part only for compatibility with current ProjectQ routine
239-
for key in qubit_generator.terms:
240-
qubit_generator.terms[key] = float(qubit_generator.terms[key].imag)
241-
qubit_generator.compress()
242-
243-
# Allocate wavefunction and act evolution on gate according to compilation
244-
evolution_operator = (
245-
projectq.ops.TimeEvolution(time=1., hamiltonian=qubit_generator))
264+
evolution_operator = uccsd_evolution(fermion_generator,
265+
fermion_transform)
246266

247267
return evolution_operator
248268

src/fermilib/utils/_unitary_cc_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import unittest
1818
from numpy.random import randn
19+
import itertools
1920

2021
import fermilib
2122
import fermilib.ops

0 commit comments

Comments
 (0)