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

Fix circuit generation of 3Q+ InterleavedRB #1015

Merged
merged 7 commits into from
Jan 23, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,9 @@ def __init__(
self._interleaved_cliff = num_from_1q_circuit(interleaved_clifford.to_circuit())
elif self.num_qubits == 2:
self._interleaved_cliff = num_from_2q_circuit(interleaved_clifford.to_circuit())
# Convert interleaved element to circuit for speed in 3Q or more case
else:
self._interleaved_cliff = interleaved_clifford
self._interleaved_cliff = interleaved_clifford.to_circuit()
self._interleaved_element = interleaved_element # Original interleaved element
self._interleaved_op = None # Transpiled interleaved element for speed
self.analysis = InterleavedRBAnalysis()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ def __sample_sequence(self, length: int, rng: Generator) -> Sequence[SequenceEle
if self.num_qubits == 2:
return rng.integers(CliffordUtils.NUM_CLIFFORD_2_QUBIT, size=length)
# Return circuit object instead of Clifford object for 3 or more qubits case for speed
# TODO: Revisit after terra#7269, #7483, #8585
return [random_clifford(self.num_qubits, rng).to_circuit() for _ in range(length)]

def _to_instruction(
Expand Down Expand Up @@ -318,7 +317,6 @@ def __compose_clifford_seq(
compose_1q if self.num_qubits == 1 else compose_2q, elements, base_elem
)
# 3 or more qubits: compose Clifford from circuits for speed
# TODO: Revisit after terra#7269, #7483, #8585
circ = QuantumCircuit(self.num_qubits)
for elem in elements:
circ.compose(elem, inplace=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import numpy as np
from ddt import ddt, data, unpack

from qiskit.circuit import Delay, QuantumCircuit, Parameter
from qiskit.circuit import Delay, QuantumCircuit, Parameter, Gate
from qiskit.circuit.library import SXGate, CXGate, TGate, CZGate
from qiskit.exceptions import QiskitError
from qiskit.providers.fake_provider import FakeManila, FakeManilaV2, FakeWashington
Expand Down Expand Up @@ -84,6 +84,14 @@ def test_analysis_config(self):
self.assertEqual(analysis.config(), loaded.config())

# ### Tests for circuit generation ###
@data([[3], 4], [[4, 7], 5], [[0, 1, 2], 3])
@unpack
def test_generate_circuits(self, qubits, length):
"""Test RB circuit generation"""
exp = rb.StandardRB(qubits=qubits, lengths=[length], num_samples=1)
circuits = exp.circuits()
self.assertAllIdentity(circuits)

def test_return_same_circuit(self):
"""Test if setting the same seed returns the same circuits."""
exp1 = rb.StandardRB(
Expand Down Expand Up @@ -265,6 +273,28 @@ def test_analysis_config(self):
self.assertEqual(analysis.config(), loaded.config())

# ### Tests for circuit generation ###
class ThreeQubitGate(Gate):
"""A 3-qubit Clifford gate for tests"""

def __init__(self):
super().__init__("3q-gate", 3, [])

def _define(self):
qc = QuantumCircuit(3, name=self.name)
qc.cx(0, 1)
qc.x(2)
self.definition = qc

@data([SXGate(), [3], 4], [CXGate(), [4, 7], 5], [ThreeQubitGate(), [0, 1, 2], 3])
@unpack
def test_generate_interleaved_circuits(self, interleaved_element, qubits, length):
"""Test interleaved circuit generation"""
exp = rb.InterleavedRB(
interleaved_element=interleaved_element, qubits=qubits, lengths=[length], num_samples=1
)
circuits = exp.circuits()
self.assertAllIdentity(circuits)

@data([SXGate(), [3], 4], [CXGate(), [4, 7], 5])
@unpack
def test_interleaved_structure(self, interleaved_element, qubits, length):
Expand Down