Skip to content

Commit

Permalink
move aqc_plugin to qiskit/transpiler/passes/synthesis
Browse files Browse the repository at this point in the history
  • Loading branch information
ShellyGarion committed Dec 19, 2023
1 parent 2bf99a3 commit f884e6d
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Changelog = "https://qiskit.org/documentation/release_notes.html"

[project.entry-points."qiskit.unitary_synthesis"]
default = "qiskit.transpiler.passes.synthesis.unitary_synthesis:DefaultUnitarySynthesis"
aqc = "qiskit.transpiler.synthesis.aqc.aqc_plugin:AQCSynthesisPlugin"
aqc = "qiskit.transpiler.passes.synthesis.aqc_plugin:AQCSynthesisPlugin"
sk = "qiskit.transpiler.passes.synthesis.solovay_kitaev_synthesis:SolovayKitaevSynthesis"

[project.entry-points."qiskit.synthesis"]
Expand Down
2 changes: 2 additions & 0 deletions qiskit/transpiler/passes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
HLSConfig
SolovayKitaev
SolovayKitaevSynthesis
AQCSynthesisPlugin
Post Layout (Post transpile qubit selection)
============================================
Expand Down Expand Up @@ -253,6 +254,7 @@
from .synthesis import HLSConfig
from .synthesis import SolovayKitaev
from .synthesis import SolovayKitaevSynthesis
from .synthesis import AQCSynthesisPlugin

# calibration
from .calibration import PulseGates
Expand Down
1 change: 1 addition & 0 deletions qiskit/transpiler/passes/synthesis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@
from .linear_functions_synthesis import LinearFunctionsSynthesis, LinearFunctionsToPermutations
from .high_level_synthesis import HighLevelSynthesis, HLSConfig
from .solovay_kitaev_synthesis import SolovayKitaev, SolovayKitaevSynthesis
from .aqc_plugin import AQCSynthesisPlugin
146 changes: 146 additions & 0 deletions qiskit/transpiler/passes/synthesis/aqc_plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2021, 2023.
#
# 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.
"""
An AQC synthesis plugin to Qiskit's transpiler.
"""
from functools import partial
import numpy as np

from qiskit.converters import circuit_to_dag
from qiskit.transpiler.passes.synthesis.plugin import UnitarySynthesisPlugin


class AQCSynthesisPlugin(UnitarySynthesisPlugin):
"""
An AQC-based Qiskit unitary synthesis plugin.
This plugin is invoked by :func:`~.compiler.transpile` when the ``unitary_synthesis_method``
parameter is set to ``"aqc"``.
This plugin supports customization and additional parameters can be passed to the plugin
by passing a dictionary as the ``unitary_synthesis_plugin_config`` parameter of
the :func:`~qiskit.compiler.transpile` function.
Supported parameters in the dictionary:
network_layout (str)
Type of network geometry, one of {``"sequ"``, ``"spin"``, ``"cart"``, ``"cyclic_spin"``,
``"cyclic_line"``}. Default value is ``"spin"``.
connectivity_type (str)
type of inter-qubit connectivity, {``"full"``, ``"line"``, ``"star"``}. Default value
is ``"full"``.
depth (int)
depth of the CNOT-network, i.e. the number of layers, where each layer consists of a
single CNOT-block.
optimizer (:class:`~.Minimizer`)
An implementation of the ``Minimizer`` protocol to be used in the optimization process.
seed (int)
A random seed.
initial_point (:class:`~numpy.ndarray`)
Initial values of angles/parameters to start the optimization process from.
"""

@property
def max_qubits(self):
"""Maximum number of supported qubits is ``14``."""
return 14

@property
def min_qubits(self):
"""Minimum number of supported qubits is ``3``."""
return 3

@property
def supports_natural_direction(self):
"""The plugin does not support natural direction,
it assumes bidirectional two qubit gates."""
return False

@property
def supports_pulse_optimize(self):
"""The plugin does not support optimization of pulses."""
return False

@property
def supports_gate_lengths(self):
"""The plugin does not support gate lengths."""
return False

@property
def supports_gate_errors(self):
"""The plugin does not support gate errors."""
return False

