Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions cirq-core/cirq/linalg/transformations_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,20 @@ def test_factor_state_vector(state_1: int, state_2: int) -> None:
assert np.allclose(b1, b)


def test_density_matrix_kronecker_product() -> None:
matrix_1_array = np.array([[1, 0], [0, 0]], dtype=np.complex64)
matrix_2_array = (
np.array([[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]], dtype=np.complex64) / 4.0
)
matrix_1 = cirq.to_valid_density_matrix(matrix_1_array, qid_shape=(2,), dtype=np.complex64)
matrix_2 = cirq.to_valid_density_matrix(matrix_2_array, qid_shape=(4,), dtype=np.complex64)
calculated_result_shape = tuple(
map(lambda x, y: (x / 2 + y / 2) * 2, matrix_1_array.shape, matrix_2_array.shape)
)
Comment on lines +675 to +677
Copy link
Copy Markdown
Contributor Author

@joesho112358 joesho112358 Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @vtomole, i saw you were assigned to this PR automatically and wanted to call out that this is a draft because i am getting:

>       assert matrix_result.shape == calculated_result_shape
E       assert (2, 4, 2, 4) == (6.0, 6.0)

from the assertion that follows. Not sure where my math is failing, but guessing i am not fully understanding the function's docstring

matrix_result = cirq.linalg.transformations.density_matrix_kronecker_product(matrix_1, matrix_2)
assert matrix_result.shape == calculated_result_shape


@pytest.mark.parametrize('num_dimensions', [*range(1, 7)])
def test_transpose_flattened_array(num_dimensions) -> None:
np.random.seed(0)
Expand Down
Loading