|View source on GitHub|
Applies arithmetic to a target and some inputs.
cirq.interop.quirk.QuirkArithmeticOperation( identifier: str, target: Sequence['cirq.Qid'], inputs: Sequence[Union[Sequence['cirq.Qid'], int]] )
Implements Quirk-specific implicit effects like assuming that the presence of an 'r' input implies modular arithmetic.
In Quirk, modular operations have no effect on values larger than the modulus. This convention is used because unitarity forces some convention on out-of-range values (they cannot simply disappear or raise exceptions), and the simplest is to do nothing. This call handles ensuring that happens, and ensuring the new target register value is normalized modulo the modulus.
||Returns a tuple of the operation's tags.|
||Returns the underlying operation without any tags.|
apply( *registers ) -> Union[int, Iterable[int]]
Returns the result of the operation operating on classical values.
For example, an addition takes two values (the target and the source), adds the source into the target, then returns the target and source as the new register values.
apply method is permitted to be sloppy in three ways:
applymethod is permitted to return values that have more bits than the registers they will be stored into. The extra bits are simply dropped. For example, if the value 5 is returned for a 2 qubit register then 5 % 22 = 1 will be used instead. Negative values are also permitted. For example, for a 3 qubit register the value -2 becomes -2 % 23 = 6.
- When the value of the last
kregisters is not changed by the operation, the
applymethod is permitted to omit these values from the result. That is to say, when the length of the output is less than the length of the input, it is padded up to the intended length by copying from the same position in the input.
- When only the first register's value changes, the
applymethod is permitted to return an
intinstead of a sequence of ints.
apply method must be reversible. Otherwise the operation will
not be unitary, and incorrect behavior will result.
A fully detailed adder:
def apply(self, target, offset): return (target + offset) % 2**len(self.target_register), offset
The same adder, with less boilerplate due to the details being
handled by the
def apply(self, target, offset): return target + offset
controlled_by( control_values: Optional[Sequence[Union[int, Collection[int]]]] = None, *control_qubits ) -> "cirq.Operation"
Returns a controlled version of this operation. If no control_qubits are specified, returns self.
||Qubits to control the operation by. Required.|
For which control qubit values to apply the
operation. A sequence of the same length as
registers() -> Sequence[Union[int, Sequence['cirq.Qid']]]
The data acted upon by the arithmetic operation.
Each register in the list can either be a classical constant (an
or else a list of qubits/qudits (a
List[cirq.Qid]). Registers that
are set to a classical constant must not be mutated by the arithmetic
operation (their value must remain fixed when passed to
Registers are big endian. The first qubit is the most significant, the last qubit is the 1s qubit, the before last qubit is the 2s qubit, etc.
|A list of constants and qubit groups that the operation will act upon.|
transform_qubits( qubit_map: Union[Dict['cirq.Qid', 'cirq.Qid'], Callable[['cirq.Qid'], 'cirq.Qid']] ) ->
Returns the same operation, but with different qubits.
||A function or a dict mapping each current qubit into a desired new qubit.|
|The receiving operation but with qubits transformed by the given function.|
||qubit_map was not a function or dict mapping qubits to qubits.|
validate_args( qubits: Sequence['cirq.Qid'] )
Raises an exception if the
qubits don't match this operation's qid
Call this method from a subclass's
||The new qids for the operation.|
||The operation had qids that don't match it's qid shape.|
with_probability( probability: "cirq.TParamVal" ) -> "cirq.Operation"
with_qubits( *new_qubits ) ->
Returns the same operation, but applied to different qubits.
The new qubits to apply the operation to. The order must
exactly match the order of qubits returned from the operation's
with_registers( *new_registers ) -> "QuirkArithmeticOperation"
Returns the same operation targeting different registers.
The new values that should be returned by the
|An instance of the same kind of operation, but acting on different registers.|
with_tags( *new_tags ) -> "cirq.TaggedOperation"
Creates a new TaggedOperation, with this op and the specified tags.
This method can be used to attach meta-data to specific operations without affecting their functionality. The intended usage is to attach classes intended for this purpose or strings to mark operations for specific usage that will be recognized by consumers. Specific examples include ignoring this operation in optimization passes, hardware-specific functionality, or circuit diagram customizability.
Tags can be a list of any type of object that is useful to identify this operation as long as the type is hashable. If you wish the resulting operation to be eventually serialized into JSON, you should also restrict the operation to be JSON serializable.
||The tags to wrap this operation in.|
__eq__( other: _SupportsValueEquality ) -> bool
__ne__( other: _SupportsValueEquality ) -> bool