Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e966c18
Create test_rb.py
ItamarGoldman May 13, 2021
9bec832
Merge remote-tracking branch 'upstream/main' into Test_Branch_Main
ItamarGoldman May 13, 2021
e81f7a7
Update test_rb.py
ItamarGoldman May 13, 2021
8d19a8b
Update test_rb.py
ItamarGoldman May 13, 2021
35751ab
Update test_rb.py
ItamarGoldman May 13, 2021
9a5da89
Update test_rb.py
ItamarGoldman May 13, 2021
fc14de5
Added Test to validate the circuit data
ItamarGoldman May 20, 2021
fa5199a
Lint fixed
ItamarGoldman May 20, 2021
00528c7
Merge remote-tracking branch 'upstream/main' into Test_Branch_Main
ItamarGoldman May 20, 2021
3e68bba
Merge remote-tracking branch 'upstream/main' into Test_Branch_Main
ItamarGoldman May 24, 2021
7039b8e
Added test for transpiled circuit
ItamarGoldman May 24, 2021
89a82fd
Update test_rb.py
ItamarGoldman May 24, 2021
077e818
Update test_rb.py
ItamarGoldman May 24, 2021
cd49a18
Black and lint
ItamarGoldman May 24, 2021
dd13ed0
uncommented test
ItamarGoldman May 24, 2021
464e7d4
Merge remote-tracking branch 'upstream/main' into Test_Branch_Main
ItamarGoldman May 27, 2021
118f133
Changes in experiment attributes
ItamarGoldman May 27, 2021
7291588
Added ddt decorator and use it to decrease the number of functions
ItamarGoldman May 27, 2021
45e3d66
Deleted the test for the transpiled circuit
ItamarGoldman May 27, 2021
2c6a9ca
Ran Black on the code
ItamarGoldman May 27, 2021
273a592
The test_rb.py passed lint (local)
ItamarGoldman May 27, 2021
34e4696
Update __init__.py
ItamarGoldman May 27, 2021
1708cfd
Fixed the test for metadata and run experiment
ItamarGoldman May 27, 2021
371ecfc
Run Black
ItamarGoldman May 27, 2021
ef92925
Fixed lint
ItamarGoldman May 27, 2021
f3f6f27
Deleted - Test for input error hadling
ItamarGoldman May 30, 2021
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,4 @@ docs/stubs/*
test/ipynb/mpl/*.png
test/ipynb/mpl/*.zip
test/ipynb/mpl/result_test.json
test/Debug_RB.py
7 changes: 7 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@ pygments>=2.4
reno>=3.2.0
sphinx-panels
nbsphinx

numpy~=1.19.2
qiskit~=0.25.3
ddt~=1.4.2
setuptools~=56.1.0
scipy~=1.5.2
matplotlib~=3.3.2
117 changes: 117 additions & 0 deletions test/test_rb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# -*- coding: utf-8 -*-

# This code is part of Qiskit.
#
# (C) Copyright IBM 2021.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

"""
A Tester for the RB experiment
"""

from qiskit.quantum_info.operators.predicates import matrix_equal
from qiskit.quantum_info import Clifford
from qiskit.test import QiskitTestCase
from qiskit.test.mock import FakeParis
from ddt import ddt, data, unpack
import numpy as np
import qiskit_experiments as qe


@ddt
class TestRB(QiskitTestCase):
"""
A test class for the RB Experiment to check that the RBExperiment class is working correctly.
"""

@data([[3]], [[4, 7]], [[0, 5, 3]])
@unpack
def test_rb_experiment(self, qubits: list):
"""
Initializes data and executes an RB experiment with specific parameters.
Args:
qubits (list): A list containing qubit indices for the experiment
"""
backend = FakeParis()
exp_attributes = {
"qubits": qubits,
"lengths": [1, 4, 6, 9, 13, 16],
"num_samples": 1,
"seed": 100,
}
rb = qe.randomized_benchmarking
rb_exp = rb.RBExperiment(
exp_attributes["qubits"],
exp_attributes["lengths"],
num_samples=exp_attributes["num_samples"],
seed=exp_attributes["seed"],
)
experiment_obj = rb_exp.run(backend)
exp_data = experiment_obj.experiment
exp_circuits = rb_exp.circuits()
self.validate_metadata(exp_circuits, exp_attributes)
self.validate_circuit_data(exp_data, exp_attributes)
self.is_identity(exp_circuits)

def is_identity(self, circuits: list):
"""Standard randomized benchmarking test - Identity check.
(assuming all the operator are spanned by clifford group)
Args:
circuits (list): list of the circuits which we want to check
"""
for qc in circuits:
num_qubits = qc.num_qubits
qc.remove_final_measurements()
# Checking if the matrix representation is the identity matrix
self.assertTrue(
matrix_equal(Clifford(qc).to_matrix(), np.identity(2 ** num_qubits)),
"Clifford sequence doesn't result in the identity matrix.",
)

def validate_metadata(self, circuits: list, exp_attributes: dict):
"""
Validate the fields in "metadata" for the experiment.
Args:
circuits (list): A list containing quantum circuits
exp_attributes (dict): A dictionary with the experiment variable and values
"""
for ind, qc in enumerate(circuits):
self.assertTrue(
qc.metadata["xval"] == exp_attributes["lengths"][ind],
"The number of gates in the experiment metadata doesn't match to the one provided.",
)
self.assertTrue(
qc.metadata["qubits"] == tuple(exp_attributes["qubits"]),
"The qubits indices in the experiment metadata doesn't match to the one provided.",
)

def validate_circuit_data(
self,
experiment: qe.randomized_benchmarking.rb_experiment.RBExperiment,
exp_attributes: dict,
):
"""
Validate that the metadata of the experiment after it had run matches the one provided.
Args:
experiment: The experiment data and results after it run
exp_attributes (dict): A dictionary with the experiment variable and values
"""
self.assertTrue(
exp_attributes["lengths"] == experiment.experiment_options.lengths,
"The number of gates in the experiment doesn't match to the one in the metadata.",
)
self.assertTrue(
exp_attributes["num_samples"] == experiment.experiment_options.num_samples,
"The number of samples in the experiment doesn't match to the one in the metadata.",
)
self.assertTrue(
tuple(exp_attributes["qubits"]) == experiment.physical_qubits,
"The qubits indices in the experiment doesn't match to the one in the metadata.",
)