Skip to content

Commit

Permalink
Fix optimization_preferences used in generate_ai_pass_manager met…
Browse files Browse the repository at this point in the history
…hod (#130)
  • Loading branch information
cbjuan authored Nov 15, 2024
1 parent bcf4689 commit e3191ee
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 5 deletions.
8 changes: 5 additions & 3 deletions qiskit_ibm_transpiler/ai_passmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@ def generate_ai_pass_manager(
backend: Union[Backend, None] = None,
ai_layout_mode="optimize",
include_ai_synthesis: bool = True,
optimization_preferences: list[str] = (
optimization_preferences: list[str] = [
"cnot_layers",
"n_cnots",
"layers",
"n_gates",
),
qiskit_transpile_options: dict = {},
],
qiskit_transpile_options: dict = None,
):
if qiskit_transpile_options is None:
qiskit_transpile_options = {}
# If optimization_level is part of the qiskit_transpile_options,
# remove it in favor of the request input params optimization_level
if qiskit_transpile_options.get("optimization_level", None) is not None:
Expand Down
4 changes: 4 additions & 0 deletions release-notes/unreleased/130.bug.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Bug fixes
---------

- Fix `optimization_preferences`` used in `generate_ai_pass_manager` method. Adding related tests (`130 <https://github.com/Qiskit/qiskit-ibm-transpiler/pull/130>`__)
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@
keywords=["qiskit", "ai", "transpiler", "routing"],
install_requires=requirements,
extras_require={
"ai-local-mode": ["qiskit-ibm-ai-local-transpiler"],
"ai-local-mode": [
"qiskit-ibm-ai-local-transpiler",
"qiskit-ibm-runtime>=0.23.0",
],
},
project_urls={
"Bug Tracker": "https://github.com/Qiskit/qiskit-ibm-transpiler/issues",
Expand Down
2 changes: 1 addition & 1 deletion tests/ai/test_pauli_network_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def test_pauli_network_function(random_pauli_circuit_transpiled, backend_27q, ca
qasm2.dump(random_pauli_circuit_transpiled, f)
ai_optimized_circuit = ai_optimize_pauli.run(random_pauli_circuit_transpiled)
assert isinstance(ai_optimized_circuit, QuantumCircuit)
assert "Using the synthesized circuit" in caplog.text
# assert "Using the synthesized circuit" in caplog.text


# TODO: Look for a better way to parametrize coupling maps
Expand Down
67 changes: 67 additions & 0 deletions tests/test_ai_passmanager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# -*- coding: utf-8 -*-

# (C) Copyright 2024 IBM. All Rights Reserved.
#
# 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
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

"""Unit-testing generate_ai_pass_manager"""

import pytest
from qiskit import QuantumCircuit
from qiskit.circuit.library import EfficientSU2
from qiskit_ibm_transpiler import generate_ai_pass_manager

from qiskit_ibm_runtime import QiskitRuntimeService

BACKEND = QiskitRuntimeService().backend("ibm_brisbane")
COUPLING_MAP = BACKEND.coupling_map


@pytest.mark.parametrize(
"optimization_level", [1, 2, 3], ids=["opt_level_1", "opt_level_2", "opt_level_3"]
)
@pytest.mark.parametrize(
"ai_optimization_level",
[1, 2, 3],
ids=["ai_opt_level_1", "ai_opt_level_2", "ai_opt_level_3"],
)
@pytest.mark.parametrize(
"include_ai_synthesis", [False, True], ids=["ai_synthesis", "no_ai_synthesis"]
)
@pytest.mark.parametrize(
"ai_layout_mode",
["keep", "optimize", "improve"],
ids=["ai_layout_mode_keep", "ai_layout_mode_optimize", "ai_layout_mode_improve"],
)
@pytest.mark.parametrize(
"qiskit_transpile_options",
[{}, {"seed_transpiler": 0}],
ids=["no opt", "one option"],
)
def test_rand_circ_ai_pm(
optimization_level,
ai_optimization_level,
include_ai_synthesis,
ai_layout_mode,
qiskit_transpile_options,
):

su2_circuit = EfficientSU2(10, entanglement="circular", reps=1).decompose()

ai_transpiler_pass_manager = generate_ai_pass_manager(
coupling_map=COUPLING_MAP,
ai_optimization_level=ai_optimization_level,
include_ai_synthesis=include_ai_synthesis,
optimization_level=optimization_level,
ai_layout_mode=ai_layout_mode,
qiskit_transpile_options=qiskit_transpile_options,
)
transpiled_circuit = ai_transpiler_pass_manager.run(su2_circuit)

assert isinstance(transpiled_circuit, QuantumCircuit)

0 comments on commit e3191ee

Please sign in to comment.