Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ResetChannel does not do in-place modification of density matrices with qibojit #1300

Open
jf-kong opened this issue Apr 16, 2024 · 0 comments
Assignees

Comments

@jf-kong
Copy link
Contributor

jf-kong commented Apr 16, 2024

When using qibojit as backend, the initial state is typically modified in-place. This generally works for simple gates and with density matrices. However, ResetChannel does not seem to modify the initial density matrix in-place, as the following example shows. Is this the intended behaviour?

import numpy as np

import qibo
from qibo import gates
from qibo.models import Circuit

qibo.set_backend("qibojit", platform="numba")

circuit1 = Circuit(2, density_matrix=True)
circuit2 = Circuit(2, density_matrix=True)

# Create a simple circuit
circuit1.add(gates.H(0))
circuit1.add(gates.CNOT(0, 1))

# Create a second circuit that differs from the first only with a ResetChannel
circuit2.add(gates.H(0))
circuit2.add(gates.CNOT(0, 1))
circuit2.add(gates.ResetChannel(1, [1.0, 0.0]))  # The only difference

# Create two 4 x 4 identical density matrices
initial_state1 = np.array(
    [[0.5, 1, 0, 1], [1, 0.5, 0, 0], [0, 0, 0, 0], [1, 0, 0, 0]], dtype=np.complex128
)
initial_state2 = np.copy(initial_state1)

# Now execute the two circuits
final_state1 = circuit1(initial_state1)
final_state2 = circuit2(initial_state2)

# The intended behavior is that the initial states are modified in place (?)
# As such, the initial states should be close to the corresponding final states
# Test for closeness of the corresponding states
assert np.allclose(final_state1.state(), initial_state1, atol=1e-6)  # This passes
assert np.allclose(initial_state2, initial_state1, atol=1e-6)  # This passes when it shouldn't
assert np.allclose(final_state2.state(), initial_state2, atol=1e-6)  # This fails
@BrunoLiegiBastonLiegi BrunoLiegiBastonLiegi self-assigned this Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants