Skip to content
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

Fix the inverse method of PauliEvolutionGate #7524

Merged
merged 2 commits into from
Jan 27, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions qiskit/circuit/library/pauli_evolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,6 @@ def _define(self):
"""Unroll, where the default synthesis is matrix based."""
self.definition = self.synthesis.synthesize(self)

def inverse(self) -> "PauliEvolutionGate":
return PauliEvolutionGate(operator=self.operator, time=-self.time, synthesis=self.synthesis)

def validate_parameter(
self, parameter: Union[int, float, ParameterExpression]
) -> Union[float, ParameterExpression]:
Expand Down
7 changes: 7 additions & 0 deletions releasenotes/notes/fix-paulievo-inverse-b53a6ecd0ff9a313.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
fixes:
- |
Fix :meth:`~qiskit.circuit.library.PauliEvolutionGate.inverse` which previously computed the
inverse by inverting the evolution time, which is only the correct inverse if the operator
was involved correctly. In particular, this led to the inverse of Trotterization-based time
evolutions being incorrect.
11 changes: 11 additions & 0 deletions test/python/circuit/library/test_evolution_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,14 @@ def test_paulisumop_coefficients_respected(self):
circuit.data[2][0].params[0], # Z
]
self.assertListEqual(rz_angles, [20, 30, -10])

@data(LieTrotter, MatrixExponential)
def test_inverse(self, synth_cls):
"""Test calculating the inverse is correct."""
evo = PauliEvolutionGate(X + Y, time=0.12, synthesis=synth_cls())

circuit = QuantumCircuit(1)
circuit.append(evo, circuit.qubits)
circuit.append(evo.inverse(), circuit.qubits)

self.assertTrue(Operator(circuit).equiv(np.identity(2 ** circuit.num_qubits)))