CQCL / tket

Source code for the TKET quantum compiler, Python bindings and utilities
https://tket.quantinuum.com/
Apache License 2.0
252 stars 48 forks source link

`DecomposeClassicalExp` creates units that do not belong to a register #1585

Closed daniel-mills-cqc closed 1 week ago

daniel-mills-cqc commented 2 weeks ago

The following:

import json
from pytket.passes import DecomposeClassicalExp
from pytket import Circuit
from pytket.extensions.quantinuum import QuantinuumAPIOffline, QuantinuumBackend

backend = QuantinuumBackend(
    device_name="H1-1LE", api_handler=QuantinuumAPIOffline()
)

with open("no_reg_circ.json", 'r') as fp:
    circuit = Circuit.from_dict(json.load(fp))

DecomposeClassicalExp().apply(circuit)

compiled_circuit = backend.get_compiled_circuit(circuit)

n_shots = 100
result = backend.run_circuit(
    circuit=compiled_circuit,
    n_shots=n_shots,
)

raises an error ending in

File ~/.pyenv/versions/3.11.7/envs/mbqc_experiments/lib/python3.11/site-packages/pytket_pecos/emulator.py:31, in Emulator.__init__(self, circuit, wasm, error_model, qsim, seed)
     22 def __init__(
     23     self,
     24     circuit: Circuit,
   (...)
     28     seed: Optional[int] = None,
     29 ):
     30     if (not is_reglike(circuit.qubits)) or (not is_reglike(circuit.bits)):
---> 31         raise ValueError("Circuit contains units that do not belong to a register.")
     33     self.phir = pytket_to_phir(circuit)
     34     self.foreign_object = None if wasm is None else WasmtimeObj(wasm._wasm_file)

ValueError: Circuit contains units that do not belong to a register.

with the attached circuit. Without DecomposeClassicalExp there is no problem. It's not clear to me if this is a phir of tket problem. no_reg_circ.json

cqc-alec commented 2 weeks ago

Looks like this will be fixed by #1584 .