Skip to content

Commit

Permalink
Fix operator_spaces.py::kron_bases initial value (quantumlib#4716)
Browse files Browse the repository at this point in the history
Fix dimensionality of initial array in kron_bases.

This was causing failures when working with zero-qubit gates: empty pauli strings, Identity(0), and the new GlobalPhaseGate.

cc @viathor to review
  • Loading branch information
daxfohl authored Nov 30, 2021
1 parent 1021db7 commit 196318f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cirq/linalg/operator_spaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

def kron_bases(*bases: Dict[str, np.ndarray], repeat: int = 1) -> Dict[str, np.ndarray]:
"""Creates tensor product of bases."""
product_basis = {'': np.ones(1)}
product_basis = {'': np.array([[1]])}
for basis in bases * repeat:
product_basis = {
name1 + name2: np.kron(matrix1, matrix2)
Expand Down
4 changes: 1 addition & 3 deletions cirq/linalg/operator_spaces_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,7 @@ def test_kron_bases_consistency(basis1, basis2):
assert np.all(basis1[name] == basis2[name])


@pytest.mark.parametrize(
'basis,repeat', itertools.product((PAULI_BASIS, STANDARD_BASIS), range(1, 5))
)
@pytest.mark.parametrize('basis,repeat', itertools.product((PAULI_BASIS, STANDARD_BASIS), range(5)))
def test_kron_bases_repeat_sanity_checks(basis, repeat):
product_basis = cirq.kron_bases(basis, repeat=repeat)
assert len(product_basis) == 4 ** repeat
Expand Down

0 comments on commit 196318f

Please sign in to comment.