Пример #1
0
def generate_fitter_data_1(results_file_path: str,
                           expected_results_file_path: str):
    """
    Create rb circuits with depolarizing error and simulate them,
    then write the results in a json file.
    also creates fitter for the data results,
    and also write the fitter results in another json file.

    The simulation results file will contain a list of Result objects in a dictionary format.
    The fitter data file will contain dictionary with the following keys:
    - 'ydata', value is stored in the form of list of dictionaries with keys of:
        - mean, list of integers
        - std, list of integers
    - fit, value is stored in the form of list of dictionaries with keys of:
        - params, list of integers
        - params_err, list of integers
        - epc, list of integers
        - epc_err, list of integers

    Args:
        results_file_path: path of the json file of the simulation results file
        expected_results_file_path: path of the json file of the fitter results file
    """

    rb_opts = {}
    shots = 1024
    rb_opts['nseeds'] = 5
    rb_opts['rb_pattern'] = [[0, 1], [2]]
    rb_opts['length_multiplier'] = [1, 2]
    rb_opts['length_vector'] = np.arange(1, 200, 20)
    rb_opts['rand_seed'] = SEED

    rb_results, xdata = rb_circuit_execution(rb_opts, shots)
    save_results_as_json(rb_results, results_file_path)

    # generate also the expected results of the fitter
    rb_fit = RBFitter(rb_results, xdata, rb_opts['rb_pattern'])
    ydata = rb_fit.ydata
    fit = rb_fit.fit
    # convert ndarray to list
    ydata = convert_ndarray_to_list_in_data(ydata)
    fit = convert_ndarray_to_list_in_data(fit)

    expected_result = {"ydata": ydata, "fit": fit}
    with open(expected_results_file_path, "w") as expected_results_file:
        json.dump(expected_result, expected_results_file)
Пример #2
0
def generate_qv_fitter_data(ideal_results_file_path: str,
                            exp_results_file_path: str):
    """
    run the quantum volume circuits and save the results
    The simulation results files will contain a list of Result objects in a dictionary format.

    Args:
        ideal_results_file_path: path of the json file of the ideal simulation results file
        exp_results_file_path: path of the json file of the noisy simulation results file
    """
    # parameters
    qubit_lists = [[0, 1, 3], [0, 1, 3, 5], [0, 1, 3, 5, 7],
                   [0, 1, 3, 5, 7, 10]]
    ntrials = 5
    # execute the circuit
    ideal_results, exp_results = qv_circuit_execution(qubit_lists,
                                                      ntrials,
                                                      shots=1024)
    # save the results
    save_results_as_json(ideal_results, ideal_results_file_path)
    save_results_as_json(exp_results, exp_results_file_path)
