Skip to content

Remove ptrace mention in the docstring (Partial trace of state vector backend) #73

@masa10-f

Description

@masa10-f

Update [@thierry-martinez]: The ptrace method has been removed from Statevec in #312. Note that there is still a reference to this method in the docstring of remove_qubit so I am leaving this issue open.

Describe the bug

The partial trace of a state vector is generally expected to return a density matrix, but Statevec.ptrace currently returns a state vector. This is an incorrect operation for non-separable quantum states, such as a Bell state.

To Reproduce

You can check the above behavior with the following code.

# %%
import numpy as np
from graphix.sim.statevec import Statevec

# %%
# prepare H and CNOT gates.
H = np.array([[1, 1], [1, -1]]) / np.sqrt(2)
CNOT = np.array([[1, 0, 0, 0], [0, 1, 0, 0],
                 [0, 0, 0, 1], [0, 0, 1, 0]])

# %%
# make a bell state
sv = Statevec(plus_states=False, nqubit=2)
sv.evolve(H, [0])
sv.evolve(CNOT, [0, 1])

print(sv.flatten())
# %%
# trace out 2nd qubit
sv.ptrace([1])
print(sv.flatten())
# the return should be |0><0| + |1><1| but, it returns |0> or |1>

Expected behavior

The Statevec.ptrace should return a density matrix. A code converting a reduced density matrix into a state vector should check its purity before conversion.

Environment (please complete the following information):

  • OS: Ubuntu 20.04
  • Python version: 3.8.10
  • Related module versions if applicable: graphix=0.2.0

Additional context

N/A

Metadata

Metadata

Labels

codingcoding (not mbqc-related) issue and proposalsdocumentationImprovements or additions to documentationquick fixsimulation backendrelated to numerical simulation backendwork-in-progress

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions