flatten_with_params: Flatten with params

Description Usage Arguments Details Value following See Also

View source: R/sampling_simulations.R

Description

Creates a copy of 'val' with any symbols or expressions replaced with new symbols.

Usage

1
flatten_with_params(val, ..., params)

Arguments

val

The value to copy and substitute parameter expressions with flattened symbols.

...

additional parameters to pass.

params

A dictionary or 'ParamResolver' where the keys are 'sympy.Symbol's used by 'val' and the values are numbers.

Details

'val' can be a 'Circuit', 'Gate', 'Operation', or other type. Also transforms a dictionary of symbol values for 'val' to an equivalent dictionary mapping the new symbols to their evaluated values. 'flatten_with_params' 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 value in the new dictionary of symbol values. - 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 dictionary of symbol values. 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')'.

Value

The list (new value, new params) where new value is 'val' with flattened expressions and new params is a dictionary mapping the new symbols like ‘sympy.Symbol(’<x + 1>')‘ to numbers like 'params[’x'] + 1'.

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 value in the new dictionary of symbol values. - 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 dictionary of symbol values. 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')'.

See Also

Other Sampling, Simulations and Data collection: big_endian_bits_to_int(), big_endian_digits_to_int(), big_endian_int_to_bits(), big_endian_int_to_digits(), circuit_like(), final_density_matrix(), final_wavefunction(), flatten_to_ops_or_moments(), flatten_to_ops(), flatten_with_sweep(), flatten(), hog_score_xeb_fidelity_from_probabilities(), measure_density_matrix(), measure_state_vector(), random_state_or_seed_like(), sample_density_matrix(), sample_state_vector(), sample_sweep(), sample(), to_resolvers(), to_sweep(), validate_mixture()


henry090/Cirq documentation built on June 13, 2020, 1:28 a.m.