Ejemplo n.º 1
0
    def test_full_qpt(self, num_qubits, fitter):
        """Test QPT experiment"""
        backend = AerSimulator(seed_simulator=9000)
        seed = 1234
        f_threshold = 0.94
        target = qi.random_unitary(2**num_qubits, seed=seed)
        qstexp = ProcessTomography(target)
        if fitter:
            qstexp.analysis.set_options(fitter=fitter)
        expdata = qstexp.run(backend)
        results = expdata.analysis_results()

        # Check state is density matrix
        state = filter_results(results, "state").value
        self.assertTrue(isinstance(state, qi.Choi),
                        msg="fitted state is not a Choi matrix")

        # Check fit state fidelity
        fid = filter_results(results, "process_fidelity").value
        self.assertGreater(fid, f_threshold, msg="fit fidelity is low")
        # Manually check fidelity
        target_fid = qi.process_fidelity(state,
                                         target,
                                         require_tp=False,
                                         require_cp=False)
        self.assertAlmostEqual(fid,
                               target_fid,
                               places=6,
                               msg="result fidelity is incorrect")
Ejemplo n.º 2
0
    def test_qpt_teleport(self):
        """Test subset state tomography generation"""
        # NOTE: This test breaks transpiler. I think it is a bug with
        # conditionals in Terra.

        # Teleport qubit 0 -> 2
        backend = AerSimulator(seed_simulator=9000)
        exp = ProcessTomography(teleport_circuit(),
                                measurement_qubits=[2],
                                preparation_qubits=[0])
        expdata = exp.run(backend, shots=10000)
        results = expdata.analysis_results()

        # Check result
        f_threshold = 0.95

        # Check state is density matrix
        state = filter_results(results, "state").value
        self.assertTrue(isinstance(state, qi.Choi),
                        msg="fitted state is not a Choi matrix")

        # Manually check fidelity
        fid = qi.process_fidelity(state, require_tp=False, require_cp=False)
        self.assertGreater(fid,
                           f_threshold,
                           msg="fitted state fidelity is low")
Ejemplo n.º 3
0
    def test_full_exp_meas_prep_qubits(self, qubits):
        """Test subset state tomography generation"""
        # Subsystem unitaries
        seed = 1111
        nq = 3
        ops = [qi.random_unitary(2, seed=seed + i) for i in range(nq)]

        # Target state
        target_circ = QuantumCircuit(len(qubits))
        for i, qubit in enumerate(qubits):
            target_circ.append(ops[qubit], [i])
        target = qi.Operator(target_circ)

        # Preparation circuit
        circ = QuantumCircuit(nq)
        for i, op in enumerate(ops):
            circ.append(op, [i])

        # Run
        backend = AerSimulator(seed_simulator=9000)
        exp = ProcessTomography(circ,
                                measurement_qubits=qubits,
                                preparation_qubits=qubits)
        expdata = exp.run(backend)
        self.assertExperimentDone(expdata)
        results = expdata.analysis_results()

        # Check result
        f_threshold = 0.95

        # Check state is density matrix
        state = filter_results(results, "state").value
        self.assertTrue(isinstance(state, qi.Choi),
                        msg="fitted state is not a Choi matrix")

        # Check fit state fidelity
        fid = filter_results(results, "process_fidelity").value
        self.assertGreater(fid, f_threshold, msg="fit fidelity is low")

        # Manually check fidelity
        target_fid = qi.process_fidelity(state,
                                         target,
                                         require_tp=False,
                                         require_cp=False)
        self.assertAlmostEqual(fid,
                               target_fid,
                               places=6,
                               msg="result fidelity is incorrect")