test_projectq_cpp_simulator.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:qiskit-sdk-py 作者: QISKit 项目源码 文件源码
def test_random_circuits(self):
        local_simulator = qasm_simulator.QasmSimulator()
        for circuit in self.rqg.get_circuits(format='QuantumCircuit'):
            self.log.info(circuit.qasm())
            compiled_circuit = openquantumcompiler.compile(circuit.qasm())
            shots = 100
            min_cnts = int(shots / 10)
            job_pq = QuantumJob(compiled_circuit,
                                backend='local_projectq_simulator',
                                seed=1, shots=shots)
            job_py = QuantumJob(compiled_circuit,
                                backend='local_qasm_simulator',
                                seed=1, shots=shots)
            result_pq = pq_simulator.run(job_pq)
            result_py = local_simulator.run(job_py)
            counts_pq = result_pq.get_counts(result_pq.get_names()[0])
            counts_py = result_py.get_counts(result_py.get_names()[0])
            # filter states with few counts
            counts_pq = {key:cnt for key,cnt in counts_pq.items() if cnt > min_cnts}
            counts_py = {key:cnt for key,cnt in counts_py.items() if cnt > min_cnts}
            self.log.info('local_projectq_simulator: ' + str(counts_pq))
            self.log.info('local_qasm_simulator: ' + str(counts_py))
            self.assertTrue(counts_pq.keys() == counts_py.keys())
            states = counts_py.keys()
            # contingency table
            ctable = numpy.array([[counts_pq[key] for key in states],
                                  [counts_py[key] for key in states]])
            result = chi2_contingency(ctable)
            self.log.info('chi2_contingency: ' + str(result))
            with self.subTest():
                self.assertGreater(result[1], 0.01)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号