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 = AerSimulator.from_backend(FakeParis()) exp_attributes = { "physical_qubits": qubits, "lengths": [1, 4, 6, 9, 13, 16], "num_samples": 3, "seed": 100, } rb_exp = StandardRB( exp_attributes["physical_qubits"], exp_attributes["lengths"], num_samples=exp_attributes["num_samples"], seed=exp_attributes["seed"], ) exp_data = rb_exp.run(backend) exp = exp_data.experiment exp_circuits = rb_exp.circuits() self.validate_metadata(exp_circuits, exp_attributes) self.validate_circuit_data(exp, exp_attributes) self.is_identity(exp_circuits)
def test_interleaved_rb_experiment(self, interleaved_element: "Gate", qubits: list): """ Initializes data and executes an interleaved RB experiment with specific parameters. Args: interleaved_element: The Clifford element to interleave qubits (list): A list containing qubit indices for the experiment """ backend = AerSimulator.from_backend(FakeParis()) exp_attributes = { "interleaved_element": interleaved_element, "physical_qubits": qubits, "lengths": [1, 4, 6, 9, 13, 16], "num_samples": 3, "seed": 100, } rb_exp = InterleavedRB( exp_attributes["interleaved_element"], exp_attributes["physical_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 test_json_serialization(self): """Verifies that mitigators can be serialized for DB storage""" qubits = [0, 1] backend = AerSimulator.from_backend(FakeParis()) exp = LocalReadoutError(qubits) exp_data = exp.run(backend).block_for_results() mitigator = exp_data.analysis_results(0).value serialized = json.dumps(mitigator, cls=ExperimentEncoder) loaded = json.loads(serialized, cls=ExperimentDecoder) self.assertTrue( matrix_equal(mitigator.assignment_matrix(), loaded.assignment_matrix()))
def test_parallel_running(self): """Test that parallel experiments work for this experiment""" backend = AerSimulator.from_backend(FakeParis()) exp1 = CorrelatedReadoutError([0, 2]) exp2 = CorrelatedReadoutError([1, 3]) exp = ParallelExperiment([exp1, exp2]) expdata = exp.run(backend=backend).block_for_results() mit1 = expdata.child_data(0).analysis_results(0).value mit2 = expdata.child_data(1).analysis_results(0).value assignment_matrix1 = mit1.assignment_matrix() assignment_matrix2 = mit2.assignment_matrix() self.assertFalse(matrix_equal(assignment_matrix1, assignment_matrix2))
def test_database_save_and_load(self): """Tests saving and loading the mitigator from the DB""" qubits = [0, 1] backend = AerSimulator.from_backend(FakeParis()) exp = LocalReadoutError(qubits) exp_data = exp.run(backend).block_for_results() exp_data.service = FakeService() exp_data.save() loaded_data = ExperimentData.load(exp_data.experiment_id, exp_data.service) exp_res = exp_data.analysis_results() load_res = loaded_data.analysis_results() exp_matrix = exp_res[0].value.assignment_matrix() load_matrix = load_res[0].value.assignment_matrix() self.assertTrue(matrix_equal(exp_matrix, load_matrix))