tensorcircuit.cons#

Constants and setups

tensorcircuit.cons.contraction_info_decorator(algorithm: Callable[[...], Any]) Callable[[...], Any][源代码]#
tensorcircuit.cons.contractor(nodes: List[Any], *, optimizer: Any = <function greedy>, memory_limit: Optional[int] = None, output_edge_order: Optional[List[Any]] = None, ignore_edge_order: bool = False, **kws: Any) Any#
tensorcircuit.cons.custom(nodes: List[Any], optimizer: Any, memory_limit: Optional[int] = None, output_edge_order: Optional[List[Any]] = None, ignore_edge_order: bool = False, **kws: Any) Any[源代码]#
tensorcircuit.cons.custom_stateful(nodes: List[Any], optimizer: Any, memory_limit: Optional[int] = None, opt_conf: Optional[Dict[str, Any]] = None, output_edge_order: Optional[List[Any]] = None, ignore_edge_order: bool = False, **kws: Any) Any[源代码]#
tensorcircuit.cons.d2s(n: int, dl: List[Any]) List[Any][源代码]#
tensorcircuit.cons.experimental_contractor(nodes: List[Any], output_edge_order: Optional[List[Any]] = None, ignore_edge_order: bool = False, local_steps: int = 2) Any[源代码]#
tensorcircuit.cons.get_contractor(method: Optional[str] = None, optimizer: Optional[Any] = None, memory_limit: Optional[int] = None, opt_conf: Optional[Dict[str, Any]] = None, *, set_global: bool = False, contraction_info: bool = False, debug_level: int = 0, **kws: Any) Callable[[...], Any]#

To set runtime contractor of the tensornetwork for a better contraction path. For more information on the usage of contractor, please refer to independent tutorial.

参数
  • method (Optional[str], optional) -- "auto", "greedy", "branch", "plain", "tng", "custom", "custom_stateful". defaults to None ("auto")

  • optimizer (Optional[Any], optional) -- Valid for "custom" or "custom_stateful" as method, defaults to None

  • memory_limit (Optional[int], optional) -- It is not very useful, as memory_limit leads to branch contraction instead of greedy which is rather slow, defaults to None

引发
  • Exception -- Tensornetwork version is too low to support some of the contractors.

  • ValueError -- Unknown method options.

返回

The new tensornetwork with its contractor set.

返回类型

tn.Node

tensorcircuit.cons.get_dtype(dtype: Optional[str] = None, *, set_global: bool = False) Tuple[str, str]#

Set the global runtime numerical dtype of tensors.

参数

dtype (Optional[str], optional) -- "complex64"/"float32" or "complex128"/"float64", defaults to None, which is equivalent to "complex64".

返回

complex dtype str and the corresponding real dtype str

返回类型

Tuple[str, str]

tensorcircuit.cons.nodes_to_adj(ns: List[Any]) Any[源代码]#
tensorcircuit.cons.plain_contractor(nodes: List[Any], output_edge_order: Optional[List[Any]] = None, ignore_edge_order: bool = False) Any[源代码]#

The naive state-vector simulator contraction path.

参数
  • nodes (List[Any]) -- The list of tn.Node.

  • output_edge_order (Optional[List[Any]], optional) -- The list of dangling node edges, defaults to be None.

返回

The tn.Node after contraction

返回类型

tn.Node

tensorcircuit.cons.runtime_backend(backend: Optional[str] = None) Iterator[Any][源代码]#

Context manager to set with-level runtime backend

参数

backend (Optional[str], optional) -- "numpy", "tensorflow", "jax", "pytorch", defaults to None

Yield

the backend object

返回类型

Iterator[Any]

tensorcircuit.cons.runtime_contractor(*confargs: Any, **confkws: Any) Iterator[Any][源代码]#

Context manager to change with-levek contractor

Yield

_description_

返回类型

Iterator[Any]

tensorcircuit.cons.runtime_dtype(dtype: Optional[str] = None) Iterator[Tuple[str, str]][源代码]#

Context manager to set with-level runtime dtype

参数

dtype (Optional[str], optional) -- "complex64" or "complex128", defaults to None ("complex64")

Yield

complex dtype str and real dtype str

返回类型

Iterator[Tuple[str, str]]

tensorcircuit.cons.set_backend(backend: Optional[str] = None, set_global: bool = True) Any#

To set the runtime backend of tensorcircuit.

Note: tc.set_backend and tc.cons.set_tensornetwork_backend are the same.

Example

>>> tc.set_backend("numpy")
numpy_backend
>>> tc.gates.num_to_tensor(0.1)
array(0.1+0.j, dtype=complex64)
>>>
>>> tc.set_backend("tensorflow")
tensorflow_backend
>>> tc.gates.num_to_tensor(0.1)
<tf.Tensor: shape=(), dtype=complex64, numpy=(0.1+0j)>
>>>
>>> tc.set_backend("pytorch")
pytorch_backend
>>> tc.gates.num_to_tensor(0.1)
tensor(0.1000+0.j)
>>>
>>> tc.set_backend("jax")
jax_backend
>>> tc.gates.num_to_tensor(0.1)
DeviceArray(0.1+0.j, dtype=complex64)
参数
  • backend (Optional[str], optional) -- "numpy", "tensorflow", "jax", "pytorch". defaults to None, which gives the same behavior as tensornetwork.backend_contextmanager.get_default_backend().

  • set_global (bool) -- Whether the object should be set as global.

返回

The tc.backend object that with all registered universal functions.

返回类型

backend object

tensorcircuit.cons.set_contractor(method: Optional[str] = None, optimizer: Optional[Any] = None, memory_limit: Optional[int] = None, opt_conf: Optional[Dict[str, Any]] = None, set_global: bool = True, contraction_info: bool = False, debug_level: int = 0, **kws: Any) Callable[[...], Any][源代码]#

To set runtime contractor of the tensornetwork for a better contraction path. For more information on the usage of contractor, please refer to independent tutorial.

参数
  • method (Optional[str], optional) -- "auto", "greedy", "branch", "plain", "tng", "custom", "custom_stateful". defaults to None ("auto")

  • optimizer (Optional[Any], optional) -- Valid for "custom" or "custom_stateful" as method, defaults to None

  • memory_limit (Optional[int], optional) -- It is not very useful, as memory_limit leads to branch contraction instead of greedy which is rather slow, defaults to None

引发
  • Exception -- Tensornetwork version is too low to support some of the contractors.

  • ValueError -- Unknown method options.

返回

The new tensornetwork with its contractor set.

返回类型

tn.Node

tensorcircuit.cons.set_dtype(dtype: Optional[str] = None, set_global: bool = True) Tuple[str, str][源代码]#

Set the global runtime numerical dtype of tensors.

参数

dtype (Optional[str], optional) -- "complex64"/"float32" or "complex128"/"float64", defaults to None, which is equivalent to "complex64".

返回

complex dtype str and the corresponding real dtype str

返回类型

Tuple[str, str]

tensorcircuit.cons.set_function_backend(backend: Optional[str] = None) Callable[[...], Any][源代码]#

Function decorator to set function-level runtime backend

参数

backend (Optional[str], optional) -- "numpy", "tensorflow", "jax", "pytorch", defaults to None

返回

Decorated function

返回类型

Callable[..., Any]

tensorcircuit.cons.set_function_contractor(*confargs: Any, **confkws: Any) Callable[[...], Any][源代码]#

Function decorate to change function-level contractor

返回

_description_

返回类型

Callable[..., Any]

tensorcircuit.cons.set_function_dtype(dtype: Optional[str] = None) Callable[[...], Any][源代码]#

Function decorator to set function-level numerical dtype

参数

dtype (Optional[str], optional) -- "complex64" or "complex128", defaults to None

返回

The decorated function

返回类型

Callable[..., Any]

tensorcircuit.cons.set_tensornetwork_backend(backend: Optional[str] = None, set_global: bool = True) Any[源代码]#

To set the runtime backend of tensorcircuit.

Note: tc.set_backend and tc.cons.set_tensornetwork_backend are the same.

Example

>>> tc.set_backend("numpy")
numpy_backend
>>> tc.gates.num_to_tensor(0.1)
array(0.1+0.j, dtype=complex64)
>>>
>>> tc.set_backend("tensorflow")
tensorflow_backend
>>> tc.gates.num_to_tensor(0.1)
<tf.Tensor: shape=(), dtype=complex64, numpy=(0.1+0j)>
>>>
>>> tc.set_backend("pytorch")
pytorch_backend
>>> tc.gates.num_to_tensor(0.1)
tensor(0.1000+0.j)
>>>
>>> tc.set_backend("jax")
jax_backend
>>> tc.gates.num_to_tensor(0.1)
DeviceArray(0.1+0.j, dtype=complex64)
参数
  • backend (Optional[str], optional) -- "numpy", "tensorflow", "jax", "pytorch". defaults to None, which gives the same behavior as tensornetwork.backend_contextmanager.get_default_backend().

  • set_global (bool) -- Whether the object should be set as global.

返回

The tc.backend object that with all registered universal functions.

返回类型

backend object

tensorcircuit.cons.split_rules(max_singular_values: Optional[int] = None, max_truncation_err: Optional[float] = None, relative: bool = False) Any[源代码]#

Obtain the direcionary of truncation rules

参数
  • max_singular_values (int, optional) -- The maximum number of singular values to keep.

  • max_truncation_err (float, optional) -- The maximum allowed truncation error.

  • relative (bool, optional) -- Multiply max_truncation_err with the largest singular value.

tensorcircuit.cons.tn_greedy_contractor(nodes: List[Any], output_edge_order: Optional[List[Any]] = None, ignore_edge_order: bool = False, max_branch: int = 1) Any[源代码]#