Exemple #1
0
    def test_fusion_qft(self):
        """Test Fusion with qft"""
        shots = 100

        circuit = transpile(qft_circuit(10, measure=True),
                            backend=self.SIMULATOR,
                            basis_gates=['u1', 'u2', 'u3', 'cx', 'cz'],
                            optimization_level=0)
        qobj = assemble([circuit],
                        self.SIMULATOR,
                        shots=shots,
                        seed_simulator=1)

        backend_options = self.fusion_options(enabled=False, threshold=1)
        result_disabled = self.SIMULATOR.run(
            qobj, backend_options=backend_options).result()
        meta_disabled = self.fusion_metadata(result_disabled)

        backend_options = self.fusion_options(enabled=True, threshold=1)
        result_enabled = self.SIMULATOR.run(
            qobj, backend_options=backend_options).result()
        meta_enabled = self.fusion_metadata(result_enabled)

        self.assertTrue(getattr(result_disabled, 'success', 'False'))
        self.assertTrue(getattr(result_enabled, 'success', 'False'))
        self.assertEqual(meta_disabled, {})
        self.assertTrue(meta_enabled.get('applied', False))
        self.assertDictAlmostEqual(result_enabled.get_counts(circuit),
                                   result_disabled.get_counts(circuit),
                                   delta=0.0,
                                   msg="fusion for qft was failed")
Exemple #2
0
    def test_default_fusion(self):
        """Test default Fusion option"""
        default_threshold = 20
        shots = 100
        circuit = qft_circuit(default_threshold - 1, measure=True)
        qobj = assemble([circuit],
                        self.SIMULATOR,
                        shots=shots,
                        seed_simulator=1)

        backend_options = self.BACKEND_OPTS.copy()
        backend_options['fusion_verbose'] = True
        backend_options['optimize_ideal_threshold'] = 1
        backend_options['optimize_noise_threshold'] = 1

        result_verbose = self.SIMULATOR.run(
            qobj, backend_options=backend_options).result()
        self.assertTrue(getattr(result_verbose, 'success', 'False'))
        self.assertTrue('results' in result_verbose.to_dict(),
                        msg="results must exist in result")
        self.assertTrue('metadata' in result_verbose.to_dict()['results'][0],
                        msg="metadata must not exist in results[0]")
        self.assertTrue(
            'fusion_verbose'
            not in result_verbose.to_dict()['results'][0]['metadata'],
            msg="fusion must work for satevector")

        circuit = qft_circuit(default_threshold, measure=True)
        qobj = assemble([circuit],
                        self.SIMULATOR,
                        shots=shots,
                        seed_simulator=1)
        result_verbose = self.SIMULATOR.run(
            qobj, backend_options=backend_options).result()
        self.assertTrue(getattr(result_verbose, 'success', 'False'))
        self.assertTrue('results' in result_verbose.to_dict(),
                        msg="results must exist in result")
        self.assertTrue('metadata' in result_verbose.to_dict()['results'][0],
                        msg="metadata must exist in results[0]")
        self.assertTrue('fusion_verbose'
                        in result_verbose.to_dict()['results'][0]['metadata'],
                        msg="fusion must work for satevector")
