Skip to content

Commit

Permalink
Fix CNOTDihedral class to support OpShape (qiskit-community#550)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShellyGarion authored Jan 21, 2021
1 parent fddd1e5 commit 824372e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
11 changes: 5 additions & 6 deletions qiskit/ignis/verification/randomized_benchmarking/dihedral.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,7 @@ def __init__(self, data, validate=True):
self.shift = elem.shift

# Initialize BaseOperator
dims = self._num_qubits * (2,)
super().__init__(dims, dims)
super().__init__(num_qubits=self._num_qubits)

# Validate the CNOTDihedral element
if validate and not self.is_cnotdihedral():
Expand Down Expand Up @@ -591,7 +590,7 @@ def from_circuit(self, circuit):
circuit = circuit.to_instruction()

# Initialize an identity CNOTDihedral object
elem = CNOTDihedral(self.num_qubits)
elem = CNOTDihedral(self._num_qubits)
append_circuit(elem, circuit)
return elem

Expand Down Expand Up @@ -655,7 +654,7 @@ def dot(self, other, qargs=None):
other.poly.weight_0 = 0 # set global phase
return other

def _tensor_product(self, other, reverse=False):
def _tensor(self, other, reverse=False):
"""Returns the tensor product operator.
Args:
Expand Down Expand Up @@ -719,7 +718,7 @@ def tensor(self, other):
CNOTDihedral: the tensor product operator: self tensor other.
"""

return self._tensor_product(other, reverse=True)
return self._tensor(other, reverse=True)

def expand(self, other):
"""Return the tensor product operator: other tensor self.
Expand All @@ -730,7 +729,7 @@ def expand(self, other):
CNOTDihedral: the tensor product operator: other tensor other.
"""

return self._tensor_product(other, reverse=False)
return self._tensor(other, reverse=False)

def adjoint(self):
"""Return the conjugate transpose of the CNOTDihedral element"""
Expand Down
4 changes: 2 additions & 2 deletions test/rb/test_dihedral.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import numpy as np
from qiskit.circuit import QuantumCircuit
from qiskit.quantum_info.operators import Operator
from qiskit.quantum_info.operators.pauli import Pauli
from qiskit.quantum_info.operators import random

import qiskit
# Import the dihedral_utils functions
Expand Down Expand Up @@ -480,7 +480,7 @@ def test_init_from_pauli(self):
nseed = 999
for qubit_num in range(1, 5):
for i in range(samples):
pauli = Pauli.random(qubit_num, seed=nseed + i)
pauli = random.random_pauli(qubit_num, seed=nseed + i)
elem = CNOTDihedral(pauli)
value = Operator(pauli)
target = Operator(elem)
Expand Down

0 comments on commit 824372e

Please sign in to comment.