Пример #1
0
    def test_qpe_Z1(self, backend_type):
        """eigenproblem Z, |1>"""
        backend = qiskit.BasicAer.get_backend(backend_type)

        unitary_circuit = Z.to_circuit()
        state_preparation = X.to_circuit()  # prepare |1>
        phase = self.one_phase(unitary_circuit,
                               state_preparation,
                               backend=backend)
        self.assertEqual(phase, 0.5)
Пример #2
0
 def test_qpe_Z(self, state_preparation, expected_phase, backend_type,
                phase_estimator):
     """eigenproblem Z, |0> and |1>"""
     unitary_circuit = Z.to_circuit()
     phase = self.one_phase(
         unitary_circuit,
         state_preparation,
         backend_type=backend_type,
         phase_estimator=phase_estimator,
     )
     self.assertEqual(phase, expected_phase)
Пример #3
0
    def test_qpe_Zplus(self):
        """superposition eigenproblem Z, |+>"""
        unitary_circuit = Z.to_circuit()
        state_preparation = H.to_circuit()  # prepare |+>
        result = self.phase_estimation(
            unitary_circuit,
            state_preparation,
            backend=qiskit.BasicAer.get_backend('statevector_simulator'))

        phases = result.filter_phases(1e-15, as_float=True)
        with self.subTest('test phases has correct values'):
            self.assertEqual(list(phases.keys()), [0.0, 0.5])

        with self.subTest('test phases has correct probabilities'):
            np.testing.assert_allclose(list(phases.values()), [0.5, 0.5])

        with self.subTest('test bitstring representation'):
            phases = result.filter_phases(1e-15, as_float=False)
            self.assertEqual(list(phases.keys()), ['000000', '100000'])