An object that explicitly specifies how to act on simulator states.



View source

Applies an action to the given argument, if it is a supported type.

For example, unitary operations can implement an _act_on_ method that checks if isinstance(args, cirq.ActOnStateVectorArgs) and, if so, apply their unitary effect to the state vector.

The global cirq.act_on method looks for whether or not the given argument has this value, before attempting any fallback strategies specified by the argument being acted on.

This method is analogous to python's __imul__ in that it is expected to perform an inline effect if it recognizes the type of an argument, and return NotImplemented otherwise. It is also analogous to python's __rmul__ in that dispatch is being done on the right hand side value instead of the left hand side value. If python had an __rimul__ method, then _act_on_ would not exist because it would be redundant.

args An object of unspecified type. The method must check if this object is of a recognized type and act on it if so.

True The receiving object (self) acted on the argument.
NotImplemented The receiving object did not act on the argument.

All other return values are considered to be errors.