Skip to content

Commit

Permalink
Reduce number of compose calls in LieTrotter synthesis (#12021)
Browse files Browse the repository at this point in the history
* Reduce number of compose calls in LieTrotter synthesis

* Decompose the output

* Update lie_trotter.py

* Update lie_trotter.py

* release note

* Update release note section

---------

Co-authored-by: Max Rossmannek <oss@zurich.ibm.com>
  • Loading branch information
caleb-johnson and mrossinek committed Mar 21, 2024
1 parent dd2570b commit c6f4d46
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
21 changes: 7 additions & 14 deletions qiskit/synthesis/evolution/lie_trotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ def synthesize(self, evolution):

# construct the evolution circuit
evolution_circuit = QuantumCircuit(operators[0].num_qubits)
first_barrier = False

if not isinstance(operators, list):
pauli_list = [(Pauli(op), np.real(coeff)) for op, coeff in operators.to_list()]
Expand All @@ -86,20 +85,14 @@ def synthesize(self, evolution):
# if we only evolve a single Pauli we don't need to additionally wrap it
wrap = not (len(pauli_list) == 1 and self.reps == 1)

for _ in range(self.reps):
for op, coeff in pauli_list:
# add barriers
if first_barrier:
if self.insert_barriers:
evolution_circuit.barrier()
else:
first_barrier = True

evolution_circuit.compose(
self.atomic_evolution(op, coeff * time / self.reps), wrap=wrap, inplace=True
)
for i, (op, coeff) in enumerate(pauli_list):
evolution_circuit.compose(
self.atomic_evolution(op, coeff * time / self.reps), wrap=wrap, inplace=True
)
if self.insert_barriers and i != len(pauli_list) - 1:
evolution_circuit.barrier()

return evolution_circuit
return evolution_circuit.repeat(self.reps).decompose()

@property
def settings(self) -> Dict[str, Any]:
Expand Down
6 changes: 6 additions & 0 deletions releasenotes/notes/faster-lie-trotter-ba8f6dd84fe4cae4.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
features_synthesis:
- |
:meth:`.LieTrotter.synthesize` now uses :meth:`.QuantumCircuit.repeat` to generate additional reps
after the first. This reduces the number of :meth:`.QuantumCircuit.compose` calls by a factor of
``reps`` and significantly reduces the runtime for larger operators.

0 comments on commit c6f4d46

Please sign in to comment.