CQCL / pytket-qiskit

pytket-qiskit, extensions for pytket quantum SDK
Apache License 2.0
17 stars 13 forks source link

Handle bits selection in results for circuits with non-default registers #407

Closed cqc-alec closed 1 month ago

cqc-alec commented 1 month ago

Fixes #339 .

Also use PrimitiveResult for debug results instead of SamplerResult, to match real devices.

Tested locally by running:

from pytket.circuit import Circuit, Qubit, Bit
from pytket.extensions.qiskit import IBMQBackend

b = IBMQBackend("ibm_nazca")
c = Circuit(5)
c.add_c_register("a", 2)
c.add_c_register("b", 2)
c.add_c_register("c", 1)
c.H(0).CX(0, 1).Measure(Qubit(3), Bit("b", 1)).Measure(Qubit(0), Bit("c", 0))
c1 = b.get_compiled_circuit(c, optimisation_level=1)
h = b.process_circuit(c1, n_shots=10)
r = b.get_result(h)
print(r.get_counts(cbits=[Bit("b", 1), Bit("c", 0)]))

Output:

Counter({(0, 0): 6, (0, 1): 4})