Esempio n. 1
0
    def test_qv_failure_insufficient_confidence(self):
        """
        Test that the quantum volume is unsuccessful when:
            there are more than 100 trials, the heavy output probability mean is more than 2/3
            but the confidence is not high enough
        """
        dir_name = os.path.dirname(os.path.abspath(__file__))
        insufficient_confidence_json = "qv_data_moderate_noise_100_trials.json"
        with open(os.path.join(dir_name, insufficient_confidence_json),
                  "r") as json_file:
            insufficient_confidence_data = json.load(json_file,
                                                     cls=ExperimentDecoder)

        num_of_qubits = 4
        backend = Aer.get_backend("aer_simulator")

        qv_exp = QuantumVolume(num_of_qubits, seed=SEED)
        exp_data = ExperimentData(experiment=qv_exp, backend=backend)
        exp_data.add_data(insufficient_confidence_data)

        qv_exp.run_analysis(exp_data)
        qv_result = exp_data.analysis_results(1)
        self.assertTrue(
            qv_result.extra["success"] is False and qv_result.value == 1,
            "quantum volume is successful with insufficient confidence",
        )
Esempio n. 2
0
    def test_qv_failure_insufficient_trials(self):
        """
        Test that the quantum volume is unsuccessful when:
            there is less than 100 trials
        """
        dir_name = os.path.dirname(os.path.abspath(__file__))
        insufficient_trials_json_file = "qv_data_70_trials.json"
        with open(os.path.join(dir_name, insufficient_trials_json_file),
                  "r") as json_file:
            insufficient_trials_data = json.load(json_file,
                                                 cls=ExperimentDecoder)

        num_of_qubits = 3
        backend = Aer.get_backend("aer_simulator")

        qv_exp = QuantumVolume(num_of_qubits, seed=SEED)
        exp_data = ExperimentData(experiment=qv_exp, backend=backend)
        exp_data.add_data(insufficient_trials_data)

        qv_exp.run_analysis(exp_data)
        qv_result = exp_data.analysis_results(1)
        self.assertTrue(
            qv_result.extra["success"] is False and qv_result.value == 1,
            "quantum volume is successful with less than 100 trials",
        )
Esempio n. 3
0
    def test_qv_success(self):
        """
        Test a successful run of quantum volume.
        Compare the results to a pre-run experiment
        """
        dir_name = os.path.dirname(os.path.abspath(__file__))
        successful_json_file = "qv_data_moderate_noise_300_trials.json"
        with open(os.path.join(dir_name, successful_json_file),
                  "r") as json_file:
            successful_data = json.load(json_file, cls=ExperimentDecoder)

        num_of_qubits = 4
        backend = Aer.get_backend("aer_simulator")

        qv_exp = QuantumVolume(range(num_of_qubits), seed=SEED)
        exp_data = ExperimentData(experiment=qv_exp, backend=backend)
        exp_data.add_data(successful_data)

        qv_exp.analysis.run(exp_data)
        results_json_file = "qv_result_moderate_noise_300_trials.json"
        with open(os.path.join(dir_name, results_json_file), "r") as json_file:
            successful_results = json.load(json_file, cls=ExperimentDecoder)

        results = exp_data.analysis_results()
        for result, reference in zip(results, successful_results):
            if isinstance(result.value, UFloat):
                # ufloat is distinguished by object id. so usually not identical to cache.
                self.assertTupleEqual(
                    (result.value.n, result.value.s),
                    (reference["value"].n, reference["value"].s),
                    "result value is not the same as precalculated analysis",
                )
            else:
                self.assertEqual(
                    result.value,
                    reference["value"],
                    "result value is not the same as precalculated analysis",
                )
            self.assertEqual(
                result.name,
                reference["name"],
                "result name is not the same as precalculated analysis",
            )
            for key, value in reference["extra"].items():
                if isinstance(value, float):
                    self.assertAlmostEqual(
                        result.extra[key],
                        value,
                        msg="result " + str(key) + " is not the same as the "
                        "pre-calculated analysis",
                    )
                else:
                    self.assertTrue(
                        result.extra[key] == value,
                        "result " + str(key) + " is not the same as the "
                        "pre-calculated analysis",
                    )
Esempio n. 4
0
    def test_bad_analysis(self):
        """Test the Rabi analysis."""
        experiment_data = ExperimentData()

        thetas = np.linspace(0.0, np.pi / 4, 31)
        amplitudes = np.linspace(0.0, 0.95, 31)

        experiment_data.add_data(
            self.simulate_experiment_data(thetas, amplitudes, shots=200))

        data_processor = DataProcessor("counts", [Probability(outcome="1")])

        experiment_data = OscillationAnalysis().run(
            experiment_data, data_processor=data_processor, plot=False)
        result = experiment_data.analysis_results()

        self.assertEqual(result[0].quality, "bad")
Esempio n. 5
0
    def test_good_analysis(self):
        """Test the Rabi analysis."""
        experiment_data = ExperimentData()

        thetas = np.linspace(-np.pi, np.pi, 31)
        amplitudes = np.linspace(-0.25, 0.25, 31)
        expected_rate, test_tol = 2.0, 0.2

        experiment_data.add_data(
            self.simulate_experiment_data(thetas, amplitudes, shots=400))

        data_processor = DataProcessor("counts", [Probability(outcome="1")])

        experiment_data = OscillationAnalysis().run(
            experiment_data, data_processor=data_processor, plot=False)
        result = experiment_data.analysis_results(0)
        self.assertEqual(result.quality, "good")
        self.assertAlmostEqual(result.value[1], expected_rate, delta=test_tol)
Esempio n. 6
0
    def test_qv_failure_insufficient_hop(self):
        """
        Test that the quantum volume is unsuccessful when:
            there are more than 100 trials, but the heavy output probability mean is less than 2/3
        """
        dir_name = os.path.dirname(os.path.abspath(__file__))
        insufficient_hop_json_file = "qv_data_high_noise.json"
        with open(os.path.join(dir_name, insufficient_hop_json_file),
                  "r") as json_file:
            insufficient_hop_data = json.load(json_file, cls=ExperimentDecoder)

        num_of_qubits = 4
        backend = Aer.get_backend("aer_simulator")

        qv_exp = QuantumVolume(range(num_of_qubits), seed=SEED)
        exp_data = ExperimentData(experiment=qv_exp, backend=backend)
        exp_data.add_data(insufficient_hop_data)

        qv_exp.analysis.run(exp_data)
        qv_result = exp_data.analysis_results(1)
        self.assertTrue(
            qv_result.extra["success"] is False and qv_result.value == 1,
            "quantum volume is successful with heavy output probability less than 2/3",
        )