# cirq.flatten_with_sweep¶

cirq.flatten_with_sweep(val: Any, sweep: Union[cirq.study.sweeps.Sweep, List[cirq.study.resolver.ParamResolver]]) → Tuple[Any, cirq.study.sweeps.Sweep][source]
Creates a copy of val with any symbols or expressions replaced with
new symbols. val can be a Circuit, Gate, Operation, or other
type. Also transforms a sweep over the symbols in val to a sweep over the
new symbols.
flatten_with_sweep goes through every parameter in val and does the
following:
• If the parameter is a number, don’t change it.

• If the parameter is a symbol, don’t change it and use the same symbol with the same values in the new sweep.

• If the parameter is an expression, replace it with a symbol and use the new symbol with the evaluated value of the expression in the new sweep. The new symbol will be sympy.Symbol('<x + 1>') if the expression was sympy.Symbol('x') + 1. In the unlikely case that an expression with a different meaning also has the string 'x + 1', a number is appended to the name to avoid collision: sympy.Symbol('<x + 1>_1').

Parameters
• val – The value to copy and substitute parameter expressions with

• symbols. (flattened) –

• sweep – A sweep over parameters used by val.

Returns

The tuple (new value, new sweep) where new value is val with flattened expressions and new sweep is the equivalent sweep over it.