Skip to content

Commit

Permalink
Merge branch 'main' into 12938-seed-validation
Browse files Browse the repository at this point in the history
  • Loading branch information
jschuhmac committed Aug 20, 2024
2 parents d21971f + 5963027 commit 05b790e
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/accelerate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@ version = "0.2.0"
features = ["ndarray"]

[dependencies.pulp]
version = "0.18.21"
version = "0.18.22"
features = ["macro"]
10 changes: 10 additions & 0 deletions qiskit/circuit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,16 @@
:class:`Qubit` nor :class:`Clbit` operands, but has an explicit :attr:`~Store.lvalue` and
:attr:`~Store.rvalue`.
For example, to determine the parity of a bitstring ``cr`` and store it in another register ``creg``,
the :class:`Store` instruction can be used in the following way::
parity = expr.lift(cr[0])
for i in range(1,n):
parity = expr.bit_xor(cr[i], parity)
qc.store(creg[0], parity)
.. autoclass:: Store
:show-inheritance:
:members:
Expand Down
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
24 changes: 24 additions & 0 deletions qiskit/quantum_info/operators/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,30 @@ class Operator(LinearOp):
.. math::
\rho \mapsto M \rho M^\dagger.
For example, the following operator :math:`M = X` applied to the zero state
:math:`|\psi\rangle=|0\rangle (\rho = |0\rangle\langle 0|)` changes it to the
one state :math:`|\psi\rangle=|1\rangle (\rho = |1\rangle\langle 1|)`:
.. code-block:: python
>>> import numpy as np
>>> from qiskit.quantum_info import Operator
>>> op = Operator(np.array([[0.0, 1.0], [1.0, 0.0]])) # Represents Pauli X operator
>>> from qiskit.quantum_info import Statevector
>>> sv = Statevector(np.array([1.0, 0.0]))
>>> sv.evolve(op)
Statevector([0.+0.j, 1.+0.j],
dims=(2,))
>>> from qiskit.quantum_info import DensityMatrix
>>> dm = DensityMatrix(np.array([[1.0, 0.0], [0.0, 0.0]]))
>>> dm.evolve(op)
DensityMatrix([[0.+0.j, 0.+0.j],
[0.+0.j, 1.+0.j]],
dims=(2,))
"""

def __init__(
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 05b790e

Please sign in to comment.