Skip to content

Commit

Permalink
Replace circuit library pending deprecated classes (Qiskit#13540)
Browse files Browse the repository at this point in the history
* replace Diagonal by DiagonalGate

* replace EfficientSU2 by efficient_su2

* update tests

* revert test

* replace QFT by QFTGate

* update GraphStateGate following review
  • Loading branch information
ShellyGarion authored Dec 17, 2024
1 parent 82bbcaa commit cf5ef03
Show file tree
Hide file tree
Showing 16 changed files with 48 additions and 48 deletions.
8 changes: 4 additions & 4 deletions qiskit/circuit/library/data_preparation/pauli_feature_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ def pauli_feature_map(
q_1: ┤ H ├────────────┤ X ├┤ P(2.0*(pi - x[0])*(pi - x[1])) ├┤ X ├─────────────
└───┘ └───┘└────────────────────────────────┘└───┘
>>> from qiskit.circuit.library import EfficientSU2
>>> from qiskit.circuit.library import efficient_su2
>>> prep = pauli_feature_map(3, reps=3, paulis=["Z", "YY", "ZXZ"])
>>> wavefunction = EfficientSU2(3)
>>> wavefunction = efficient_su2(3)
>>> classifier = prep.compose(wavefunction)
>>> classifier.num_parameters
27
Expand Down Expand Up @@ -286,8 +286,8 @@ def zz_feature_map(
q_1: ┤ H ├┤ P(2.0*x[1]) ├┤ X ├┤ P(2.0*(pi - x[0])*(pi - x[1])) ├┤ X ├
└───┘└─────────────┘└───┘└────────────────────────────────┘└───┘
>>> from qiskit.circuit.library import EfficientSU2
>>> classifier = zz_feature_map(3) + EfficientSU2(3)
>>> from qiskit.circuit.library import efficient_su2
>>> classifier = zz_feature_map(3).compose(efficient_su2(3))
>>> classifier.num_parameters
15
>>> classifier.parameters # 'x' for the data preparation, 'θ' for the SU2 parameters
Expand Down
4 changes: 2 additions & 2 deletions qiskit/circuit/library/generalized_gates/uc.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from qiskit.exceptions import QiskitError
from qiskit._accelerate import uc_gate

from .diagonal import Diagonal
from .diagonal import DiagonalGate

_EPS = 1e-10 # global variable used to chop very small numbers to zero

Expand Down Expand Up @@ -276,7 +276,7 @@ def _dec_ucg(self):
# Important: the diagonal gate is given in the computational basis of the qubits
# q[k-1],...,q[0],q_target (ordered with decreasing significance),
# where q[i] are the control qubits and t denotes the target qubit.
diagonal = Diagonal(diag)
diagonal = DiagonalGate(diag)

circuit.append(diagonal, [q_target] + q_controls)
return circuit, diag
Expand Down
4 changes: 2 additions & 2 deletions qiskit/circuit/library/overlap.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ def unitary_overlap(
:include-source:
import numpy as np
from qiskit.circuit.library import EfficientSU2, unitary_overlap
from qiskit.circuit.library import efficient_su2, unitary_overlap
# get two circuit to prepare states of which we compute the overlap
circuit = EfficientSU2(2, reps=1)
circuit = efficient_su2(2, reps=1)
unitary1 = circuit.assign_parameters(np.random.random(circuit.num_parameters))
unitary2 = circuit.assign_parameters(np.random.random(circuit.num_parameters))
Expand Down
6 changes: 3 additions & 3 deletions test/benchmarks/circuit_construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from qiskit.quantum_info import random_clifford
from qiskit import QuantumRegister, QuantumCircuit
from qiskit.circuit import Parameter
from qiskit.circuit.library import EfficientSU2, QuantumVolume
from qiskit.circuit.library import efficient_su2, quantum_volume
from .utils import dtc_unitary, multi_control_circuit

SEED = 12345
Expand Down Expand Up @@ -112,7 +112,7 @@ def time_QV100_build(self, circuit_size, num_qubits):
"""Measures an SDKs ability to build a 100Q
QV circit from scratch.
"""
return QuantumVolume(circuit_size, num_qubits, seed=SEED)
return quantum_volume(circuit_size, num_qubits, seed=SEED)

def time_DTC100_set_build(self, circuit_size, num_qubits):
"""Measures an SDKs ability to build a set
Expand Down Expand Up @@ -154,7 +154,7 @@ def time_param_circSU2_100_build(self, num_qubits):
over 100Q utilizing 4 repetitions. This will yield a
circuit with 1000 parameters
"""
out = EfficientSU2(num_qubits, reps=4, entanglement="circular", flatten=True)
out = efficient_su2(num_qubits, reps=4, entanglement="circular")
out._build()
return out

Expand Down
4 changes: 2 additions & 2 deletions test/benchmarks/utility_scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import os

from qiskit import QuantumCircuit
from qiskit.circuit.library import EfficientSU2
from qiskit.circuit.library import efficient_su2
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager
from qiskit.providers.fake_provider import GenericBackendV2
from qiskit.transpiler import CouplingMap
Expand Down Expand Up @@ -48,7 +48,7 @@ def setup(self, basis_gate):
self.qaoa_qasm = os.path.join(qasm_dir, "qaoa_barabasi_albert_N100_3reps.qasm")
self.qaoa_qc = QuantumCircuit.from_qasm_file(self.qaoa_qasm)
self.qv_qc = build_qv_model_circuit(50, 50, SEED)
self.circSU2 = EfficientSU2(100, reps=3, entanglement="circular")
self.circSU2 = efficient_su2(100, reps=3, entanglement="circular")
self.bv_100 = bv_all_ones(100)
self.bv_like_100 = trivial_bvlike_circuit(100)

Expand Down
8 changes: 4 additions & 4 deletions test/python/quantum_info/operators/symplectic/test_pauli.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
CYGate,
CZGate,
ECRGate,
EfficientSU2,
efficient_su2,
HGate,
IGate,
SdgGate,
Expand Down Expand Up @@ -515,7 +515,7 @@ def test_circuit_with_bit(self):

def test_apply_layout_with_transpile(self):
"""Test the apply_layout method with a transpiler layout."""
psi = EfficientSU2(4, reps=4, entanglement="circular")
psi = efficient_su2(4, reps=4, entanglement="circular")
op = Pauli("IZZZ")
backend = GenericBackendV2(num_qubits=7)
transpiled_psi = transpile(psi, backend, optimization_level=3, seed_transpiler=12345)
Expand All @@ -530,7 +530,7 @@ def test_apply_layout_with_transpile(self):

def test_apply_layout_consistency(self):
"""Test that the Pauli apply_layout() is consistent with the SparsePauliOp apply_layout()."""
psi = EfficientSU2(4, reps=4, entanglement="circular")
psi = efficient_su2(4, reps=4, entanglement="circular")
op = Pauli("IZZZ")
sparse_op = SparsePauliOp(op)
backend = GenericBackendV2(num_qubits=7)
Expand All @@ -541,7 +541,7 @@ def test_apply_layout_consistency(self):

def test_permute_pauli_estimator_example(self):
"""Test using the apply_layout method with an estimator workflow."""
psi = EfficientSU2(4, reps=4, entanglement="circular")
psi = efficient_su2(4, reps=4, entanglement="circular")
op = Pauli("XXXI")
backend = GenericBackendV2(num_qubits=7, seed=0)
backend.set_options(seed_simulator=123)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

from qiskit import QiskitError
from qiskit.circuit import Parameter, ParameterExpression, ParameterVector
from qiskit.circuit.library import EfficientSU2
from qiskit.circuit.library import efficient_su2
from qiskit.circuit.parametertable import ParameterView
from qiskit.compiler.transpiler import transpile
from qiskit.primitives import BackendEstimator
Expand Down Expand Up @@ -1148,7 +1148,7 @@ def test_paulis_setter_absorbs_phase_2(self):

def test_apply_layout_with_transpile(self):
"""Test the apply_layout method with a transpiler layout."""
psi = EfficientSU2(4, reps=4, entanglement="circular")
psi = efficient_su2(4, reps=4, entanglement="circular")
op = SparsePauliOp.from_list([("IIII", 1), ("IZZZ", 2), ("XXXI", 3)])
backend = GenericBackendV2(num_qubits=7)
transpiled_psi = transpile(psi, backend, optimization_level=3, seed_transpiler=12345)
Expand All @@ -1163,7 +1163,7 @@ def test_apply_layout_with_transpile(self):

def test_permute_sparse_pauli_op_estimator_example(self):
"""Test using the apply_layout method with an estimator workflow."""
psi = EfficientSU2(4, reps=4, entanglement="circular")
psi = efficient_su2(4, reps=4, entanglement="circular")
op = SparsePauliOp.from_list([("IIII", 1), ("IZZZ", 2), ("XXXI", 3)])
backend = GenericBackendV2(num_qubits=7, seed=0)
backend.set_options(seed_simulator=123)
Expand Down
6 changes: 3 additions & 3 deletions test/python/quantum_info/operators/test_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from qiskit import QiskitError
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
from qiskit.circuit import library
from qiskit.circuit.library import HGate, CHGate, CXGate, QFT
from qiskit.circuit.library import HGate, CHGate, CXGate, QFTGate
from qiskit.transpiler import CouplingMap
from qiskit.transpiler.layout import Layout, TranspileLayout
from qiskit.quantum_info.operators import Operator, ScalarOp
Expand Down Expand Up @@ -743,7 +743,7 @@ def test_equiv(self):

def test_reverse_qargs(self):
"""Test reverse_qargs method"""
circ1 = QFT(5)
circ1 = QFTGate(5).definition
circ2 = circ1.reverse_bits()

state1 = Operator(circ1)
Expand All @@ -752,7 +752,7 @@ def test_reverse_qargs(self):

def test_drawings(self):
"""Test draw method"""
qc1 = QFT(5)
qc1 = QFTGate(5).definition
op = Operator.from_circuit(qc1)
with self.subTest(msg="str(operator)"):
str(op)
Expand Down
6 changes: 3 additions & 3 deletions test/python/quantum_info/states/test_densitymatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from numpy.testing import assert_allclose

from qiskit import QiskitError, QuantumCircuit, QuantumRegister
from qiskit.circuit.library import QFT, HGate
from qiskit.circuit.library import QFTGate, HGate
from qiskit.quantum_info.operators.operator import Operator
from qiskit.quantum_info.operators.symplectic import Pauli, SparsePauliOp
from qiskit.quantum_info.random import random_density_matrix, random_pauli, random_unitary
Expand Down Expand Up @@ -1186,7 +1186,7 @@ def test_expval_pauli_qargs(self, qubits):

def test_reverse_qargs(self):
"""Test reverse_qargs method"""
circ1 = QFT(5)
circ1 = QFTGate(5).definition
circ2 = circ1.reverse_bits()

state1 = DensityMatrix.from_instruction(circ1)
Expand All @@ -1197,7 +1197,7 @@ def test_reverse_qargs(self):
@unittest.skipUnless(optionals.HAS_PYLATEX, "requires pylatexenc")
def test_drawings(self):
"""Test draw method"""
qc1 = QFT(5)
qc1 = QFTGate(5).definition
dm = DensityMatrix.from_instruction(qc1)
with self.subTest(msg="str(density_matrix)"):
str(dm)
Expand Down
6 changes: 3 additions & 3 deletions test/python/quantum_info/states/test_statevector.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from qiskit import QiskitError
from qiskit import QuantumRegister, QuantumCircuit
from qiskit import transpile
from qiskit.circuit.library import HGate, QFT, GlobalPhaseGate
from qiskit.circuit.library import HGate, QFTGate, GlobalPhaseGate
from qiskit.providers.basic_provider import BasicSimulator
from qiskit.utils import optionals
from qiskit.quantum_info.random import random_unitary, random_statevector, random_pauli
Expand Down Expand Up @@ -1218,7 +1218,7 @@ def test_global_phase(self):

def test_reverse_qargs(self):
"""Test reverse_qargs method"""
circ1 = QFT(5)
circ1 = QFTGate(5).definition
circ2 = circ1.reverse_bits()

state1 = Statevector.from_instruction(circ1)
Expand All @@ -1229,7 +1229,7 @@ def test_reverse_qargs(self):
@unittest.skipUnless(optionals.HAS_PYLATEX, "requires pylatexenc")
def test_drawings(self):
"""Test draw method"""
qc1 = QFT(5)
qc1 = QFTGate(5).definition
sv = Statevector.from_instruction(qc1)
with self.subTest(msg="str(statevector)"):
str(sv)
Expand Down
9 changes: 4 additions & 5 deletions test/python/transpiler/test_preset_passmanagers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,17 @@

from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister
from qiskit.circuit import Qubit, Gate, ControlFlowOp, ForLoopOp
from qiskit.circuit.library import quantum_volume
from qiskit.compiler import transpile
from qiskit.transpiler import CouplingMap, Layout, PassManager, TranspilerError, Target
from qiskit.circuit.library import U2Gate, U3Gate, QuantumVolume, CXGate, CZGate, XGate
from qiskit.circuit.library import U2Gate, U3Gate, quantum_volume, CXGate, CZGate, XGate
from qiskit.transpiler.passes import (
ALAPScheduleAnalysis,
PadDynamicalDecoupling,
RemoveResetInZeroState,
)
from qiskit.providers.fake_provider import Fake5QV1, Fake20QV1, GenericBackendV2
from qiskit.converters import circuit_to_dag
from qiskit.circuit.library import GraphState
from qiskit.circuit.library import GraphStateGate
from qiskit.quantum_info import random_unitary
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager
from qiskit.transpiler.preset_passmanagers import level0, level1, level2, level3
Expand Down Expand Up @@ -269,7 +268,7 @@ def test_unroll_only_if_not_gates_in_basis(self):
basis_gates=["id", "u1", "u2", "u3", "cx"],
seed=42,
)
qv_circuit = QuantumVolume(3)
qv_circuit = quantum_volume(3)
gates_in_basis_true_count = 0
consolidate_blocks_count = 0

Expand Down Expand Up @@ -1048,7 +1047,7 @@ def test_all_levels_use_trivial_if_perfect(self, level):

adjacency_matrix = np.zeros((20, 20))
adjacency_matrix[rows, cols] = 1
qc = GraphState(adjacency_matrix)
qc = GraphStateGate(adjacency_matrix).definition
qc.measure_all()
expected = {
0: Qubit(QuantumRegister(20, "q"), 0),
Expand Down
6 changes: 3 additions & 3 deletions test/python/transpiler/test_sabre_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from qiskit import QuantumRegister, QuantumCircuit
from qiskit.circuit.classical import expr, types
from qiskit.circuit.library import EfficientSU2, QuantumVolume
from qiskit.circuit.library import efficient_su2, quantum_volume
from qiskit.transpiler import CouplingMap, AnalysisPass, PassManager
from qiskit.transpiler.passes import SabreLayout, DenseLayout, StochasticSwap, Unroll3qOrMore
from qiskit.transpiler.exceptions import TranspilerError
Expand Down Expand Up @@ -321,7 +321,7 @@ def test_release_valve_routes_multiple(self):
Regression test of #13081.
"""
qv = QuantumVolume(500, seed=42)
qv = quantum_volume(500, seed=42)
qv.measure_all()
qc = Unroll3qOrMore()(qv)

Expand Down Expand Up @@ -476,7 +476,7 @@ class TestSabrePreLayout(QiskitTestCase):

def setUp(self):
super().setUp()
circuit = EfficientSU2(16, entanglement="circular", reps=6, flatten=True)
circuit = efficient_su2(16, entanglement="circular", reps=6)
circuit.assign_parameters([math.pi / 2] * len(circuit.parameters), inplace=True)
circuit.measure_all()
self.circuit = circuit
Expand Down
4 changes: 2 additions & 2 deletions test/python/transpiler/test_unitary_synthesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from qiskit import transpile
from qiskit.providers.fake_provider import Fake5QV1, GenericBackendV2
from qiskit.circuit import QuantumCircuit, QuantumRegister, ClassicalRegister
from qiskit.circuit.library import QuantumVolume
from qiskit.circuit.library import quantum_volume
from qiskit.converters import circuit_to_dag, dag_to_circuit
from qiskit.transpiler.passes import UnitarySynthesis
from qiskit.quantum_info.operators import Operator
Expand Down Expand Up @@ -558,7 +558,7 @@ def test_two_qubit_pulse_optimal_none_no_raise(self):

def test_qv_natural(self):
"""check that quantum volume circuit compiles for natural direction"""
qv64 = QuantumVolume(5, seed=15)
qv64 = quantum_volume(5, seed=15)

def construct_passmanager(basis_gates, coupling_map, synthesis_fidelity, pulse_optimize):
seed = 2
Expand Down
11 changes: 6 additions & 5 deletions test/python/transpiler/test_vf2_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from qiskit.converters import circuit_to_dag
from qiskit.providers.fake_provider import Fake5QV1, Fake127QPulseV1, GenericBackendV2
from qiskit.circuit import Measure
from qiskit.circuit.library import GraphState, CXGate, XGate, HGate
from qiskit.circuit.library import GraphStateGate, CXGate, XGate, HGate
from qiskit.transpiler import PassManager, AnalysisPass
from qiskit.transpiler.target import InstructionProperties
from qiskit.transpiler.preset_passmanagers.common import generate_embed_passmanager
Expand Down Expand Up @@ -293,9 +293,9 @@ class TestVF2LayoutLattice(LayoutTestCase):
cmap25 = CouplingMap.from_hexagonal_lattice(25, 25, bidirectional=False)

def graph_state_from_pygraph(self, graph):
"""Creates a GraphState circuit from a PyGraph"""
"""Creates a GraphStateGate circuit from a PyGraph"""
adjacency_matrix = rustworkx.adjacency_matrix(graph)
return GraphState(adjacency_matrix).decompose()
return GraphStateGate(adjacency_matrix).definition

def test_hexagonal_lattice_graph_20_in_25(self):
"""A 20x20 interaction map in 25x25 coupling map"""
Expand Down Expand Up @@ -509,10 +509,11 @@ def test_perfect_fit_Manhattan(self):
rows = [x[0] for x in MANHATTAN_CMAP]
cols = [x[1] for x in MANHATTAN_CMAP]

adj_matrix = numpy.zeros((65, 65))
num_qubits = 65
adj_matrix = numpy.zeros((num_qubits, num_qubits))
adj_matrix[rows, cols] = 1

circuit = GraphState(adj_matrix).decompose()
circuit = GraphStateGate(adj_matrix).definition
circuit.measure_all()

dag = circuit_to_dag(circuit)
Expand Down
4 changes: 2 additions & 2 deletions test/python/visualization/test_circuit_latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
CPhaseGate,
HamiltonianGate,
Isometry,
iqp,
)
from qiskit.circuit import Parameter, Qubit, Clbit
from qiskit.circuit.library import IQP
from qiskit.quantum_info.random import random_unitary
from qiskit.utils import optionals
from .visualization import QiskitVisualizationTestCase
Expand Down Expand Up @@ -295,7 +295,7 @@ def test_big_gates(self):
filename = self._get_resource_path("test_latex_big_gates.tex")
qr = QuantumRegister(6, "q")
circuit = QuantumCircuit(qr)
circuit.append(IQP([[6, 5, 3], [5, 4, 5], [3, 5, 1]]), [0, 1, 2])
circuit.append(iqp([[6, 5, 3], [5, 4, 5], [3, 5, 1]]), [0, 1, 2])

desired_vector = [
1 / math.sqrt(16) * complex(0, 1),
Expand Down
Loading

0 comments on commit cf5ef03

Please sign in to comment.