<commit_before># Copyright 2018 The Cirq Developers
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""A simplified time-slice of operations within a sequenced circuit."""

from typing import Iterable

from cirq import ops


class Moment(object):
    """A simplified time-slice of operations within a sequenced circuit.

    Note that grouping sequenced circuits into moments is an abstraction that
    may not carry over directly to the scheduling on the hardware or simulator.
    Operations in the same moment may or may not actually end up scheduled to
    occur at the same time. However the topological quantum circuit ordering
    will be preserved, and many schedulers or consumers will attempt to
    maximize the moment representation.

    Attributes:
        operations: A tuple of the Operations for this Moment.
        qubits: A set of the qubits acted upon by this Moment.
    """

    def __init__(self, operations: Iterable[ops.Operation] = ()) -> None:
        """Constructs a moment with the given operations.

        Args:
            operations: The operations applied within the moment.
                Will be frozen into a tuple before storing.

        Raises:
            ValueError: A qubit appears more than once.
        """
        self.operations = tuple(operations)

        # Check that operations don't overlap.
        affected_qubits = [q for op in self.operations for q in op.qubits]
        self.qubits = frozenset(affected_qubits)
        if len(affected_qubits) != len(self.qubits):
            raise ValueError(
                'Overlapping operations: {}'.format(ops))

    def operates_on(self, qubits: Iterable[ops.QubitId]) -> bool:
        """Determines if the moment has operations touching the given qubits.

        Args:
            qubits: The qubits that may or may not be touched by operations.

        Returns:
            Whether this moment has operations involving the qubits.
        """
        qubits = frozenset(qubits)
        return any(q in qubits for op in self.operations for q in op.qubits)

    def with_operation(self, operation: ops.Operation):
        """Returns an equal moment, but with the given op added.

        Args:
            operation: The operation to append.

        Returns:
            The new moment.
        """
        return Moment(self.operations + (operation,))

    def without_operations_touching(self, qubits: Iterable[ops.QubitId]):
        """Returns an equal moment, but without ops on the given qubits.
<commit_msg>Fix overlapping operations error printing the ops module instead of the relevant operations (#480)<commit_after># Copyright 2018 The Cirq Developers
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""A simplified time-slice of operations within a sequenced circuit."""

from typing import Iterable

from cirq import ops


class Moment(object):
    """A simplified time-slice of operations within a sequenced circuit.

    Note that grouping sequenced circuits into moments is an abstraction that
    may not carry over directly to the scheduling on the hardware or simulator.
    Operations in the same moment may or may not actually end up scheduled to
    occur at the same time. However the topological quantum circuit ordering
    will be preserved, and many schedulers or consumers will attempt to
    maximize the moment representation.

    Attributes:
        operations: A tuple of the Operations for this Moment.
        qubits: A set of the qubits acted upon by this Moment.
    """

    def __init__(self, operations: Iterable[ops.Operation] = ()) -> None:
        """Constructs a moment with the given operations.

        Args:
            operations: The operations applied within the moment.
                Will be frozen into a tuple before storing.

        Raises:
            ValueError: A qubit appears more than once.
        """
        self.operations = tuple(operations)

        # Check that operations don't overlap.
        affected_qubits = [q for op in self.operations for q in op.qubits]
        self.qubits = frozenset(affected_qubits)
        if len(affected_qubits) != len(self.qubits):
            raise ValueError(
                'Overlapping operations: {}'.format(self.operations))

    def operates_on(self, qubits: Iterable[ops.QubitId]) -> bool:
        """Determines if the moment has operations touching the given qubits.

        Args:
            qubits: The qubits that may or may not be touched by operations.

        Returns:
            Whether this moment has operations involving the qubits.
        """
        qubits = frozenset(qubits)
        return any(q in qubits for op in self.operations for q in op.qubits)

    def with_operation(self, operation: ops.Operation):
        """Returns an equal moment, but with the given op added.

        Args:
            operation: The operation to append.

        Returns:
            The new moment.
        """
        return Moment(self.operations + (operation,))

    def without_operations_touching(self, qubits: Iterable[ops.QubitId]):
        """Returns an equal moment, but without ops on the given qubits.

{'fraction_non_alphanumeric': 0.0648948312408283, 'fraction_numerical': 0.0030979944562204466, 'mean_word_length': 2.78875849289685, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3358519', 'n_tokens_mistral': 1560, 'n_tokens_neox': 1456, 'n_words': 719}