Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

virtual padding for invalid section_size in synth_cnot_count_full_pmh #12712

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions qiskit/synthesis/linear/cnot_synth.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ def synth_cnot_count_full_pmh(
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].
section_size: The size of each section, used in the
Patel–Markov–Hayes algorithm [1]. ``section_size`` must be a factor of the number
of qubits.

Returns:
QuantumCircuit: a CX-only circuit implementing the linear transformation.
Expand All @@ -51,11 +53,18 @@ def synth_cnot_count_full_pmh(
Quantum Information & Computation 8.3 (2008): 282-294.
`arXiv:quant-ph/0302002 [quant-ph] <https://arxiv.org/abs/quant-ph/0302002>`_
"""

if not isinstance(state, (list, np.ndarray)):
raise QiskitError(
f"state should be of type list or numpy.ndarray, but was of the type {type(state)}"
)
state = np.array(state)
num_qubits = state.shape[0]

# Raise an error if section_size is larger than the number of qubits
if section_size > num_qubits:
raise QiskitError(f"section_size ({section_size}) cannot be larger than the number of qubits ({num_qubits})")

# Synthesize lower triangular part
[state, circuit_l] = _lwr_cnot_synth(state, section_size)
state = np.transpose(state)
Expand Down Expand Up @@ -139,4 +148,4 @@ def _lwr_cnot_synth(state, section_size):
if sum(state[col, :] & state[row, :]) > cutoff:
state[col, :] ^= state[row, :]
circuit.append([row, col])
return [state, circuit]
return [state, circuit]
Loading