Пример #1
0
 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 _generate_int_rb_fitter_data(dir_name: str, rb_exp_name: str,
                                 exp_attributes: dict):
    """
    Executing standard RB experiment and storing its data in json format.
    The json is composed of a list that the first element is a dictionary containing
    the experiment attributes and the second element is a list with all the experiment
    data.
    Args:
        dir_name: The json file name that the program write the data to.
        rb_exp_name: The experiment name for naming the output files.
        exp_attributes: attributes to config the RB experiment.
    """
    gate_error_ratio = {
        ((0, ), "id"): 1,
        ((0, ), "rz"): 0,
        ((0, ), "sx"): 1,
        ((0, ), "x"): 1,
        ((0, 1), "cx"): 1,
    }
    interleaved_gates = {"x": XGate(), "cx": CXGate()}
    transpiled_base_gate = ["cx", "sx", "x"]
    results_file_path = os.path.join(dir_name,
                                     str(rb_exp_name + "_output_data.json"))
    analysis_file_path = os.path.join(
        dir_name, str(rb_exp_name + "_output_analysis.json"))
    noise_model = create_depolarizing_noise_model()
    backend = AerSimulator(seed_simulator=exp_attributes["seed"])
    print("Generating experiment")
    rb_exp = InterleavedRB(
        interleaved_gates[exp_attributes["interleaved_element"]],
        exp_attributes["physical_qubits"],
        exp_attributes["lengths"],
        num_samples=exp_attributes["num_samples"],
        seed=exp_attributes["seed"],
    )
    rb_exp.analysis.set_options(gate_error_ratio=gate_error_ratio)
    print("Running experiment")
    experiment_obj = rb_exp.run(backend,
                                noise_model=noise_model,
                                basis_gates=transpiled_base_gate)
    experiment_obj.block_for_results()
    print("Done running experiment")
    exp_results = experiment_obj.data()
    with open(results_file_path, "w") as json_file:
        joined_list_data = [exp_attributes, exp_results]
        json_file.write(json.dumps(joined_list_data))
    _analysis_save(experiment_obj.analysis_results(), analysis_file_path)