Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make unrealized SingleQubitQPDGate has definition of None rather …
Browse files Browse the repository at this point in the history
…than error

Fixes #417 according to #417 (comment)
garrison committed Oct 27, 2023
1 parent 2df0933 commit 580b9b9
Showing 2 changed files with 6 additions and 17 deletions.
16 changes: 5 additions & 11 deletions circuit_knitting/cutting/qpd/instructions/qpd_gate.py
Original file line number Diff line number Diff line change
@@ -14,14 +14,12 @@

from __future__ import annotations

from abc import ABC, abstractmethod

from qiskit.circuit import QuantumCircuit, Instruction, CircuitInstruction

from ..qpd_basis import QPDBasis


class BaseQPDGate(Instruction, ABC):
class BaseQPDGate(Instruction):
"""Base class for a gate to be decomposed using quasiprobability decomposition."""

def __init__(
@@ -101,11 +99,6 @@ def __eq__(self, other):
and self.label == other.label
)

@abstractmethod
def _define(self) -> None:
"""Generate a decomposed gate."""
raise NotImplementedError # pragma: no cover


class TwoQubitQPDGate(BaseQPDGate):
"""Two qubit gate to be decomposed using quasiprobability decomposition."""
@@ -198,9 +191,10 @@ def _set_qubit_id(self, qubit_id: int) -> None:

def _define(self) -> None:
if self.basis_id is None:
raise ValueError(
"Missing 'basis_id': unable to realize SingleQubitQPDGate."
)
# With basis_id is not set, it does not make sense to define this
# operation in terms of more fundamental instructions, so we have
# self.definition remain as None.
return
qc = QuantumCircuit(1)
base = self.basis.maps[self.basis_id]
for op in base[self.qubit_id]:
7 changes: 1 addition & 6 deletions test/cutting/qpd/instructions/test_qpd_gate.py
Original file line number Diff line number Diff line change
@@ -92,12 +92,7 @@ def test_qubit_id_out_of_range(self):
def test_missing_basis_id(self):
maps = [([XGate()], [YGate()])]
basis = QPDBasis(maps, [1.0])
with pytest.raises(ValueError) as e_info:
SingleQubitQPDGate(basis=basis, qubit_id=0).definition
self.assertEqual(
"Missing 'basis_id': unable to realize SingleQubitQPDGate.",
e_info.value.args[0],
)
assert SingleQubitQPDGate(basis=basis, qubit_id=0).definition is None

def test_compare_1q_and_2q(self):
maps = [([XGate()], [YGate()])]

0 comments on commit 580b9b9

Please sign in to comment.