Skip to content

Commit

Permalink
Include missing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ElePT committed Nov 28, 2023
1 parent 9f06c82 commit 68c145c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion qiskit/providers/fake_provider/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,4 +265,4 @@

# Configurable fake backend
from .utils.configurable_backend import ConfigurableFakeBackend
from .fake_generic import FakeGeneric
from .fake_generic import FakeGeneric, GenericTarget
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from qiskit.test import QiskitTestCase
from qiskit.circuit.library import EfficientSU2
from qiskit.primitives import BackendEstimator
from qiskit.providers.fake_provider import FakeNairobiV2
from qiskit.providers.fake_provider import FakeGeneric
from qiskit.compiler.transpiler import transpile


Expand Down Expand Up @@ -1033,7 +1033,7 @@ def test_apply_layout_with_transpile(self):
"""Test the apply_layout method with a transpiler layout."""
psi = EfficientSU2(4, reps=4, entanglement="circular")
op = SparsePauliOp.from_list([("IIII", 1), ("IZZZ", 2), ("XXXI", 3)])
backend = FakeNairobiV2()
backend = FakeGeneric(num_qubits=7, basis_gates=["cx", "x", "id", "sx", "rz"])
transpiled_psi = transpile(psi, backend, optimization_level=3, seed_transpiler=12345)
permuted_op = op.apply_layout(transpiled_psi.layout)
identity_op = SparsePauliOp("I" * 7)
Expand All @@ -1048,15 +1048,15 @@ 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")
op = SparsePauliOp.from_list([("IIII", 1), ("IZZZ", 2), ("XXXI", 3)])
backend = FakeNairobiV2()
backend = FakeGeneric(num_qubits=7, basis_gates=["cx", "x", "id", "sx", "rz"], seed=0)
backend.set_options(seed_simulator=123)
estimator = BackendEstimator(backend=backend, skip_transpilation=True)
thetas = list(range(len(psi.parameters)))
transpiled_psi = transpile(psi, backend, optimization_level=3)
permuted_op = op.apply_layout(transpiled_psi.layout)
job = estimator.run(transpiled_psi, permuted_op, thetas)
res = job.result().values
np.testing.assert_allclose(res, [1.35351562], rtol=0.5, atol=0.2)
np.testing.assert_allclose(res, [5.859375], rtol=0.5, atol=0.2)

def test_apply_layout_invalid_qubits_list(self):
"""Test that apply_layout with an invalid qubit count raises."""
Expand Down
8 changes: 4 additions & 4 deletions test/python/transpiler/test_normalize_rx_angle.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
NormalizeRXAngle,
)
from qiskit.test import QiskitTestCase
from qiskit.providers.fake_provider import FakeBelemV2
from qiskit.providers.fake_provider import FakeGeneric
from qiskit.transpiler import Target
from qiskit.circuit.library.standard_gates import SXGate

Expand Down Expand Up @@ -60,7 +60,7 @@ def test_rz_added_for_negative_rotation_angles(self):
"""Check that RZ is added before and after RX,
if RX rotation angle is negative"""

backend = FakeBelemV2()
backend = FakeGeneric(num_qubits=5, basis_gates=["cx", "x", "id", "sx", "rz"])
tp = NormalizeRXAngle(target=backend.target)

# circuit to transpile and test
Expand All @@ -83,7 +83,7 @@ def test_rz_added_for_negative_rotation_angles(self):
)
def test_angle_wrapping_works(self, raw_theta, correct_wrapped_theta):
"""Check that RX rotation angles are correctly wrapped to [0, pi]"""
backend = FakeBelemV2()
backend = FakeGeneric(num_qubits=5, basis_gates=["cx", "x", "id", "sx", "rz"])
tp = NormalizeRXAngle(target=backend.target)

# circuit to transpile and test
Expand Down Expand Up @@ -118,7 +118,7 @@ def test_quantize_angles(self, resolution, rx_angles, correct_num_of_cals):
"""Test that quantize_angles() adds a new calibration only if
the requested angle is not in the vicinity of the already generated angles.
"""
backend = FakeBelemV2()
backend = FakeGeneric(num_qubits=5, basis_gates=["cx", "x", "id", "sx", "rz"])
tp = NormalizeRXAngle(backend.target, resolution_in_radian=resolution)

qc = QuantumCircuit(1)
Expand Down
10 changes: 6 additions & 4 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.test import QiskitTestCase
from qiskit.providers.fake_provider import FakeVigo, FakeMumbaiFractionalCX, FakeBelemV2
from qiskit.providers.fake_provider import FakeVigo, FakeMumbaiFractionalCX, FakeGeneric
from qiskit.providers.fake_provider.fake_backend_v2 import FakeBackendV2, FakeBackend5QV2
from qiskit.circuit import QuantumCircuit, QuantumRegister, ClassicalRegister
from qiskit.circuit.library import QuantumVolume
Expand Down Expand Up @@ -846,7 +846,8 @@ def test_single_qubit_with_target(self):
qc = QuantumCircuit(1)
qc.append(ZGate(), [qc.qubits[0]])
dag = circuit_to_dag(qc)
unitary_synth_pass = UnitarySynthesis(target=FakeBelemV2().target)
backend = FakeGeneric(num_qubits=5, basis_gates=["cx", "x", "id", "sx", "rz"])
unitary_synth_pass = UnitarySynthesis(target=backend.target)
result_dag = unitary_synth_pass.run(dag)
result_qc = dag_to_circuit(result_dag)
self.assertEqual(qc, result_qc)
Expand All @@ -856,7 +857,8 @@ def test_single_qubit_identity_with_target(self):
qc = QuantumCircuit(1)
qc.unitary([[1.0, 0.0], [0.0, 1.0]], 0)
dag = circuit_to_dag(qc)
unitary_synth_pass = UnitarySynthesis(target=FakeBelemV2().target)
backend = FakeGeneric(num_qubits=5, basis_gates=["cx", "x", "id", "sx", "rz"])
unitary_synth_pass = UnitarySynthesis(target=backend.target)
result_dag = unitary_synth_pass.run(dag)
result_qc = dag_to_circuit(result_dag)
self.assertEqual(result_qc, QuantumCircuit(1))
Expand All @@ -866,7 +868,7 @@ def test_unitary_synthesis_with_ideal_and_variable_width_ops(self):
qc = QuantumCircuit(2)
qc.unitary(np.eye(4), [0, 1])
dag = circuit_to_dag(qc)
target = FakeBelemV2().target
target = FakeGeneric(num_qubits=5, basis_gates=["cx", "x", "id", "sx", "rz"]).target
target.add_instruction(IfElseOp, name="if_else")
target.add_instruction(ZGate())
target.add_instruction(ECRGate())
Expand Down

0 comments on commit 68c145c

Please sign in to comment.