Skip to content

Commit

Permalink
Fix compatibility/deprecations with newer Qiskit versions (#317) (#318)
Browse files Browse the repository at this point in the history
(cherry picked from commit 65bd8e2)

Co-authored-by: Steve Wood <[email protected]>
  • Loading branch information
mergify[bot] and woodsp-ibm authored Feb 6, 2024
1 parent 87e3230 commit 93e5718
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of a Qiskit project.
#
# (C) Copyright IBM 2018, 2023.
# (C) Copyright IBM 2018, 2024.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
Expand Down Expand Up @@ -54,7 +54,7 @@ def __init__(
)

super().__init__(*european_call.qregs, name="ECEV")
self._data = european_call.data
self.data = european_call.data
self._european_call = european_call

def post_processing(self, scaled_value: float) -> float:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of a Qiskit project.
#
# (C) Copyright IBM 2017, 2023.
# (C) Copyright IBM 2017, 2024.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
Expand All @@ -14,7 +14,10 @@

from typing import Tuple, List, Union, Optional
import numpy as np

from qiskit.circuit import QuantumCircuit
from qiskit.circuit.library import Initialize, Isometry

from .normal import _check_bounds_valid, _check_dimensions_match


Expand Down Expand Up @@ -162,13 +165,10 @@ def __init__(
super().__init__(*inner.qregs, name=name)

# use default the isometry (or initialize w/o resets) algorithm to construct the circuit
# pylint: disable=no-member
if upto_diag:
inner.isometry(np.sqrt(normalized_probabilities), inner.qubits, None)
inner.append(Isometry(np.sqrt(normalized_probabilities), 0, 0), inner.qubits)
self.append(inner.to_instruction(), inner.qubits) # Isometry is not a Gate
else:
from qiskit.extensions import Initialize # pylint: disable=cyclic-import

initialize = Initialize(np.sqrt(normalized_probabilities))
circuit = initialize.gates_to_uncompute().inverse()
inner.compose(circuit, inplace=True)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of a Qiskit project.
#
# (C) Copyright IBM 2017, 2023.
# (C) Copyright IBM 2017, 2024.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
Expand All @@ -14,7 +14,9 @@

from typing import Tuple, Union, List, Optional, Any
import numpy as np

from qiskit.circuit import QuantumCircuit
from qiskit.circuit.library import Initialize, Isometry


class NormalDistribution(QuantumCircuit):
Expand Down Expand Up @@ -208,13 +210,10 @@ def __init__(
super().__init__(*inner.qregs, name=name)

# use default the isometry (or initialize w/o resets) algorithm to construct the circuit
# pylint: disable=no-member
if upto_diag:
inner.isometry(np.sqrt(normalized_probabilities), inner.qubits, None)
inner.append(Isometry(np.sqrt(normalized_probabilities), 0, 0), inner.qubits)
self.append(inner.to_instruction(), inner.qubits) # Isometry is not a Gate
else:
from qiskit.extensions import Initialize # pylint: disable=cyclic-import

initialize = Initialize(np.sqrt(normalized_probabilities))
circuit = initialize.gates_to_uncompute().inverse()
inner.compose(circuit, inplace=True)
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
qiskit>=0.44
qiskit>=0.45
qiskit-algorithms>=0.2.0
qiskit-optimization>=0.6.0
scipy>=1.4
Expand Down
12 changes: 6 additions & 6 deletions test/circuit/test_probability_distributions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of a Qiskit project.
#
# (C) Copyright IBM 2017, 2023.
# (C) Copyright IBM 2017, 2024.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
Expand All @@ -13,12 +13,12 @@
"""Test library of probability distribution circuits."""

import unittest
from ddt import ddt, data, unpack
from test import QiskitFinanceTestCase

from ddt import ddt, data, unpack
import numpy as np
from scipy.stats import multivariate_normal

from qiskit.test.base import QiskitTestCase
from qiskit.circuit import QuantumCircuit
from qiskit.quantum_info import Statevector
from qiskit_finance.circuit.library import (
Expand All @@ -28,7 +28,7 @@
)


class TestUniformDistribution(QiskitTestCase):
class TestUniformDistribution(QiskitFinanceTestCase):
"""Test the uniform distribution circuit."""

def test_uniform(self):
Expand All @@ -41,7 +41,7 @@ def test_uniform(self):


@ddt
class TestNormalDistribution(QiskitTestCase):
class TestNormalDistribution(QiskitFinanceTestCase):
"""Test the normal distribution circuit."""

def assertDistributionIsCorrect(self, circuit, num_qubits, mu, sigma, bounds, upto_diag):
Expand Down Expand Up @@ -146,7 +146,7 @@ def test_bounds_invalid(self, bounds):


@ddt
class TestLogNormalDistribution(QiskitTestCase):
class TestLogNormalDistribution(QiskitFinanceTestCase):
"""Test the normal distribution circuit."""

def assertDistributionIsCorrect(self, circuit, num_qubits, mu, sigma, bounds, upto_diag):
Expand Down

0 comments on commit 93e5718

Please sign in to comment.