Пример #3
0
def generate_purity_data(results_file_path_purity: str,
                         results_file_path_coherent: str,
                         expected_results_file_path_purity: str,
                         expected_results_file_path_coherent: str):
    """
        Create purity rb circuits with depolarizing error and simulate them,
         then write the results in a json file (separate files for purity and coherent).
        also creates fitter for the data results,
        and also write the fitter results in another json file (separate files for purity
         and coherent).

        The simulation results file will contain a list of Result objects in a dictionary format.
        The fitter data file will contain dictionary with the following keys:
        - 'ydata', value is stored in the form of list of dictionaries with keys of:
            - mean, list of integers
            - std, list of integers
        - fit, value is stored in the form of list of dictionaries with keys of:
            - params, list of integers
            - params_err, list of integers
            - epc, list of integers
            - epc_err, list of integers
            - pepc, list of integers
            - pepc_err, list of integers

        Args:
            results_file_path_purity: path of the json file of the purity simulation results file
            results_file_path_coherent: path of the json file of the coherent simulation results
            file
            expected_results_file_path_purity: path of the json file of the purity fitter
            results file
            expected_results_file_path_coherent: path of the json file of the coherent fitter
            results file
        """
    rb_opts = {}
    shots = 200
    rb_opts['nseeds'] = 3
    rb_opts['rb_pattern'] = [[0, 1]]
    rb_opts['length_vector'] = np.arange(1, 200, 20)
    rb_opts['is_purity'] = True
    rb_opts['rand_seed'] = SEED

    rb_purity_results, xdata, npurity, rb_coherent_results = \
        rb_purity_circuit_execution(rb_opts, shots)

    # save the results
    save_results_as_json(rb_purity_results, results_file_path_purity)
    # COHERENT FITTER IS NOT TESTED YET
    save_results_as_json(rb_coherent_results, results_file_path_coherent)

    # generate also the expected results of the fitter
    rbfit_purity = PurityRBFitter(rb_purity_results, npurity, xdata,
                                  rb_opts['rb_pattern'])

    fit = rbfit_purity.fit
    ydata = rbfit_purity.ydata

    # convert ndarray to list
    ydata = convert_ndarray_to_list_in_data(ydata)
    fit = convert_ndarray_to_list_in_data(fit)

    expected_result = {"ydata": ydata, "fit": fit}
    with open(expected_results_file_path_purity, "w") as expected_results_file:
        json.dump(expected_result, expected_results_file)

    # generate also the expected results of the fitter for coherent
    rbfit_coherent = rb.PurityRBFitter(rb_coherent_results, npurity, xdata,
                                       rb_opts['rb_pattern'])

    coherent_fit = rbfit_coherent.fit
    coherent_ydata = rbfit_coherent.ydata

    # convert ndarray to list
    coherent_ydata = convert_ndarray_to_list_in_data(coherent_ydata)
    coherent_fit = convert_ndarray_to_list_in_data(coherent_fit)

    coherent_expected_result = {"ydata": coherent_ydata, "fit": coherent_fit}
    # COHERENT FITTER IS NOT TESTED YET
    with open(expected_results_file_path_coherent,
              "w") as expected_results_file:
        json.dump(coherent_expected_result, expected_results_file)
Пример #4
0
def generate_cnotdihedral_data(results_file_path_cnotdihedral_x: str,
                               results_file_path_cnotdihedral_z: str,
                               expected_results_file_path: str):
    """
        Create cnot-dihedral rb circuits with depolarizing error and simulate them,
         then write the results in a json file (separate files for x and z).
        also creates fitter for the data results,
        and also write the fitter results in another json file.

        The simulation results file will contain a list of Result objects in a dictionary format.
        The fitter data file will contain dictionary with the following keys:
        - 'cnotdihedral_Z_ydata', value is stored in the form of list of dictionaries with keys of:
            - mean, list of integers
            - std, list of integers
        - 'cnotdihedral_X_ydata', value is stored in the form of list of dictionaries with keys of:
            - mean, list of integers
            - std, list of integers
        - joint_fit, value is stored in the form of list of dictionaries with keys of:
            - alpha, list of integers
            - alpha_err, list of integers
            - epc_est, list of integers
            - epc_est_err, list of integers

        Args:
            results_file_path_cnotdihedral_z: path of the json file of the simulation results file
                of the cnot-dihedral in the z plane circuits
            results_file_path_cnotdihedral_x: path of the json file of the simulation results file
                of the cnot-dihedral in the x plane circuits
            expected_results_file_path: path of the json file of the fitter results file
        """

    rb_opts = {}
    shots = 200
    rb_opts['nseeds'] = 5
    rb_opts['rb_pattern'] = [[0, 2], [1]]
    rb_opts['length_vector'] = np.arange(1, 200, 20)
    rb_opts['length_multiplier'] = [1, 3]
    rb_opts['group_gates'] = 'CNOT-Dihedral'
    rb_opts['rand_seed'] = SEED

    cnotdihedral_x_results, xdata, cnotdihedral_z_results = \
        rb_cnotdihedral_execution(rb_opts, shots)
    save_results_as_json(cnotdihedral_x_results,
                         results_file_path_cnotdihedral_x)
    save_results_as_json(cnotdihedral_z_results,
                         results_file_path_cnotdihedral_z)

    # generate also the expected results of the fitter
    joint_rb_fit = CNOTDihedralRBFitter(cnotdihedral_z_results,
                                        cnotdihedral_x_results, xdata,
                                        rb_opts['rb_pattern'])

    joint_fit = joint_rb_fit.fit_cnotdihedral
    cnotdihedral_z_ydata = joint_rb_fit.ydata[0]
    cnotdihedral_x_ydata = joint_rb_fit.ydata[1]
    # convert ndarray to list
    cnotdihedral_x_ydata = convert_ndarray_to_list_in_data(
        cnotdihedral_x_ydata)
    cnotdihedral_z_ydata = convert_ndarray_to_list_in_data(
        cnotdihedral_z_ydata)
    joint_fit = convert_ndarray_to_list_in_data(joint_fit)

    expected_result = {
        "cnotdihedral_Z_ydata": cnotdihedral_z_ydata,
        "cnotdihedral_X_ydata": cnotdihedral_x_ydata,
        "joint_fit": joint_fit
    }
    with open(expected_results_file_path, "w") as expected_results_file:
        json.dump(expected_result, expected_results_file)
