Skip to content

simulate_moment_steps return invalid density matrices #3100

Closed
@CirqUser199

Description

@CirqUser199

When I try to simulate the density matrix through a circuit using simulate_moment_steps, I have some density matrices that have a trace different than 1 for some steps. For instance, when I execute the simple code below, the last line returns 1/2. If I did no mistake, this means that the simulator returns a density matrix that has trace less than 1. From what I can see, this could be caused by the insert strategy (maybe it interferes with the moment by moment simulator). Did you already hear about such an issue?

import cirq
import numpy as np
from cirq.circuits import InsertStrategy
q0, q1, q2, q3, q4, q5, q6 = cirq.LineQubit.range(7)

example_circuit=cirq.Circuit()
example_circuit.append([cirq.rx(3*np.pi/7)(q0),cirq.rx(3*np.pi/5)(q1),cirq.rx(np.pi/4)(q2)])
example_circuit.append([cirq.ry(1*np.pi/5)(q0),cirq.ry(3*np.pi/2)(q1),cirq.ry(2*np.pi/5)(q2)])
example_circuit.append([cirq.H(q3),cirq.H(q4)], strategy=InsertStrategy.NEW_THEN_INLINE)
example_circuit.append([cirq.CNOT(q3,q5),cirq.CNOT(q4,q6)], strategy=InsertStrategy.NEW_THEN_INLINE)

sim = cirq.DensityMatrixSimulator()
example_densities=[]

for i, step in enumerate(sim.simulate_moment_steps(example_circuit)):
    example_densities.append(step.density_matrix())
    
np.trace(example_densities[2])

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions