Skip to content

Commit

Permalink
fix stateprep's normalize (Qiskit#12988)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cryoris committed Aug 19, 2024
1 parent 393fb59 commit 5963027
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def _define_synthesis_isom(self):
q = QuantumRegister(self.num_qubits, "q")
initialize_circuit = QuantumCircuit(q, name="init_def")

isom = Isometry(self._params_arg, 0, 0)
isom = Isometry(self.params, 0, 0)
initialize_circuit.append(isom, q[:])

# invert the circuit to create the desired vector from zero (assuming
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
fixes:
- |
Fixed a bug in :class:`.StatePreparation` where the ``normalize``
argument was ignored for input arrays.
Fixed `#12984 <https://github.com/Qiskit/qiskit/issues/12984>`__.
10 changes: 10 additions & 0 deletions test/python/circuit/library/test_state_preparation.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,16 @@ def test_repeats(self):
qc.append(StatePreparation("01").repeat(2), [0, 1])
self.assertEqual(qc.decompose().count_ops()["state_preparation"], 2)

def test_normalize(self):
"""Test the normalization.
Regression test of #12984.
"""
qc = QuantumCircuit(1)
qc.compose(StatePreparation([1, 1], normalize=True), range(1), inplace=True)

self.assertTrue(Statevector(qc).equiv(np.array([1, 1]) / np.sqrt(2)))


if __name__ == "__main__":
unittest.main()

0 comments on commit 5963027

Please sign in to comment.