Exemple #3
0
    def test_fusion_theshold(self):
        """Test fusion threhsold"""
        shots = 100
        threshold = 10
        backend_options = self.fusion_options(enabled=True,
                                              threshold=threshold)

        with self.subTest(msg='below fusion threshold'):
            circuit = transpile(qft_circuit(threshold - 1, measure=True),
                                self.SIMULATOR,
                                basis_gates=['u1', 'u2', 'u3', 'cx', 'cz'],
                                optimization_level=0)
            qobj = assemble(circuit, self.SIMULATOR, shots=shots)
            result = self.SIMULATOR.run(
                qobj, backend_options=backend_options).result()
            self.assertSuccess(result)
            meta = self.fusion_metadata(result)
            self.assertFalse(meta.get('applied', False))

        with self.subTest(msg='at fusion threshold'):
            circuit = transpile(qft_circuit(threshold, measure=True),
                                self.SIMULATOR,
                                basis_gates=['u1', 'u2', 'u3', 'cx', 'cz'],
                                optimization_level=0)
            qobj = assemble(circuit, self.SIMULATOR, shots=shots)
            result = self.SIMULATOR.run(
                qobj, backend_options=backend_options).result()
            self.assertSuccess(result)
            meta = self.fusion_metadata(result)
            self.assertTrue(meta.get('applied', False))

        with self.subTest(msg='above fusion threshold'):
            circuit = transpile(qft_circuit(threshold + 1, measure=True),
                                self.SIMULATOR,
                                basis_gates=['u1', 'u2', 'u3', 'cx', 'cz'],
                                optimization_level=0)
            qobj = assemble(circuit, self.SIMULATOR, shots=shots)
            result = self.SIMULATOR.run(
                qobj, backend_options=backend_options).result()
            self.assertSuccess(result)
            meta = self.fusion_metadata(result)
            self.assertTrue(meta.get('applied', False))
Exemple #4
0
    def test_fusion_theshold(self):
        """Test fusion threhsold"""
        shots = 100
        threshold = 10
        backend_options = self.fusion_options(enabled=True,
                                              threshold=threshold)

        with self.subTest(msg='below fusion threshold'):
            circuit = qft_circuit(threshold - 1, measure=True)
            qobj = assemble([circuit], self.SIMULATOR, shots=shots)
            result = self.SIMULATOR.run(
                qobj, backend_options=backend_options).result()
            meta = self.fusion_metadata(result)

            self.assertTrue(getattr(result, 'success', False))
            self.assertFalse(meta.get('applied', False))

        with self.subTest(msg='at fusion threshold'):
            circuit = qft_circuit(threshold, measure=True)
            qobj = assemble([circuit], self.SIMULATOR, shots=shots)
            result = self.SIMULATOR.run(
                qobj, backend_options=backend_options).result()
            meta = self.fusion_metadata(result)

            self.assertTrue(getattr(result, 'success', False))
            self.assertTrue(meta.get('applied', False))

        with self.subTest(msg='above fusion threshold'):
            circuit = qft_circuit(threshold + 1, measure=True)
            qobj = assemble([circuit], self.SIMULATOR, shots=shots)
            result = self.SIMULATOR.run(
                qobj, backend_options=backend_options).result()
            meta = self.fusion_metadata(result)

            self.assertTrue(getattr(result, 'success', False))
            self.assertTrue(meta.get('applied', False))
Exemple #5
0
    def test_fusion_qft(self):
        """Test Fusion with qft"""
        shots = 100

        circuit = qft_circuit(10, measure=True)
        qobj = assemble([circuit],
                        self.SIMULATOR,
                        shots=shots,
                        seed_simulator=1)

        backend_options = self.BACKEND_OPTS.copy()
        backend_options['fusion_enable'] = True
        backend_options['fusion_verbose'] = True
        backend_options['fusion_threshold'] = 1
        backend_options['optimize_ideal_threshold'] = 1
        backend_options['optimize_noise_threshold'] = 1

        result_fusion = self.SIMULATOR.run(
            qobj, backend_options=backend_options).result()
        self.assertTrue(getattr(result_fusion, 'success', 'False'))

        backend_options = self.BACKEND_OPTS.copy()
        backend_options['fusion_enable'] = False
        backend_options['fusion_verbose'] = True
        backend_options['fusion_threshold'] = 1
        backend_options['optimize_ideal_threshold'] = 1
        backend_options['optimize_noise_threshold'] = 1

        result_nonfusion = self.SIMULATOR.run(
            qobj, backend_options=backend_options).result()
        self.assertTrue(getattr(result_nonfusion, 'success', 'False'))

        self.assertDictAlmostEqual(result_fusion.get_counts(circuit),
                                   result_nonfusion.get_counts(circuit),
                                   delta=0.0,
                                   msg="fusion for qft was failed")