Skip to content

Commit

Permalink
Fix Trotter evolution of sums with identity terms (qiskit-community/q…
Browse files Browse the repository at this point in the history
…iskit-aqua#1304)

* Fix Trotter evolution of sums with identity terms

Previously, Trotterization did not exclude any terms consisting of a scalar times the
identity from the list of terms to be repeated. Instead, if present, an identity term was
included in the resulting circuit as repeated identity gates, with the coefficient of the
identity operator discarded.  But, this coefficient must be accounted for: exp(-i * coeff
* I) should introduce a global phase.

With this PR, we remove the scalar-multiple-of-identity terms from the SummedOp to be
Trotterized. We then set the global phase of the resulting circuit to account for the
removed identity term.

Fixes qiskit-community/qiskit-aqua#1269

* Add test for Trotter evolution of sums with identity terms

* Add release note for fix-trotter-global-phase

* Fix linter complaints

Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com>
  • Loading branch information
jlapeyre and woodsp-ibm authored Oct 2, 2020
1 parent eda3493 commit 6b44e1c
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions qiskit/aqua/operators/evolutions/pauli_trotter_evolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,20 @@ def _recursive_convert(self, operator: OperatorBase) -> OperatorBase:
# if operator.primitive.abelian:
# return self.evolution_for_abelian_paulisum(operator.primitive)
# else:
trotterized = self.trotter.convert(operator.primitive)
return self._recursive_convert(trotterized)
# Collect terms that are not the identity.
oplist = [x for x in operator.primitive if not isinstance(x, PauliOp)
or sum(x.primitive.x + x.primitive.z) != 0] # type: ignore
# Collect the coefficients of any identity terms,
# which become global phases when exponentiated.
identity_phases = [x.coeff for x in operator.primitive if isinstance(x, PauliOp)
and sum(x.primitive.x + x.primitive.z) == 0] # type: ignore
# Construct sum without the identity operators.
new_primitive = SummedOp(oplist, coeff=operator.primitive.coeff)
trotterized = self.trotter.convert(new_primitive)
circuit_no_identities = self._recursive_convert(trotterized)
# Set the global phase of the QuantumCircuit to account for removed identity terms.
circuit_no_identities.primitive.global_phase = -sum(identity_phases) # type: ignore
return circuit_no_identities
elif isinstance(operator.primitive, PauliOp):
return self.evolution_for_pauli(operator.primitive)
# Covers ListOp, ComposedOp, TensoredOp
Expand Down

0 comments on commit 6b44e1c

Please sign in to comment.