Skip to content

Commit

Permalink
Revert "Workaround for CircuitInstruction operation mutability."
Browse files Browse the repository at this point in the history
This reverts commit 21f3e51.
  • Loading branch information
kevinhartman committed Sep 28, 2023
1 parent 21f3e51 commit d49881c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 28 deletions.
4 changes: 0 additions & 4 deletions crates/accelerate/src/quantum_circuit/circuit_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ pub struct CircuitData {

#[derive(FromPyObject)]
pub struct ElementType {
// Note that _operation_wrapper is used only to support c_if,
// which on the Python-side swaps out the operation that the
// wrapper points to.
#[pyo3(attribute("_operation_wrapper"))]
operation: PyObject,
qubits: Py<PyTuple>,
clbits: Py<PyTuple>,
Expand Down
29 changes: 5 additions & 24 deletions qiskit/circuit/quantumcircuitdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@
from .classicalregister import Clbit


class _OperationWrapper:
operation: Operation

def __init__(self, op: Operation):
self.operation = op


class CircuitInstruction:
"""A single instruction in a :class:`.QuantumCircuit`, comprised of the :attr:`operation` and
various operands.
Expand Down Expand Up @@ -65,20 +58,10 @@ class CircuitInstruction:
of distinct items, with no duplicates.
"""

__slots__ = ("_operation_wrapper", "qubits", "clbits")

_operation_wrapper: _OperationWrapper

@property
def operation(self) -> Operation:
"""The logical operation that this instruction represents an execution of."""
return self._operation_wrapper.operation

@operation.setter
def operation(self, op: Operation):
"""Updates in place the logical operation that this instruction represents an execution of."""
self._operation_wrapper.operation = op
__slots__ = ("operation", "qubits", "clbits")

operation: Operation
"""The logical operation that this instruction represents an execution of."""
qubits: Tuple[Qubit, ...]
"""A sequence of the qubits that the operation is applied to."""
clbits: Tuple[Clbit, ...]
Expand All @@ -90,16 +73,14 @@ def __init__(
qubits: Iterable[Qubit] = (),
clbits: Iterable[Clbit] = (),
):
self._operation_wrapper = (
operation if isinstance(operation, _OperationWrapper) else _OperationWrapper(operation)
)
self.operation = operation
self.qubits = tuple(qubits)
self.clbits = tuple(clbits)

def copy(self) -> "CircuitInstruction":
"""Return a shallow copy of the :class:`CircuitInstruction`."""
return self.__class__(
operation=self._operation_wrapper,
operation=self.operation,
qubits=self.qubits,
clbits=self.clbits,
)
Expand Down

0 comments on commit d49881c

Please sign in to comment.