A stateful quantum handler for native controllers #
The handler uses the existing joint density matrix of a fixed active register and an untouched
reference, together with the classical service state. The native word program is unchanged:
ProbOracleComp.runWith interprets its requests through DeviceRequest.codec. One fixed H is
passed to the complete run. Sampling H belongs outside that run, so adaptive stages share it.
Gates and coherent queries use the existing OracleGateCode decoder. A malformed instruction is
a no-op. A measurement uses classicalDensityBranch and PMF.bindOnSupport; only supported
branches are normalized. It measures one wire while retaining the complete joint state.
Classical service replies have an explicit fixed bit width. Their implementation cost remains
outside the native controller's cost, as with other external oracle services.
These are original interface and composition results. The quantum operations reuse the unitary and projective-measurement semantics of de Wolf, §15.1, p. 128. No density matrix is encoded as a classical machine word, and no efficient classical simulation is claimed.
Main definitions #
Cslib.Quantum.DeviceState: the joint density matrix and the external classical service state.Cslib.Quantum.DeviceState.evolve: an existing active-register unitary, with reference intact.Cslib.Quantum.DeviceState.measure: supported finite classical readout.Cslib.Quantum.deviceHandler: typed elementary quantum and classical service operations.Cslib.Quantum.deviceWordHandler: the canonical word interface for the existing controller.
The semantic state of the device: the existing joint density matrix and classical service state. The reference register is never addressed by a controller request.
Joint active/reference density matrix.
- isDensityMatrix : IsDensityMatrix self.density
Positivity and unit trace of that matrix.
- serviceState : State
State used only by the external classical service.
Apply an existing unitary to the active register, retaining every reference correlation.
The state update is exactly the existing matrix conjugation by U ⊗ I.
Every active-register unitary preserves the reference marginal, including entangled inputs.
Execute one existing instruction. Malformed placements or an oversized query are skipped,
exactly as in OracleCircuit.toCircuit.
Instruction execution uses precisely the existing placed-gate decoder.
The existing decoder's rejection leaves the complete state unchanged.
Read a finite classical function of the active basis index, retaining the supported normalized joint state. The native handler specializes this operation to reading one wire.
Continue directly from the supported conditional states of a classical readout.
Forgetting the conditional state gives exactly the existing mapped basis measurement.
A readout whose selected branch already contains the whole state is deterministic and preserves that state, including its reference correlations.
Typed device operations. The service returns exactly r bits and never accesses the joint
quantum state. All coherent calls use the same supplied function H.
An elementary gate returns the empty acknowledgement.
A wire measurement reports its single outcome bit.
The classical service changes only its own state and reports exactly its fixed-width reply.
Every reply has an explicit size bound: quantum acknowledgements are empty, measurements
return one bit, and classical services return their declared r bits.
The word interface uses OracleCodec.wordOracle; noncanonical words return [] without
an operation or state change.
The word handler is the existing codec adaptation of the typed handler.
A canonically encoded request executes its typed operation, with the same complete state.
Rejected word requests have the explicit answer [] and preserve the full device state.