Skip to content

Commit

Permalink
Fix warning on array creation from ragged sequences (quantumlib#4801)
Browse files Browse the repository at this point in the history
Avoid conversion of ragged nested sequences to numpy array.
Use simple equality check to compare lists of tuples.
Use RandomState.choice to get item index instead of the item itself
which implies conversion to numpy.array.

Fixes  check/pytest -Werror:'Creating an ndarray from ragged'
  • Loading branch information
pavoljuhas authored and MichaelBroughton committed Jan 22, 2022
1 parent 0311fcf commit fadd14f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions cirq-core/cirq/ops/boolean_hamiltonian_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ def test_gray_code_sorting(n_bits, expected_hs):
hs = hs_template.copy()
random.shuffle(hs)

sorted_hs = sorted(list(hs), key=functools.cmp_to_key(bh._gray_code_comparator))
sorted_hs = sorted(hs, key=functools.cmp_to_key(bh._gray_code_comparator))

np.testing.assert_array_equal(sorted_hs, expected_hs)
assert sorted_hs == expected_hs


@pytest.mark.parametrize(
Expand Down
2 changes: 1 addition & 1 deletion cirq-core/cirq/transformers/transformer_primitives_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ def test_merge_operations_complexity(op_density):
lambda _, __: None,
lambda op1, _: op1,
lambda _, op2: op2,
lambda op1, op2: prng.choice([op1, op2, None]),
lambda op1, op2: (op1, op2, None)[prng.choice(3)],
]:

def wrapped_merge_func(op1, op2):
Expand Down

0 comments on commit fadd14f

Please sign in to comment.