Skip to content

Optimize product state mode setting #7462

Open
@daxfohl

Description

@daxfohl

Is your feature request related to a use case or problem? Please explain

Product state mode (controlled by the simulator flag split_untangled_states, defaults to True for all circuits. This likely isn't optimal.

Describe the solution you would prefer

While in theory, product state mode should always be faster, there are caveats

  • It substitutes 2N*2N matrix multiplication with N 2*2 multiplications (in the simplest case) for N qubits when they're not entangled. This seems nice, but for smallish N, a single large matrix multiplication in numpy could be much faster than jumping back and forth from C to Python N times. For qubits<N, where N needs to be determined by testing, it should default to False.
  • For nonterminal measurements, when the measured qubits immediately get entangled again, it causes an unnecessary factorization and re-kronning of the substates, that can be an expensive and useless operation.
  • For terminal measurements, there's no need to factor the substate after measuring because it's terminal.
  • The factorization and kronning of substates during simulation likely increases rounding error. (I would guess kronning-only has little to no effect, or plausibly even decrease error, but factorization would likely have a significant effect).
  • Perhaps the boolean flag should be replaced by an enum: None, KronOnly, and Full, where KronOnly starts in product state mode but doesn't try to factor after each measurement, whereas Full does both.
  • For real-world quantum circuits, the first step in many algorithms is "entangle all qubits". Perhaps the default setting should be Off.

I think the first bullet point could be done easily without tradeoffs; just run some simulations, figure out where the breakeven N is, and update the code to turn it off if N <= breakeven. The remainder may need more analysis in terms of real-world circuits we'd like to optimize for vs artificial examples that highlight a single characteristic.

How urgent is this for you? Is it blocking important work?

P3 – I'm not really blocked by it; it's an idea I'm proposing based on principle

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/simulationgood for learningFor beginners in QC, this will help picking up some knowledge. Bit harder than "good first issues"kind/feature-requestDescribes new functionality

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions