@@ -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+
212240def 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
0 commit comments