Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ def _validate_input(

if all(q == ops.I for q in pauli_str):
raise ValueError(
"Empty Pauli strings or Pauli strings consisting"
"only of Pauli I are not allowed. Please provide"
"Empty Pauli strings or Pauli strings consisting "
"only of Pauli I are not allowed. Please provide "
"valid input Pauli strings."
)
if pauli_str.coefficient.imag != 0:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,9 @@ def _create_ghz(number_of_qubits: int, qubits: Sequence[cirq.Qid]) -> cirq.Circu
def _generate_random_pauli_string(qubits: Sequence[cirq.Qid], enable_coeff: bool = False):
pauli_ops = [cirq.I, cirq.X, cirq.Y, cirq.Z]

# Ensure at least one non-identity.
operators = {q: cirq.I(q) for q in qubits} # Start with all identities
# Choose a random subset of qubits to have non-identity operators
non_identity_qubits = random.sample(qubits, random.randint(1, len(qubits)))
for q in non_identity_qubits:
operators[q] = random.choice([cirq.X, cirq.Y, cirq.Z])(q) # Only non-identity ops
operators = {q: random.choice(pauli_ops) for q in qubits}
# Ensure at least one non-identity.
operators[random.choice(qubits)] = random.choice(pauli_ops[1:])

if enable_coeff:
coefficient = (2 * random.random() - 1) * 100
Expand Down Expand Up @@ -461,8 +457,8 @@ def test_all_pauli_strings_are_pauli_i() -> None:

with pytest.raises(
ValueError,
match="Empty Pauli strings or Pauli strings consisting"
"only of Pauli I are not allowed. Please provide"
match="Empty Pauli strings or Pauli strings consisting "
"only of Pauli I are not allowed. Please provide "
"valid input Pauli strings.",
):
measure_pauli_strings(
Expand Down