janus.optimize.synthesis.linear.cnot_synth 源代码

"""
Implementation of the GraySynth algorithm for synthesizing CNOT-Phase
circuits with efficient CNOT cost, and the Patel-Hayes-Markov algorithm
for optimal synthesis of linear (CNOT-only) reversible circuits.
"""

from __future__ import annotations

import numpy as np
from janus.circuit import Circuit as QuantumCircuit
from janus.compat.accelerate.synthesis.linear import synth_cnot_count_full_pmh as fast_pmh


[文档] def synthesize_cnot_count_pmh( state: list[list[bool]] | np.ndarray[bool], section_size: int | None = None ) -> QuantumCircuit: r""" Synthesize linear reversible circuits for all-to-all architecture using Patel, Markov and Hayes method. This function is an implementation of the Patel, Markov and Hayes algorithm from [1] for optimal synthesis of linear reversible circuits for all-to-all architecture, as specified by an :math:`n \times n` matrix. Args: state: :math:`n \times n` boolean invertible matrix, describing the state of the input circuit. section_size: The size of each section in the Patel–Markov–Hayes algorithm [1]. If ``None`` it is chosen to be :math:`\max(2, \alpha\log_2(n))` with :math:`\alpha = 0.56`, which approximately minimizes the upper bound on the number of row operations given in [1] Eq. (3). Returns: A CX-only circuit implementing the linear transformation. Raises: ValueError: When ``section_size`` is larger than the number of columns. References: 1. Patel, Ketan N., Igor L. Markov, and John P. Hayes, *Optimal synthesis of linear reversible circuits*, Quantum Information & Computation 8.3 (2008): 282-294. `arXiv:quant-ph/0302002 [quant-ph] <https://arxiv.org/abs/quant-ph/0302002>`_ """ normalized = np.asarray(state).astype(bool) if section_size is not None and normalized.shape[1] < section_size: raise ValueError( f"The section_size ({section_size}) cannot be larger than the number of columns " f"({normalized.shape[1]})." ) # call Python implementation with normalized input gates = fast_pmh(normalized, section_size if section_size else 2) # construct circuit from the gate list n = normalized.shape[0] circuit = QuantumCircuit(n) for ctrl, tgt in gates: circuit.cx(ctrl, tgt) return circuit
# Backward compatibility alias synth_cnot_count_full_pmh = synthesize_cnot_count_pmh