TeamGraphix / graphix

measurement-based quantum computing (MBQC) compiler and simulator
https://graphix.readthedocs.io
Apache License 2.0
55 stars 20 forks source link

[Bug]: ValueError in code snippet #59

Closed zilkf92 closed 1 year ago

zilkf92 commented 1 year ago

Describe the bug When executing the first code snippet in https://github.com/TeamGraphix/graphix/blob/master/docs/source/lc-mbqc.rst, a ValueError occurs. The ValueError occurs due to exchanged parameters for evolve_single(op, i) method. This issue prevents users from obtaining the expected results and might lead to confusion.

To Reproduce

  1. Copy the code snippet into a Python environment or integrated development environment (IDE):
    
    from graphix import GraphState
    import networkx as nx
    import numpy as np
    from graphix.sim.statevec import meas_op

graphstate and statevector instance

g = nx.complete_graph(4, create_using=GraphState) state = g.to_statevector()

measure qubit 0 in X basis, assume meas result s=0

g.measure_x(0, choice=0) state_from_graphsim = g.to_statevector()

do the same with statevector sim

state.evolve_single(0, meas_op(0, choice=0)) state.normalize() state.ptrace([0])


2. Execute the code snippet with the necessary dependencies.

3. Observe the ValueError being raised:
`ValueError: shape-mismatch for sum`

**Expected behavior**
The code snippet should run without errors.

**Environment:**
 - OS: Ubuntu 20.04.3 LTS focal
 - Python version: 3.10.11
 - graphix version: 0.2.2

**Solution:**
When parameters `op` (2x2 matrix; Type: np.array) and `i` (Qubit index; Type: int) are swapped, as indicated in the Module reference, the code executes without error.