qojulia / qojulia/QuantumInterface.jl

Clarify traceout! semantics relative to ptrace across simulator backends

Open
#89 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
8
Forks
19
Avg merge
1d 21h
Merged PRs (30d)
2

Description

Summary

QuantumInterface declares both ptrace and traceout!, but the ecosystem currently uses traceout! for three materially different operations:

  1. an exact, non-mutating partial trace that returns a smaller state;
  2. an in-place reduction that retains the original native subsystem storage; and
  3. a stochastic pure-trajectory reduction whose ensemble reproduces a partial trace.

The only generic behavior currently supplied by QuantumInterface is:

traceout!(s::StateVector, i) = ptrace(s, i)

Source

Consequently, generic downstream code cannot infer from traceout! whether the input is mutated, whether nsubsystems decreases, or whether the returned state is the exact reduced state or one sampled trajectory.

Current behavior

Implementation traceout! behavior Mutates the input? Native subsystem count Relationship to ptrace
QuantumOptics Ket / state vector Inherits QuantumInterface's StateVector fallback. A pure input can return a mixed Operator. No; returns a replacement Decreases Exactly ptrace
QuantumOptics Operator Explicitly delegates to QuantumInterface.ptrace. No; returns a replacement Decreases Exactly ptrace
Gabs GaussianState GaussianState <: StateVector, so it inherits the same fallback and returns the Gaussian marginal with the selected modes removed. No; returns a replacement Decreases Exactly ptrace
QuantumClifford Stabilizer, MixedStabilizer, and MixedDestabilizer Canonicalizes the tableau and reduces stabilizer information/rank, but retains the traced qubits' tableau columns. The result is a same-width representation whose retained-subsystem observables agree with the partial trace. Yes Unchanged ptrace first applies this reduction to a copy and then removes the discarded columns, returning a genuinely smaller state
QuantumSavory internal MCKet Monte Carlo wrapper Samples a projection of the discarded subsystem in its canonical basis, discards the outcome, and returns the smaller conditional pure state. No; returns a replacement Decreases Not equal to the exact partial trace for one trajectory; the trajectory ensemble reproduces it. There is no ptrace(::MCKet, ...) method

Relevant implementations:

Concrete downstream problem

QuantumSavory PR #519 exposed the storage difference. QuantumSavory removes a register backreference and renumbers later subsystem indices after traceout!. That is correct for QuantumOptics, Gabs, and its Monte Carlo wrapper because their returned native states are smaller.

With QuantumClifford, however, native tableau columns remain allocated. QuantumSavory's surviving register indices then no longer identify the corresponding native columns. PR #519 therefore needs a private backend adapter that calls QuantumClifford ptrace instead of traceout!.

Questions for the interface contract

  1. Should ptrace(state, indices) be the exact, non-mutating operation that always returns a state on the complementary subsystem space?
  2. Should traceout! be required to produce the same mathematical and storage result as ptrace, with mutation only as an optimization?
  3. Must a successful traceout! decrease nsubsystems, or should retained/padded native storage be a supported contract with an explicit trait?
  4. If retained-column erasure is useful for reset and fixed circuit positions, should it have a separate name from partial trace?
  5. Should stochastic trajectory discard have a separate interface or an explicit trait, since one result is conditional while only the ensemble equals ptrace?
  6. Given that the current StateVector and QuantumOptics Operator methods do not mutate their inputs, should the bang-name contract be documented as "may mutate", or should the functional operation use another name?

Suggested outcome

A documented contract should let backend-neutral code determine at least:

  • whether the operation is exact or trajectory-sampled;
  • whether the original object can be mutated;
  • whether the returned native state has fewer subsystems; and
  • when traceout! is guaranteed to be equivalent to ptrace.

The resolution does not need to prescribe one storage strategy, but the distinction needs to be queryable or represented by separate operations.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the StateVector fallback in src/abstract_types.jl, then compare the cited QuantumOptics, Gabs, QuantumClifford, and MCKet implementations of ptrace and traceout!. Determine which semantics the interface can expose for mutation, subsystem count, exactness, and trajectory sampling. Done means the contract is documented or represented by distinct operations or queryable traits, with the backend differences addressed.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.