Last active
February 25, 2021 10:47
-
-
Save quantumjim/40d6616d61f53d3905aeb534e29eaf13 to your computer and use it in GitHub Desktop.
topo codes test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from qiskit.ignis.verification.topological_codes import RepetitionCode | |
from qiskit.ignis.verification.topological_codes import GraphDecoder | |
from qiskit import execute, Aer, QuantumCircuit | |
import copy | |
HAS_AER = True | |
max_dist = 5 | |
for d in range(3,max_dist): | |
code = RepetitionCode(d, 2) | |
dec = GraphDecoder(code) | |
qc = code.circuit['0'] | |
blank_qc = QuantumCircuit() | |
for qreg in qc.qregs: | |
blank_qc.add_register(qreg) | |
for creg in qc.cregs: | |
blank_qc.add_register(creg) | |
error_circuit = {} | |
circuit_name = {} | |
depth = len(qc) | |
for j in range(depth): | |
qubits = qc.data[j][1] | |
for qubit in qubits: | |
for error in ['x', 'y', 'z']: | |
temp_qc = copy.deepcopy(blank_qc) | |
temp_qc.name = str((j, qubit, error)) | |
temp_qc.data = qc.data[0:j] | |
getattr(temp_qc, error)(qubit) | |
temp_qc.data += qc.data[j:depth + 1] | |
circuit_name[(j, qubit, error)] = temp_qc.name | |
error_circuit[temp_qc.name] = temp_qc | |
if HAS_AER: | |
simulator = Aer.get_backend('qasm_simulator') | |
else: | |
simulator = BasicAer.get_backend('qasm_simulator') | |
job = execute(list(error_circuit.values()), simulator) | |
for error_name in error_circuit: | |
counts = job.result().get_counts(error_circuit[error_name]) | |
results = code.process_results({'0':counts}) | |
logical_prob_match = dec.get_logical_prob(results) | |
assert logical_prob_match['0']==0.0, 'Error '+error_name+' causes a logical error for a code of distance '+str(d)+'.' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment