Esempio n. 1
0
    def test_qv_sigma_decreasing(self):
        """
        Test that the sigma is decreasing after adding more trials
        """
        num_of_qubits = 3
        backend = Aer.get_backend("aer_simulator")

        qv_exp = QuantumVolume(num_of_qubits, seed=SEED)
        # set number of trials to a low number to make the test faster
        qv_exp.set_experiment_options(trials=2)
        expdata1 = qv_exp.run(backend)
        expdata1.block_for_results()
        result_data1 = expdata1.analysis_results(0)
        expdata2 = qv_exp.run(backend, experiment_data=expdata1)
        expdata2.block_for_results()
        result_data2 = expdata2.analysis_results(0)

        self.assertTrue(result_data1.extra["trials"] == 2,
                        "number of trials is incorrect")
        self.assertTrue(
            result_data2.extra["trials"] == 4,
            "number of trials is incorrect"
            " after adding more trials",
        )
        self.assertTrue(
            result_data2.value.stderr <= result_data1.value.stderr,
            "sigma did not decreased after adding more trials",
        )
def create_qv_data_high_confidence(dir_path: str):
    """
    create quantum volume experiment_data using seed, and save it as a json
    the circuit is generated with moderate noise, so the mean hop is above 2/3,
    and also with enough trials, so the confidence is above threshold
    Args:
        dir_path(str): The directory which the data will be saved to.
    """
    num_of_qubits = 4
    backend = AerSimulator(seed_simulator=SEED)
    basis_gates = ["id", "rz", "sx", "x", "cx", "reset"]
    noise = create_noise_model()

    qv_exp = QuantumVolume(range(num_of_qubits), seed=SEED)
    qv_exp.set_experiment_options(trials=300)
    qv_exp.set_transpile_options(basis_gates=basis_gates)
    qv_data = qv_exp.run(backend, noise_model=noise, basis_gates=basis_gates)
    qv_data.block_for_results()

    result_file_path = os.path.join(dir_path, "qv_data_moderate_noise_300_trials.json")
    with open(result_file_path, "w") as json_file:
        json.dump(qv_data.data(), json_file, cls=ExperimentEncoder)

    result_file_path = os.path.join(dir_path, "qv_result_moderate_noise_300_trials.json")
    with open(result_file_path, "w") as json_file:
        result_dicts = []
        for result in qv_data.analysis_results():
            result_dicts.append(
                {
                    "name": result.name,
                    "value": result.value,
                    "extra": result.extra,
                }
            )
        json.dump(result_dicts, json_file, cls=ExperimentEncoder)
def create_qv_data_70_trials(dir_path: str):
    """
    create quantum volume experiment_data using seed, and save it as a json
    Args:
        dir_path(str): The directory which the data will be saved to.
    """
    num_of_qubits = 3
    backend = AerSimulator(seed_simulator=SEED)

    qv_exp = QuantumVolume(range(num_of_qubits), seed=SEED)
    qv_exp.set_experiment_options(trials=70)
    qv_data = qv_exp.run(backend)
    qv_data.block_for_results()

    result_file_path = os.path.join(dir_path, "qv_data_70_trials.json")
    with open(result_file_path, "w") as json_file:
        json.dump(qv_data.data(), json_file, cls=ExperimentEncoder)
def create_qv_data_low_hop(dir_path: str):
    """
    create quantum volume experiment_data using seed, and save it as a json
    the circuit is generated with high noise, so the mean hop is below 2/3
    Args:
        dir_path(str): The directory which the data will be saved to.
    """
    num_of_qubits = 4
    backend = AerSimulator(seed_simulator=SEED)
    basis_gates = ["id", "rz", "sx", "x", "cx", "reset"]
    noise = create_high_noise_model()

    qv_exp = QuantumVolume(range(num_of_qubits), seed=SEED)
    qv_exp.set_transpile_options(basis_gates=basis_gates)
    qv_data = qv_exp.run(backend, noise_model=noise, basis_gates=basis_gates)
    qv_data.block_for_results()

    result_file_path = os.path.join(dir_path, "qv_data_high_noise.json")
    with open(result_file_path, "w") as json_file:
        json.dump(qv_data.data(), json_file, cls=ExperimentEncoder)
Esempio n. 5
0
def create_qv_data_low_confidence(dir_path: str):
    """
    create quantum volume experiment_data using seed, and save it as a json
    the circuit is generated with moderate noise, so the mean hop is above 2/3,
    but there are not enough trials, so the confidence is below threshold
    Args:
        dir_path(str): The directory which the data will be saved to.
    """
    num_of_qubits = 4
    backend = Aer.get_backend("aer_simulator")
    basis_gates = ["id", "rz", "sx", "x", "cx", "reset"]
    noise = create_noise_model()

    qv_exp = QuantumVolume(num_of_qubits, seed=SEED)
    qv_exp.set_transpile_options(basis_gates=basis_gates)
    qv_data = qv_exp.run(backend, noise_model=noise, basis_gates=basis_gates)
    qv_data.block_for_results()

    result_file_path = os.path.join(dir_path,
                                    "qv_data_moderate_noise_100_trials.json")
    with open(result_file_path, "w") as json_file:
        json.dump(qv_data.data(), json_file, cls=ExperimentEncoder)