本文整理汇总了Python中sympy.Basic方法的典型用法代码示例。如果您正苦于以下问题:Python sympy.Basic方法的具体用法?Python sympy.Basic怎么用?Python sympy.Basic使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy
的用法示例。
在下文中一共展示了sympy.Basic方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: assert_eigengate_implements_consistent_protocols
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Basic [as 别名]
def assert_eigengate_implements_consistent_protocols(
eigen_gate_type: Type[cirq.EigenGate],
*,
exponents: Sequence[Union[sympy.Basic, float]] = (
0, 1, -1, 0.25, -0.5, 0.1, sympy.Symbol('s')),
global_shifts: Sequence[float] = (0, -0.5, 0.1),
qubit_count: Optional[int] = None,
ignoring_global_phase: bool=False,
setup_code: str = _setup_code,
global_vals: Optional[Dict[str, Any]] = None,
local_vals: Optional[Dict[str, Any]] = None) -> None:
"""Checks that an EigenGate subclass is internally consistent and has a
good __repr__."""
cirq.testing.assert_eigengate_implements_consistent_protocols(
eigen_gate_type,
exponents=exponents,
global_shifts=global_shifts,
qubit_count=qubit_count,
ignoring_global_phase=ignoring_global_phase,
setup_code=setup_code,
global_vals=global_vals,
local_vals=local_vals)
示例2: marginal_product_capital
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Basic [as 别名]
def marginal_product_capital(self):
r"""
Symbolic expression for the marginal product of capital (per unit
effective labor).
:getter: Return the current marginal product of capital.
:type: sympy.Basic
Notes
-----
The marginal product of capital is defined as follows:
.. math::
\frac{\partial F(K, AL)}{\partial K} \equiv f'(k)
where :math:`k=K/AL` is capital stock (per unit effective labor).
"""
return sym.diff(self.intensive_output, k)
示例3: par_convert
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Basic [as 别名]
def par_convert(args, prog):
"""Convert Blackbird symbolic Operation arguments into their SF counterparts.
Args:
args (Iterable[Any]): Operation arguments
prog (Program): program containing the Operations.
Returns:
list[Any]: converted arguments
"""
def do_convert(a):
if isinstance(a, sympy.Basic):
# substitute SF symbolic parameter objects for Blackbird ones
s = {}
for k in a.atoms(sympy.Symbol):
if k.name[0] == "q":
s[k] = MeasuredParameter(prog.register[int(k.name[1:])])
else:
s[k] = prog.params(k.name) # free parameter
return a.subs(s)
return a # return non-symbols as-is
return [do_convert(a) for a in args]
示例4: par_regref_deps
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Basic [as 别名]
def par_regref_deps(p):
"""RegRef dependencies of an Operation parameter.
Returns the RegRefs that the parameter depends on through the :class:`MeasuredParameter`
atoms it contains.
Args:
p (Any): Operation parameter
Returns:
set[RegRef]: RegRefs the parameter depends on
"""
ret = set()
if is_object_array(p):
# p is an object array, possibly containing symbols
for k in p:
ret.update(par_regref_deps(k))
elif isinstance(p, sympy.Basic):
# p is a Sympy expression, possibly containing measured parameters
for k in p.atoms(MeasuredParameter):
ret.add(k.regref)
return ret
示例5: __init__
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Basic [as 别名]
def __init__(self, output, params):
"""
Create an instance of the Solow growth model.
Parameters
----------
output : sym.Basic
Symbolic expression defining the aggregate production
function.
params : dict
Dictionary of model parameters.
"""
self.irf = impulse_response.ImpulseResponse(self)
self.output = output
self.params = params
示例6: marginal_product_capital
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Basic [as 别名]
def marginal_product_capital(self):
r"""
Symbolic expression for the marginal product of capital (per
unit effective labor).
:getter: Return the current marginal product of capital (per
unit effective labor).
:type: sym.Basic
Notes
-----
The marginal product of capital is defined as follows:
.. math::
\frac{\partial F(K, AL)}{\partial K} \equiv f'(k)
where :math:`k=K/AL` is capital stock (per unit effective labor)
"""
return sym.diff(self.intensive_output, k)
示例7: is_parameterized
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Basic [as 别名]
def is_parameterized(val: Any) -> bool:
"""Returns whether the object is parameterized with any Symbols.
A value is parameterized when it has an `_is_parameterized_` method and
that method returns a truthy value, or if the value is an instance of
sympy.Basic.
Returns:
True if the gate has any unresolved Symbols
and False otherwise. If no implementation of the magic
method above exists or if that method returns NotImplemented,
this will default to False.
"""
if isinstance(val, sympy.Basic):
return True
if isinstance(val, (list, tuple)):
return any(is_parameterized(e) for e in val)
getter = getattr(val, '_is_parameterized_', None)
result = NotImplemented if getter is None else getter()
if result is not NotImplemented:
return result
else:
return False
示例8: parse_formula
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Basic [as 别名]
def parse_formula(formula: str) -> Union[float, sympy.Basic]:
"""Attempts to parse formula text in exactly the same way as Quirk."""
if not isinstance(formula, str):
raise TypeError('formula must be a string')
token_map = {**PARSE_COMPLEX_TOKEN_MAP_RAD, 't': sympy.Symbol('t')}
result = _parse_formula_using_token_map(formula, token_map)
if isinstance(result, sympy.Basic):
if result.free_symbols:
return result
result = complex(result)
if isinstance(result, complex):
if abs(np.imag(result)) > 1e-8:
raise ValueError('Not a real result.')
result = np.real(result)
return float(cast(SupportsFloat, result))
示例9: transform_params
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Basic [as 别名]
def transform_params(self, params: resolver.ParamResolverOrSimilarType
) -> resolver.ParamDictType:
"""Returns a `ParamResolver` to use with a circuit flattened earlier
with `cirq.flatten`.
If `params` maps symbol `a` to 3.0 and this `ExpressionMap` maps
`a/2+1` to `'<a/2 + 1>'` then this method returns a resolver that maps
symbol `'<a/2 + 1>'` to 2.5.
See `cirq.flatten` for an example.
Args:
params: The params to transform.
"""
param_dict = {
sym: protocols.resolve_parameters(formula, params)
for formula, sym in self.items()
if isinstance(sym, sympy.Basic)
}
return param_dict
示例10: Rxxyy
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Basic [as 别名]
def Rxxyy(rads: float) -> cirq.ISwapPowGate:
"""Returns a gate with the matrix exp(-i rads (X⊗X + Y⊗Y) / 2)."""
pi = sympy.pi if isinstance(rads, sympy.Basic) else np.pi
return cirq.ISwapPowGate(exponent=-2 * rads / pi)
示例11: Ryxxy
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Basic [as 别名]
def Ryxxy(rads: float) -> cirq.PhasedISwapPowGate:
"""Returns a gate with the matrix exp(-i rads (Y⊗X - X⊗Y) / 2)."""
pi = sympy.pi if isinstance(rads, sympy.Basic) else np.pi
return cirq.PhasedISwapPowGate(exponent=2 * rads / pi)
示例12: Rzz
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Basic [as 别名]
def Rzz(rads: float) -> cirq.ZZPowGate:
"""Returns a gate with the matrix exp(-i Z⊗Z rads)."""
pi = sympy.pi if isinstance(rads, sympy.Basic) else np.pi
return cirq.ZZPowGate(exponent=2 * rads / pi, global_shift=-0.5)
示例13: rot11
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Basic [as 别名]
def rot11(rads: float) -> cirq.CZPowGate:
"""Phases the |11> state of two qubits by e^{i rads}."""
pi = sympy.pi if isinstance(rads, sympy.Basic) else np.pi
return cirq.CZ**(rads / pi)
示例14: solow_residual
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Basic [as 别名]
def solow_residual(self):
"""
Symbolic expression for the Solow residual which is used as a measure
of technology.
:getter: Return the symbolic expression.
:type: sym.Basic
"""
rho = (sigma - 1) / sigma
residual = (((1 / (1 - alpha)) * (Y / L)**rho -
(alpha / (1 - alpha)) * (K / L)**rho)**(1 / rho))
return residual
示例15: __init__
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Basic [as 别名]
def __init__(self, output, params):
"""
Create an instance of the Solow growth model.
Parameters
----------
output : sympy.Basic
Symbolic expression defining the aggregate production function.
params : dict
Dictionary of model parameters.
"""
self.irf = impulse_response.ImpulseResponse(self)
self.output = output
self.params = params