Skip to content

SetFromTensorProduct may discard weights when promoting local qubits #6

Description

@hutchpd

Problem

In QuantumSystem.SetFromTensorProduct, promoted local qubits appear to have weights applied using WithWeights(...), but the returned value may be discarded.

If WithWeights returns a new qubit for local/non-system qubits, then calling it without assigning the result may silently lose the intended weights.

Why this matters

This could produce incorrect global wavefunctions when constructing a QuantumSystem from locally weighted qubits.

It is also an API trap because WithWeights appears to behave differently depending on whether a qubit is system-managed or local.

Suggested approach

Review the SetFromTensorProduct promotion path and ensure the result of WithWeights(...) is preserved.

For example:

sysQ = sysQ.WithWeights(weights, false);

or replace this with a clearer explicit in-place system method if that better matches the intended design.

Acceptance criteria

  • Weighted local qubits retain their amplitudes after being promoted into a QuantumSystem.
  • A regression test proves exact amplitude preservation after SetFromTensorProduct.
  • The test fails against the old behaviour and passes after the fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions