當前位置: 首頁>>代碼示例>>Python>>正文


Python sympy.Basic方法代碼示例

本文整理匯總了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) 
開發者ID:quantumlib,項目名稱:OpenFermion-Cirq,代碼行數:25,代碼來源:wrapped.py

示例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) 
開發者ID:solowPy,項目名稱:solowPy,代碼行數:22,代碼來源:model.py

示例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] 
開發者ID:XanaduAI,項目名稱:strawberryfields,代碼行數:26,代碼來源:parameters.py

示例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 
開發者ID:XanaduAI,項目名稱:strawberryfields,代碼行數:24,代碼來源:parameters.py

示例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 
開發者ID:QuantEcon,項目名稱:QuantEcon.lectures.code,代碼行數:18,代碼來源:model.py

示例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) 
開發者ID:QuantEcon,項目名稱:QuantEcon.lectures.code,代碼行數:23,代碼來源:model.py

示例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 
開發者ID:quantumlib,項目名稱:Cirq,代碼行數:27,代碼來源:resolve_parameters.py

示例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)) 
開發者ID:quantumlib,項目名稱:Cirq,代碼行數:21,代碼來源:parse.py

示例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 
開發者ID:quantumlib,項目名稱:Cirq,代碼行數:22,代碼來源:flatten_expressions.py

示例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) 
開發者ID:quantumlib,項目名稱:OpenFermion-Cirq,代碼行數:6,代碼來源:common_gates.py

示例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) 
開發者ID:quantumlib,項目名稱:OpenFermion-Cirq,代碼行數:6,代碼來源:common_gates.py

示例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) 
開發者ID:quantumlib,項目名稱:OpenFermion-Cirq,代碼行數:6,代碼來源:common_gates.py

示例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) 
開發者ID:quantumlib,項目名稱:OpenFermion-Cirq,代碼行數:6,代碼來源:common_gates.py

示例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 
開發者ID:solowPy,項目名稱:solowPy,代碼行數:15,代碼來源:ces.py

示例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 
開發者ID:solowPy,項目名稱:solowPy,代碼行數:17,代碼來源:model.py


注:本文中的sympy.Basic方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。