@property
def supported_bases(self):
"""The plugin does not support bases for synthesis."""
return None

@property
def supports_basis_gates(self):
"""The plugin does not support basis gates and by default it synthesizes a circuit using
``["rx", "ry", "rz", "cx"]`` gate basis."""
return False

@property
def supports_coupling_map(self):
"""The plugin does not support coupling maps."""
return False

def run(self, unitary, **options):

# Runtime imports to avoid the overhead of these imports for
# plugin discovery and only use them if the plugin is run/used
from scipy.optimize import minimize
from qiskit.transpiler.synthesis.aqc.aqc import AQC
from qiskit.transpiler.synthesis.aqc.cnot_structures import make_cnot_network
from qiskit.transpiler.synthesis.aqc.cnot_unit_circuit import CNOTUnitCircuit
from qiskit.transpiler.synthesis.aqc.cnot_unit_objective import DefaultCNOTUnitObjective

num_qubits = int(round(np.log2(unitary.shape[0])))

config = options.get("config") or {}

network_layout = config.get("network_layout", "spin")
connectivity_type = config.get("connectivity_type", "full")
depth = config.get("depth", 0)

cnots = make_cnot_network(
num_qubits=num_qubits,
network_layout=network_layout,
connectivity_type=connectivity_type,
depth=depth,
)

default_optimizer = partial(minimize, args=(), method="L-BFGS-B", options={"maxiter": 1000})
optimizer = config.get("optimizer", default_optimizer)
seed = config.get("seed")
aqc = AQC(optimizer, seed)

approximate_circuit = CNOTUnitCircuit(num_qubits=num_qubits, cnots=cnots)
approximating_objective = DefaultCNOTUnitObjective(num_qubits=num_qubits, cnots=cnots)

initial_point = config.get("initial_point")
aqc.compile_unitary(
target_matrix=unitary,
approximate_circuit=approximate_circuit,
approximating_objective=approximating_objective,
initial_point=initial_point,
)

dag_circuit = circuit_to_dag(approximate_circuit)
return dag_circuit
2 changes: 0 additions & 2 deletions qiskit/transpiler/synthesis/aqc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
:template: autosummary/class_no_inherited_members.rst
AQC
AQCSynthesisPlugin
ApproximateCircuit
ApproximatingObjective
CNOTUnitCircuit
Expand Down Expand Up @@ -171,7 +170,6 @@

from .approximate import ApproximateCircuit, ApproximatingObjective
from .aqc import AQC
from .aqc_plugin import AQCSynthesisPlugin
from .cnot_structures import make_cnot_network
from .cnot_unit_circuit import CNOTUnitCircuit
from .cnot_unit_objective import CNOTUnitObjective, DefaultCNOTUnitObjective
Expand Down
7 changes: 7 additions & 0 deletions qiskit/transpiler/synthesis/aqc/aqc_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from qiskit.converters import circuit_to_dag
from qiskit.transpiler.passes.synthesis.plugin import UnitarySynthesisPlugin
from qiskit.utils.deprecation import deprecate_func


class AQCSynthesisPlugin(UnitarySynthesisPlugin):
Expand Down Expand Up @@ -101,6 +102,12 @@ def supports_coupling_map(self):
"""The plugin does not support coupling maps."""
return False

@deprecate_func(
since="0.46.0",
pending=True,
additional_msg="AQCSynthesisPlugin has been moved to qiskit.transpiler.passes.synthesis"
"instead use AQCSynthesisPlugin from qiskit.transpiler.passes.synthesis",
)
def run(self, unitary, **options):

# Runtime imports to avoid the overhead of these imports for
Expand Down
2 changes: 1 addition & 1 deletion test/python/transpiler/aqc/test_aqc_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from qiskit.test import QiskitTestCase
from qiskit.transpiler import PassManager
from qiskit.transpiler.passes import UnitarySynthesis
from qiskit.transpiler.synthesis.aqc.aqc_plugin import AQCSynthesisPlugin
from qiskit.transpiler.passes.synthesis import AQCSynthesisPlugin


class TestAQCSynthesisPlugin(QiskitTestCase):
Expand Down

0 comments on commit f884e6d

Please sign in to comment.