Пример #5
0
def generate_interleaved_data(results_file_path_original: str,
                              results_file_path_interleaved: str,
                              expected_results_file_path: str):
    """
        Create interleaved rb circuits with depolarizing error and simulate them,
         then write the results in a json file.
        also creates fitter for the data results,
        and also write the fitter results in another json file.

        The simulation results file will contain a list of Result objects in a dictionary format.
        The fitter data file will contain dictionary with the following keys:
        - 'original_ydata', value is stored in the form of list of dictionaries with keys of:
            - mean, list of integers
            - std, list of integers
        - 'interleaved_ydata', value is stored in the form of list of dictionaries with keys of:
            - mean, list of integers
            - std, list of integers
        - joint_fit, value is stored in the form of list of dictionaries with keys of:
            - alpha, list of integers
            - alpha_err, list of integers
            - alpha_c, list of integers
            - alpha_c_err, list of integers
            - epc_est, list of integers
            - epc_est_err, list of integers
            - systematic_err, list of integers
            - systematic_err_L, list of integers
            - systematic_err_R, list of integers

        Args:
            results_file_path_original: path of the json file of the simulation results file
                of the original circuits
            results_file_path_interleaved: path of the json file of the simulation results file
                of the interleaved circuits
            expected_results_file_path: path of the json file of the fitter results file
        """

    rb_opts = {}
    shots = 200
    rb_opts['nseeds'] = 2
    rb_opts['rb_pattern'] = [[0, 2], [1]]
    rb_opts['length_vector'] = np.arange(1, 100, 10)
    rb_opts['length_multiplier'] = [1, 3]
    # create interleaved elem of the form [['x 0', 'x 1', 'cx 0 1'], ['x 0']]
    qc1 = qiskit.QuantumCircuit(2)
    qc1.x(0)
    qc1.x(1)
    qc1.cx(0, 1)
    qc2 = qiskit.QuantumCircuit(1)
    qc2.x(0)
    rb_opts["interleaved_elem"] = [qc1, qc2]
    rb_opts['rand_seed'] = SEED

    results, xdata, interleaved_results = rb_interleaved_execution(
        rb_opts, shots)
    save_results_as_json(results, results_file_path_original)
    save_results_as_json(interleaved_results, results_file_path_interleaved)

    # generate also the expected results of the fitter
    joint_rb_fit = InterleavedRBFitter(results, interleaved_results, xdata,
                                       rb_opts['rb_pattern'])
    joint_fit = joint_rb_fit.fit_int
    original_ydata = joint_rb_fit.ydata[0]
    interleaved_ydata = joint_rb_fit.ydata[1]
    # convert ndarray to list
    original_ydata = convert_ndarray_to_list_in_data(original_ydata)
    interleaved_ydata = convert_ndarray_to_list_in_data(interleaved_ydata)
    joint_fit = convert_ndarray_to_list_in_data(joint_fit)

    expected_result = {
        "original_ydata": original_ydata,
        "interleaved_ydata": interleaved_ydata,
        "joint_fit": joint_fit
    }
    with open(expected_results_file_path, "w") as expected_results_file:
        json.dump(expected_result, expected_results_file)