uid stringlengths 24 24 | split stringclasses 1
value | category stringclasses 2
values | content stringlengths 5 482k | signature stringlengths 1 14k | suffix stringlengths 1 482k | prefix stringlengths 9 14k | prefix_token_count int64 3 5.01k | prefix_token_budget int64 64 256 | element_token_count int64 1 292k | signature_token_count int64 1 5.01k | prefix_context_token_count int64 0 255 | repo stringlengths 7 112 | path stringlengths 4 208 | language stringclasses 1
value | name stringlengths 1 218 | qualname stringlengths 1 218 | start_line int64 1 26.7k | end_line int64 1 26.7k | signature_start_line int64 1 26.7k | signature_end_line int64 1 26.7k | source_hash stringlengths 40 40 | source_dataset stringclasses 1
value | source_split stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
77fbdeb498ad1260ab06e64d | train | class | @PIPELINES.register_module()
class BottomUpResizeAlign:
"""Resize multi-scale size and align transform for bottom-up.
Args:
transforms (List): ToTensor & Normalize
use_udp (bool): To use unbiased data processing.
Paper ref: Huang et al. The Devil is in the Details: Delving into
... | @PIPELINES.register_module()
class BottomUpResizeAlign:
| """Resize multi-scale size and align transform for bottom-up.
Args:
transforms (List): ToTensor & Normalize
use_udp (bool): To use unbiased data processing.
Paper ref: Huang et al. The Devil is in the Details: Delving into
Unbiased Data Processing for Human Pose Estimati... | 2.0), round(h / 2.0)])
results['ann_info']['test_scale_factor'] = self.test_scale_factor
results['ann_info']['base_size'] = (w_resized, h_resized)
results['ann_info']['center'] = center
results['ann_info']['scale'] = np.array([scale_w, scale_h])
return results
@PIPELINES.regist... | 93 | 93 | 310 | 12 | 80 | SummerVideoAnalysis/mmpose | mmpose/datasets/pipelines/bottom_up_transform.py | Python | BottomUpResizeAlign | BottomUpResizeAlign | 712 | 747 | 712 | 713 | 57ad7b458d521a16989d290b54661118f2a7de49 | bigcode/the-stack | train |
5854c90644a4710f655fde4d | train | function | def _ceil_to_multiples_of(x, base=64):
"""Transform x to the integral multiple of the base."""
return int(np.ceil(x / base)) * base
| def _ceil_to_multiples_of(x, base=64):
| """Transform x to the integral multiple of the base."""
return int(np.ceil(x / base)) * base
| 2
import numpy as np
from mmpose.core.post_processing import (get_affine_transform, get_warp_matrix,
warp_affine_joints)
from mmpose.datasets.builder import PIPELINES
from .shared_transform import Compose
def _ceil_to_multiples_of(x, base=64):
| 64 | 64 | 38 | 14 | 49 | SummerVideoAnalysis/mmpose | mmpose/datasets/pipelines/bottom_up_transform.py | Python | _ceil_to_multiples_of | _ceil_to_multiples_of | 10 | 12 | 10 | 10 | f23d89d30a8a3fa0b4eb4c9c73adb94ae6d0cca9 | bigcode/the-stack | train |
a63cf03c553a2aae77b398f9 | train | class | class JointsEncoder:
"""Encodes the visible joints into (coordinates, score); The coordinate of
one joint and its score are of `int` type.
(idx * output_size**2 + y * output_size + x, 1) or (0, 0).
Args:
max_num_people(int): Max number of people in an image
num_joints(int): Number of k... | class JointsEncoder:
| """Encodes the visible joints into (coordinates, score); The coordinate of
one joint and its score are of `int` type.
(idx * output_size**2 + y * output_size + x, 1) or (0, 0).
Args:
max_num_people(int): Max number of people in an image
num_joints(int): Number of keypoints
outp... | self.output_size) - ul[0]
a, b = max(0, -ul[1]), min(br[1], self.output_size) - ul[1]
cc, dd = max(0, ul[0]), min(br[0], self.output_size)
aa, bb = max(0, ul[1]), min(br[1], self.output_size)
hms[idx, aa:bb,
cc:dd]... | 128 | 128 | 429 | 5 | 122 | SummerVideoAnalysis/mmpose | mmpose/datasets/pipelines/bottom_up_transform.py | Python | JointsEncoder | JointsEncoder | 195 | 242 | 195 | 195 | 62ebba672099b40731566c6e95cea1e64f07de28 | bigcode/the-stack | train |
b6053334b1614084ab133169 | train | function | def _get_multi_scale_size(image,
input_size,
current_scale,
min_scale,
use_udp=False):
"""Get the size for multi-scale training.
Args:
image: Input image.
input_size (int): Size of the image ... | def _get_multi_scale_size(image,
input_size,
current_scale,
min_scale,
use_udp=False):
| """Get the size for multi-scale training.
Args:
image: Input image.
input_size (int): Size of the image input.
current_scale (float): Scale factor.
min_scale (float): Minimal scale.
use_udp (bool): To use unbiased data processing.
Paper ref: Huang et al. The ... | import cv2
import numpy as np
from mmpose.core.post_processing import (get_affine_transform, get_warp_matrix,
warp_affine_joints)
from mmpose.datasets.builder import PIPELINES
from .shared_transform import Compose
def _ceil_to_multiples_of(x, base=64):
"""Transform x to t... | 115 | 170 | 568 | 25 | 89 | SummerVideoAnalysis/mmpose | mmpose/datasets/pipelines/bottom_up_transform.py | Python | _get_multi_scale_size | _get_multi_scale_size | 15 | 68 | 15 | 19 | fb7f9277b625627d1663e3ed8ca34f5a55c36470 | bigcode/the-stack | train |
6368a436a69f43f9e10aced2 | train | function | def MPO_ham_bilinear_biquadratic(L=None, theta=0, *, S=1 / 2, cyclic=False,
compress=True, **mpo_opts):
""" Hamiltonian of one-dimensional bilinear biquadratic chain in MPO form,
see PhysRevB.93.184428.
Parameters
----------
L : int
The number of sites.
... | def MPO_ham_bilinear_biquadratic(L=None, theta=0, *, S=1 / 2, cyclic=False,
compress=True, **mpo_opts):
| """ Hamiltonian of one-dimensional bilinear biquadratic chain in MPO form,
see PhysRevB.93.184428.
Parameters
----------
L : int
The number of sites.
theta : float or (float, float), optional
The parameter for linear and non-linear term of interaction strength,
defaults ... | H += np.sin(theta), YY, ZZ
H += np.sin(theta), ZZ, XX
H += np.sin(theta), ZZ, YY
H += np.sin(theta), ZZ, ZZ
return H
def MPO_ham_bilinear_biquadratic(L=None, theta=0, *, S=1 / 2, cyclic=False,
compress=True, **mpo_opts):
| 85 | 85 | 286 | 38 | 46 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | MPO_ham_bilinear_biquadratic | MPO_ham_bilinear_biquadratic | 1,871 | 1,899 | 1,871 | 1,872 | 54f920e64b80c36b9f2964d02750cdefd0877456 | bigcode/the-stack | train |
f64214fbf99e909007a4170f | train | function | @functools.lru_cache(128)
def classical_ising_H_matrix(beta, h=0.0):
"""The magnetic field term for the classical ising model.
"""
H = np.array([math.exp(-beta * h), math.exp(beta * h)])
make_immutable(H)
return H
| @functools.lru_cache(128)
def classical_ising_H_matrix(beta, h=0.0):
| """The magnetic field term for the classical ising model.
"""
H = np.array([math.exp(-beta * h), math.exp(beta * h)])
make_immutable(H)
return H
| [[math.exp(j * beta), math.exp(-j * beta)],
[math.exp(-j * beta), math.exp(j * beta)]])
make_immutable(S)
return S
@functools.lru_cache(128)
def classical_ising_H_matrix(beta, h=0.0):
| 64 | 64 | 68 | 24 | 39 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | classical_ising_H_matrix | classical_ising_H_matrix | 298 | 304 | 298 | 299 | 6a951bc510fa53cc3d5dd2a5236cc78c9bdfb1e9 | bigcode/the-stack | train |
89bc520ca3182240bb74fb4d | train | class | class SpinHam1D:
"""Class for easily building custom spin hamiltonians in MPO or LocalHam1D
form. Currently limited to nearest neighbour interactions (and single site
terms). It is possible to set 'default' translationally invariant terms,
but also terms acting on specific sites only (which take precede... | class SpinHam1D:
| """Class for easily building custom spin hamiltonians in MPO or LocalHam1D
form. Currently limited to nearest neighbour interactions (and single site
terms). It is possible to set 'default' translationally invariant terms,
but also terms acting on specific sites only (which take precedence).
It is a... | :-1, 0, :, :]
HR = H
else:
HL = H[-1, :, :, :]
HR = H[:, 0, :, :]
if which == 'L':
return HL
elif which == 'R':
return HR
elif which == 'A':
return HL, H, HR
class _TermAdder:
"""Simple class to allow ``SpinHam1D`` syntax like
``builder[i, j] +=... | 256 | 256 | 2,451 | 6 | 249 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | SpinHam1D | SpinHam1D | 1,161 | 1,458 | 1,161 | 1,161 | 35b4a9c0d07c4e0406f54a855601c1d85fa7b643 | bigcode/the-stack | train |
096e5fec0411fabdfcd0cf35 | train | function | def _ham_ising(j=1.0, bx=0.0, *, S=1 / 2, cyclic=False):
H = SpinHam1D(S=1 / 2, cyclic=cyclic)
H += j, 'Z', 'Z'
H -= bx, 'X'
return H
| def _ham_ising(j=1.0, bx=0.0, *, S=1 / 2, cyclic=False):
| H = SpinHam1D(S=1 / 2, cyclic=cyclic)
H += j, 'Z', 'Z'
H -= bx, 'X'
return H
| ,
cyclic=self.cyclic, **local_ham_1d_opts)
SpinHam = deprecated(SpinHam1D, 'SpinHam', 'SpinHam1D')
def _ham_ising(j=1.0, bx=0.0, *, S=1 / 2, cyclic=False):
| 64 | 64 | 70 | 28 | 36 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | _ham_ising | _ham_ising | 1,464 | 1,468 | 1,464 | 1,464 | 7b077b322c6ab0202a29f05205c5bf42259a19fb | bigcode/the-stack | train |
f0bb26c08305ff57ea8a1eef | train | function | def MPS_product_state(arrays, cyclic=False, **mps_opts):
"""Generate a product state in MatrixProductState form, i,e,
with bond dimension 1, from single site vectors described by ``arrays``.
"""
cyc_dim = (1,) if cyclic else ()
def gen_array_shapes():
yield (*cyc_dim, 1, -1)
for _ i... | def MPS_product_state(arrays, cyclic=False, **mps_opts):
| """Generate a product state in MatrixProductState form, i,e,
with bond dimension 1, from single site vectors described by ``arrays``.
"""
cyc_dim = (1,) if cyclic else ()
def gen_array_shapes():
yield (*cyc_dim, 1, -1)
for _ in range(len(arrays) - 2):
yield (1, 1, -1)
... | ize(normalize=True)
elif normalize == 'right':
rmps.left_canonize(normalize=True)
elif normalize:
rmps /= (rmps.H @ rmps)**0.5
return rmps
def MPS_product_state(arrays, cyclic=False, **mps_opts):
| 64 | 64 | 164 | 16 | 47 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | MPS_product_state | MPS_product_state | 718 | 733 | 718 | 718 | 904255d72cc81b97a201bdc4e01c05d055b5ae83 | bigcode/the-stack | train |
311a6fc6bebfb5d6330f04ba | train | function | @functools.lru_cache(128)
def classical_ising_T_matrix(beta, h=0.0, directions='lrud'):
"""The single effective TN site for the classical ising model.
"""
arrays = (
[classical_ising_sqrtS_matrix(beta)] * len(directions) +
[classical_ising_H_matrix(beta, h)]
)
lhs = ",".join(f'i{x}' ... | @functools.lru_cache(128)
def classical_ising_T_matrix(beta, h=0.0, directions='lrud'):
| """The single effective TN site for the classical ising model.
"""
arrays = (
[classical_ising_sqrtS_matrix(beta)] * len(directions) +
[classical_ising_H_matrix(beta, h)]
)
lhs = ",".join(f'i{x}' for x in directions)
eq = lhs + ",i->" + directions
return oe.contract(eq, *arra... | inh(beta)**0.5]]
) / 2**0.5
make_immutable(S_1_2)
return S_1_2
@functools.lru_cache(128)
def classical_ising_T_matrix(beta, h=0.0, directions='lrud'):
| 64 | 64 | 117 | 29 | 34 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | classical_ising_T_matrix | classical_ising_T_matrix | 321 | 331 | 321 | 322 | 5da1f599ffc1446135a00aa40f415134404ca081 | bigcode/the-stack | train |
45e36c64c5593254995621c5 | train | function | @random_seed_fn
def MPS_rand_computational_state(L, dtype='float64', **mps_opts):
"""Generate a random computation basis state, like '01101001010'.
Parameters
----------
L : int
The number of qubits.
seed : int, optional
The seed to use.
dtype : {float, complex} or numpy dtype, ... | @random_seed_fn
def MPS_rand_computational_state(L, dtype='float64', **mps_opts):
| """Generate a random computation basis state, like '01101001010'.
Parameters
----------
L : int
The number of qubits.
seed : int, optional
The seed to use.
dtype : {float, complex} or numpy dtype, optional
Data type of the tensor network.
mps_opts
Supplied to... | astype(dtype)
yield np.array([[0., 1.],
[1., 0.]]).astype(dtype)
return MatrixProductState(gen_arrays(), **mps_opts)
@random_seed_fn
def MPS_rand_computational_state(L, dtype='float64', **mps_opts):
| 64 | 64 | 157 | 25 | 39 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | MPS_rand_computational_state | MPS_rand_computational_state | 840 | 856 | 840 | 841 | bdb1b6c0e4f1893c46810619626b4bb7f75dcb52 | bigcode/the-stack | train |
5c0f56f77c40aee5a7c4dde8 | train | function | def MPO_zeros(L, phys_dim=2, dtype='float64', cyclic=False, **mpo_opts):
"""Generate a zeros MPO of size ``L``.
Parameters
----------
L : int
The number of sites.
phys_dim : int, optional
The physical (site) dimensions, defaults to 2.
dtype : {float, complex} or numpy dtype, opt... | def MPO_zeros(L, phys_dim=2, dtype='float64', cyclic=False, **mpo_opts):
| """Generate a zeros MPO of size ``L``.
Parameters
----------
L : int
The number of sites.
phys_dim : int, optional
The physical (site) dimensions, defaults to 2.
dtype : {float, complex} or numpy dtype, optional
Data type of the tensor network.
cyclic : bool, optiona... | =mpo.dtype,
site_tag_id=mpo.site_tag_id, cyclic=mpo.cyclic,
upper_ind_id=mpo.upper_ind_id,
lower_ind_id=mpo.lower_ind_id, **mpo_opts)
def MPO_zeros(L, phys_dim=2, dtype='float64', cyclic=False, **mpo_opts):
| 74 | 74 | 248 | 24 | 50 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | MPO_zeros | MPO_zeros | 945 | 970 | 945 | 945 | c27fe1fea4dc727108f3968e936fb0c3c55e1148 | bigcode/the-stack | train |
ba681da0987e38897b27323b | train | function | @functools.lru_cache(128)
def classical_ising_sqrtS_matrix(beta):
"""The sqrt factorized interaction term for the classical ising model.
"""
S_1_2 = np.array(
[[math.cosh(beta)**0.5 + math.sinh(beta)**0.5,
math.cosh(beta)**0.5 - math.sinh(beta)**0.5],
[math.cosh(beta)**0.5 - math.... | @functools.lru_cache(128)
def classical_ising_sqrtS_matrix(beta):
| """The sqrt factorized interaction term for the classical ising model.
"""
S_1_2 = np.array(
[[math.cosh(beta)**0.5 + math.sinh(beta)**0.5,
math.cosh(beta)**0.5 - math.sinh(beta)**0.5],
[math.cosh(beta)**0.5 - math.sinh(beta)**0.5,
math.cosh(beta)**0.5 + math.sinh(beta)*... | """The magnetic field term for the classical ising model.
"""
H = np.array([math.exp(-beta * h), math.exp(beta * h)])
make_immutable(H)
return H
@functools.lru_cache(128)
def classical_ising_sqrtS_matrix(beta):
| 64 | 64 | 153 | 20 | 43 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | classical_ising_sqrtS_matrix | classical_ising_sqrtS_matrix | 307 | 318 | 307 | 308 | 6e33d3317aa9772d0a8364ac99d46e40864ed03d | bigcode/the-stack | train |
a4a2cbaf3a71f97c88b374fd | train | function | def TN_rand_reg(
n,
reg,
D,
phys_dim=None,
seed=None,
dtype='float64',
site_tag_id='I{}',
site_ind_id='k{}',
):
"""Create a random regular tensor network.
Parameters
----------
n : int
The number of tensors.
reg : int
The degree of the tensor network ... | def TN_rand_reg(
n,
reg,
D,
phys_dim=None,
seed=None,
dtype='float64',
site_tag_id='I{}',
site_ind_id='k{}',
):
| """Create a random regular tensor network.
Parameters
----------
n : int
The number of tensors.
reg : int
The degree of the tensor network (how many tensors each tensor
connects to).
D : int
The bond dimension connecting tensors.
phys_dim : int, optional
... | ', 'complex64'}, optional
The underlying data type - can only be complex.
Returns
-------
Tensor
"""
data = rand_phase(shape, dtype=dtype)
return Tensor(data=data, inds=inds, tags=tags)
def TN_rand_reg(
n,
reg,
D,
phys_dim=None,
seed=None,
dtype='float64',
si... | 99 | 99 | 331 | 46 | 53 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | TN_rand_reg | TN_rand_reg | 79 | 130 | 79 | 88 | 4afa19157577b202a40ac9a71e8ccb230a176aa6 | bigcode/the-stack | train |
eb5e0e1782043da8836a0156 | train | function | @functools.lru_cache(128)
def classical_ising_T2d_matrix(beta, directions='lrud', h=0.0):
"""The single effective TN site for the 2D classical ising model.
"""
return classical_ising_T_matrix(beta, h, directions)
| @functools.lru_cache(128)
def classical_ising_T2d_matrix(beta, directions='lrud', h=0.0):
| """The single effective TN site for the 2D classical ising model.
"""
return classical_ising_T_matrix(beta, h, directions)
| ",".join(f'i{x}' for x in directions)
eq = lhs + ",i->" + directions
return oe.contract(eq, *arrays)
@functools.lru_cache(128)
def classical_ising_T2d_matrix(beta, directions='lrud', h=0.0):
| 64 | 64 | 63 | 31 | 33 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | classical_ising_T2d_matrix | classical_ising_T2d_matrix | 334 | 338 | 334 | 335 | d4858de78b08acc6e6e6e02778345a07869b09bf | bigcode/the-stack | train |
38c4c0788d1e1d7ed8601cd1 | train | function | def HTN3D_classical_ising_partition_function(
Lx,
Ly,
Lz,
beta,
h=0.0,
j=1.0,
cyclic=False,
ind_id='s{},{},{}',
):
"""Hyper tensor network representation of the 3D classical ising model
partition function. The indices will be shared by 6 or 7 tensors depending
on whether ``h`... | def HTN3D_classical_ising_partition_function(
Lx,
Ly,
Lz,
beta,
h=0.0,
j=1.0,
cyclic=False,
ind_id='s{},{},{}',
):
| """Hyper tensor network representation of the 3D classical ising model
partition function. The indices will be shared by 6 or 7 tensors depending
on whether ``h`` is non-zero. As opposed to the 'normal' tensor network,
here each classical spin is still a single index, which is easier to
contract exa... | - 1 or cyclic_x:
inds = ind_id.format(i, j), ind_id.format((i + 1) % Lx, j)
ts.append(Tensor(S, inds=inds))
if j < Ly - 1 or cyclic_y:
inds = ind_id.format(i, j), ind_id.format(i, (j + 1) % Ly)
ts.append(Tensor(S, inds=inds))
if h != 0.0:
ts... | 177 | 177 | 590 | 55 | 122 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | HTN3D_classical_ising_partition_function | HTN3D_classical_ising_partition_function | 417 | 490 | 417 | 426 | 525b84ac9ce464925587733e7a646bf97aec176c | bigcode/the-stack | train |
48241d0c109d20101a4d9996 | train | function | def ham_2d_j1j2(Lx, Ly, j1=1.0, j2=0.5, bz=0.0, **local_ham_2d_opts):
r"""Heisenberg Hamiltonian in
:class:`~quimb.tensor.tensor_2d_tebd.LocalHam2D`. form.
.. math::
H_\mathrm{Heis} =
\sum_{<ij>} (
J_{1,X} \sigma^X_i \sigma^X_{j} +
J_{1,Y} \sigma^Y_i \sigma^Y_{j} +
... | def ham_2d_j1j2(Lx, Ly, j1=1.0, j2=0.5, bz=0.0, **local_ham_2d_opts):
| r"""Heisenberg Hamiltonian in
:class:`~quimb.tensor.tensor_2d_tebd.LocalHam2D`. form.
.. math::
H_\mathrm{Heis} =
\sum_{<ij>} (
J_{1,X} \sigma^X_i \sigma^X_{j} +
J_{1,Y} \sigma^Y_i \sigma^Y_{j} +
J_{1,Z} \sigma^Z_i \sigma^Z_{j}
)
+
... | iferromagnetic.
bz : float, optional
The Z-magnetic field strength.
local_ham_2d_opts
Supplied to :class:`~quimb.tensor.tensor_2d_tebd.LocalHam2D`.
Returns
-------
LocalHam2D
"""
H2 = ham_heis(2, j=j, cyclic=False)
if bz == 0.0:
H1 = None
else:
H1 = -... | 186 | 186 | 622 | 43 | 143 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | ham_2d_j1j2 | ham_2d_j1j2 | 2,131 | 2,193 | 2,131 | 2,131 | 392486f5b8148d09bb4e268a47d72a5f3f5e8693 | bigcode/the-stack | train |
cdd8de489ce3f703d597c189 | train | function | def MPO_ham_mbl(L, dh, j=1.0, seed=None, S=1 / 2, *, cyclic=False,
dh_dist='s', dh_dim=1, beta=None, **mpo_opts):
r"""The many-body-localized spin hamiltonian in MPO form.
.. math::
H_\mathrm{MBL} =
\sum_{i} (
J_X \sigma^X_i \sigma^X_{i + 1} +
J_Y \sigma... | def MPO_ham_mbl(L, dh, j=1.0, seed=None, S=1 / 2, *, cyclic=False,
dh_dist='s', dh_dim=1, beta=None, **mpo_opts):
| r"""The many-body-localized spin hamiltonian in MPO form.
.. math::
H_\mathrm{MBL} =
\sum_{i} (
J_X \sigma^X_i \sigma^X_{i + 1} +
J_Y \sigma^Y_i \sigma^Y_{i + 1} +
J_Z \sigma^Z_i \sigma^Z_{i + 1}
)
- \sum_{i} h_i \sigma^Z_i
Note the ... | = _gen_mbl_random_factors(L, dh, dh_dim, dh_dist, seed, beta)
# generate noise, potentially in all directions, each with own strength
for i in range(L):
dh_r_xyzs = zip(dhds, rs[:, i], 'XYZ')
for dh, r, xyz in dh_r_xyzs:
H[i] += dh * r, xyz
return H
def MPO_ham_mbl(L, dh, j=1.... | 139 | 139 | 465 | 49 | 89 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | MPO_ham_mbl | MPO_ham_mbl | 1,951 | 1,996 | 1,951 | 1,952 | 801d43c36963ad62fc22923c517720c9df81245f | bigcode/the-stack | train |
38107f99c519d384968bb6b3 | train | function | def ham_1d_bilinear_biquadratic(L=None, theta=0, *, S=1 / 2,
cyclic=False, **local_ham_1d_opts):
""" Hamiltonian of one-dimensional bilinear biquadratic chain in LocalHam1D
form, see PhysRevB.93.184428.
Parameters
----------
L : int
The number of sites.
t... | def ham_1d_bilinear_biquadratic(L=None, theta=0, *, S=1 / 2,
cyclic=False, **local_ham_1d_opts):
| """ Hamiltonian of one-dimensional bilinear biquadratic chain in LocalHam1D
form, see PhysRevB.93.184428.
Parameters
----------
L : int
The number of sites.
theta : float or (float, float), optional
The parameter for linear and non-linear term of interaction strength,
de... | )
if compress is True:
H_mpo.compress(cutoff=1e-12, cutoff_mode='rel' if cyclic else 'sum2')
return H_mpo
def ham_1d_bilinear_biquadratic(L=None, theta=0, *, S=1 / 2,
cyclic=False, **local_ham_1d_opts):
| 79 | 79 | 266 | 40 | 38 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | ham_1d_bilinear_biquadratic | ham_1d_bilinear_biquadratic | 1,902 | 1,927 | 1,902 | 1,903 | a9598866844baa77df2983d0bce84f55bfd0f722 | bigcode/the-stack | train |
a1bdff245150c8aa2a756478 | train | function | def MPO_ham_heis(L, j=1.0, bz=0.0, *, S=1 / 2, cyclic=False, **mpo_opts):
r"""Heisenberg Hamiltonian in MPO form.
.. math::
H_\mathrm{Heis} =
\sum_{i} (
J_X \sigma^X_i \sigma^X_{i + 1} +
J_Y \sigma^Y_i \sigma^Y_{i + 1} +
J_Z \sigma^Z_i \sigma^Z_{i + 1}
... | def MPO_ham_heis(L, j=1.0, bz=0.0, *, S=1 / 2, cyclic=False, **mpo_opts):
| r"""Heisenberg Hamiltonian in MPO form.
.. math::
H_\mathrm{Heis} =
\sum_{i} (
J_X \sigma^X_i \sigma^X_{i + 1} +
J_Y \sigma^Y_i \sigma^Y_{i + 1} +
J_Z \sigma^Z_i \sigma^Z_{i + 1}
)
- B_Z \sum_{i} \sigma^Z_i
Note the default conventio... | / 2, '+', '-'
H += jx / 2, '-', '+'
else:
H += jx, 'X', 'X'
H += jy, 'Y', 'Y'
H += jz, 'Z', 'Z'
H -= bz, 'Z'
return H
def MPO_ham_heis(L, j=1.0, bz=0.0, *, S=1 / 2, cyclic=False, **mpo_opts):
| 106 | 106 | 355 | 36 | 69 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | MPO_ham_heis | MPO_ham_heis | 1,674 | 1,711 | 1,674 | 1,674 | 097d23902eed392d86b58d503e5f789024b9ada4 | bigcode/the-stack | train |
e8fba09e7597e1bc77c55c07 | train | function | @random_seed_fn
def rand_tensor(shape, inds, tags=None, dtype='float64', left_inds=None):
"""Generate a random tensor with specified shape and inds.
Parameters
----------
shape : sequence of int
Size of each dimension.
inds : sequence of str
Names of each dimension.
tags : seque... | @random_seed_fn
def rand_tensor(shape, inds, tags=None, dtype='float64', left_inds=None):
| """Generate a random tensor with specified shape and inds.
Parameters
----------
shape : sequence of int
Size of each dimension.
inds : sequence of str
Names of each dimension.
tags : sequence of str
Labels to tag this tensor with.
dtype : {'float64', 'complex128', '... | import gen_2d_bonds, TensorNetwork2D
from .tensor_1d_tebd import LocalHam1D
from .tensor_2d_tebd import LocalHam2D
@random_seed_fn
def rand_tensor(shape, inds, tags=None, dtype='float64', left_inds=None):
| 65 | 65 | 218 | 24 | 40 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | rand_tensor | rand_tensor | 26 | 51 | 26 | 27 | 927471938bf7f10560034f53180cc944120d9528 | bigcode/the-stack | train |
e1a881df5e3854d61e706beb | train | function | def ham_2d_ising(Lx, Ly, j=1.0, bx=0.0, **local_ham_2d_opts):
r"""Ising Hamiltonian in
:class:`~quimb.tensor.tensor_2d_tebd.LocalHam2D` form.
.. math::
H_\mathrm{Ising} =
J \sum_{<ij>} \sigma^Z_i \sigma^Z_{j} -
B_x \sum_{i} \sigma^X_i
for nearest neighbors :math:`<ij>`. Note t... | def ham_2d_ising(Lx, Ly, j=1.0, bx=0.0, **local_ham_2d_opts):
| r"""Ising Hamiltonian in
:class:`~quimb.tensor.tensor_2d_tebd.LocalHam2D` form.
.. math::
H_\mathrm{Ising} =
J \sum_{<ij>} \sigma^Z_i \sigma^Z_{j} -
B_x \sum_{i} \sigma^X_i
for nearest neighbors :math:`<ij>`. Note the default convention of
antiferromagnetic interactions an... | dh_dist=dh_dist, dh_dim=dh_dim, beta=beta)
return H.build_local_ham(L, **local_ham_1d_opts)
NNI_ham_mbl = deprecated(ham_1d_mbl, 'NNI_ham_mbl', 'ham_1d_mbl')
def ham_2d_ising(Lx, Ly, j=1.0, bx=0.0, **local_ham_2d_opts):
| 99 | 99 | 333 | 33 | 66 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | ham_2d_ising | ham_2d_ising | 2,051 | 2,086 | 2,051 | 2,051 | 0a08cf58a91c2b0725ab2d6d1ec47b78129bc141 | bigcode/the-stack | train |
5e261fe6d1dc5664fb934967 | train | function | @functools.lru_cache(128)
def classical_ising_T3d_matrix(beta, directions='lrudab', h=0.0):
"""The single effective TN site for the 3D classical ising model.
"""
return classical_ising_T_matrix(beta, h, directions)
| @functools.lru_cache(128)
def classical_ising_T3d_matrix(beta, directions='lrudab', h=0.0):
| """The single effective TN site for the 3D classical ising model.
"""
return classical_ising_T_matrix(beta, h, directions)
| """The single effective TN site for the 2D classical ising model.
"""
return classical_ising_T_matrix(beta, h, directions)
@functools.lru_cache(128)
def classical_ising_T3d_matrix(beta, directions='lrudab', h=0.0):
| 64 | 64 | 64 | 32 | 32 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | classical_ising_T3d_matrix | classical_ising_T3d_matrix | 341 | 345 | 341 | 342 | 1e1d6ab9d861edc5a3210890e1def47f5919577c | bigcode/the-stack | train |
59a20f4f0d832f5fb918fc75 | train | function | def _ham_XY(j=1.0, bz=0.0, *, S=1 / 2, cyclic=False):
H = SpinHam1D(S=S, cyclic=cyclic)
try:
jx, jy = j
except (TypeError, ValueError):
jx = jy = j
if jx == jy:
# easy way to enforce realness
H += jx / 2, '+', '-'
H += jx / 2, '-', '+'
else:
H += jx,... | def _ham_XY(j=1.0, bz=0.0, *, S=1 / 2, cyclic=False):
| H = SpinHam1D(S=S, cyclic=cyclic)
try:
jx, jy = j
except (TypeError, ValueError):
jx = jy = j
if jx == jy:
# easy way to enforce realness
H += jx / 2, '+', '-'
H += jx / 2, '-', '+'
else:
H += jx, 'X', 'X'
H += jy, 'Y', 'Y'
H -= bz, 'Z'
... | 1d_opts)
NNI_ham_ising = deprecated(ham_1d_ising, 'NNI_ham_ising', 'ham_1d_ising')
def _ham_XY(j=1.0, bz=0.0, *, S=1 / 2, cyclic=False):
| 64 | 64 | 150 | 28 | 36 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | _ham_XY | _ham_XY | 1,548 | 1,566 | 1,548 | 1,548 | c426a3de527c8fa1f61f14d8537c3044fc4b6f2c | bigcode/the-stack | train |
6a9d9376c153b265baaa066e | train | function | def ham_1d_XY(L=None, j=1.0, bz=0.0, *, S=1 / 2,
cyclic=False, **local_ham_1d_opts):
r"""XY-Hamiltonian in
:class:`~quimb.tensor.tensor_1d_tebd.LocalHam1D` form.
.. math::
H_\mathrm{XY} =
\sum_{i} (
J_X \sigma^X_i \sigma^X_{i + 1} +
J_Y \sigma^Y_i \sig... | def ham_1d_XY(L=None, j=1.0, bz=0.0, *, S=1 / 2,
cyclic=False, **local_ham_1d_opts):
| r"""XY-Hamiltonian in
:class:`~quimb.tensor.tensor_1d_tebd.LocalHam1D` form.
.. math::
H_\mathrm{XY} =
\sum_{i} (
J_X \sigma^X_i \sigma^X_{i + 1} +
J_Y \sigma^Y_i \sigma^Y_{i + 1}
)
- B_Z \sum_{i} \sigma^Z_i
Note the default convention of an... | _opts
Supplied to :class:`~quimb.tensor.tensor_1d.MatrixProductOperator`.
Returns
-------
MatrixProductOperator
"""
H = _ham_XY(j=j, bz=bz, S=S, cyclic=cyclic)
return H.build_mpo(L, **mpo_opts)
def ham_1d_XY(L=None, j=1.0, bz=0.0, *, S=1 / 2,
cyclic=False, **local_ham_1d_o... | 111 | 111 | 370 | 43 | 68 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | ham_1d_XY | ham_1d_XY | 1,608 | 1,646 | 1,608 | 1,609 | 1a3d861595ce6955d96b89d50e5a7dead995c9b6 | bigcode/the-stack | train |
60b61210559e592a33a7b606 | train | function | @random_seed_fn
def MPS_rand_state(L, bond_dim, phys_dim=2, normalize=True, cyclic=False,
dtype='float64', trans_invar=False, **mps_opts):
"""Generate a random matrix product state.
Parameters
----------
L : int
The number of sites.
bond_dim : int
The bond dimensi... | @random_seed_fn
def MPS_rand_state(L, bond_dim, phys_dim=2, normalize=True, cyclic=False,
dtype='float64', trans_invar=False, **mps_opts):
| """Generate a random matrix product state.
Parameters
----------
L : int
The number of sites.
bond_dim : int
The bond dimension.
phys_dim : int, optional
The physical (site) dimensions, defaults to 2.
normalize : bool, optional
Whether to normalize the state.... | (bonds[((i - 1) % Lx, j, k), (i, j, k)])
ts.append(Tensor(
data=classical_ising_T3d_matrix(beta, directions, h=h),
inds=inds,
tags=[site_tag_id.format(i, j, k)]))
tn = TensorNetwork(ts)
return tn
# ------------------------------------------------------------------... | 134 | 134 | 448 | 42 | 92 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | MPS_rand_state | MPS_rand_state | 659 | 715 | 659 | 661 | dc1e59d18ee88d0cdcda20754b5be69cddca272c | bigcode/the-stack | train |
1e8ce997f956da8551139147 | train | function | def MPS_ghz_state(L, dtype='float64', **mps_opts):
"""Build the chi=2 OBC MPS representation of the GHZ state.
Parameters
----------
L : int
Number of qubits.
dtype : {'float64', 'complex128', 'float32', 'complex64'}, optional
The underlying data type.
mps_opts
Supplied ... | def MPS_ghz_state(L, dtype='float64', **mps_opts):
| """Build the chi=2 OBC MPS representation of the GHZ state.
Parameters
----------
L : int
Number of qubits.
dtype : {'float64', 'complex128', 'float32', 'complex64'}, optional
The underlying data type.
mps_opts
Supplied to :class:`~quimb.tensor.tensor_1d.MatrixProductSta... | L % 2 == 1) * "0"
if down_first:
binary_str = "1" + binary_str[:-1]
return MPS_computational_state(binary_str, dtype=dtype, **mps_opts)
def MPS_ghz_state(L, dtype='float64', **mps_opts):
| 69 | 69 | 231 | 19 | 50 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | MPS_ghz_state | MPS_ghz_state | 782 | 808 | 782 | 782 | 19fb195cc25c9c691ed5cdb538cb66ede72de703 | bigcode/the-stack | train |
792fcbc2db0fdf6203e6ffb9 | train | function | @random_seed_fn
def MPO_rand(L, bond_dim, phys_dim=2, normalize=True, cyclic=False,
herm=False, dtype='float64', **mpo_opts):
"""Generate a random matrix product state.
Parameters
----------
L : int
The number of sites.
bond_dim : int
The bond dimension.
phys_dim : ... | @random_seed_fn
def MPO_rand(L, bond_dim, phys_dim=2, normalize=True, cyclic=False,
herm=False, dtype='float64', **mpo_opts):
| """Generate a random matrix product state.
Parameters
----------
L : int
The number of sites.
bond_dim : int
The bond dimension.
phys_dim : int, optional
The physical (site) dimensions, defaults to 2.
normalize : bool, optional
Whether to normalize the operat... | same physical index and
inds/tags as ``mpo``.
"""
return MPO_zeros(L=mpo.L, phys_dim=mpo.phys_dim(),
dtype=mpo.dtype, site_tag_id=mpo.site_tag_id,
upper_ind_id=mpo.upper_ind_id, cyclic=mpo.cyclic,
lower_ind_id=mpo.lower_ind_id, **mpo_opts)
@ran... | 126 | 126 | 420 | 38 | 88 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | MPO_rand | MPO_rand | 983 | 1,029 | 983 | 985 | faa0f899148c16d27a4e41e0a6106479cffa7e9c | bigcode/the-stack | train |
dcc89bdd08012cec72f4d5e3 | train | function | def MPO_zeros_like(mpo, **mpo_opts):
"""Return a zeros matrix operator with the same physical index and
inds/tags as ``mpo``.
"""
return MPO_zeros(L=mpo.L, phys_dim=mpo.phys_dim(),
dtype=mpo.dtype, site_tag_id=mpo.site_tag_id,
upper_ind_id=mpo.upper_ind_id, cycl... | def MPO_zeros_like(mpo, **mpo_opts):
| """Return a zeros matrix operator with the same physical index and
inds/tags as ``mpo``.
"""
return MPO_zeros(L=mpo.L, phys_dim=mpo.phys_dim(),
dtype=mpo.dtype, site_tag_id=mpo.site_tag_id,
upper_ind_id=mpo.upper_ind_id, cyclic=mpo.cyclic,
l... | ((1, 1, phys_dim, phys_dim), dtype=dtype)
yield np.zeros((1, *cyc_dim, phys_dim, phys_dim), dtype=dtype)
return MatrixProductOperator(gen_arrays(), **mpo_opts)
def MPO_zeros_like(mpo, **mpo_opts):
| 64 | 64 | 110 | 13 | 51 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | MPO_zeros_like | MPO_zeros_like | 973 | 980 | 973 | 973 | bce79fa3dcb7b9ddc8b7fa21cbd39b2dc1ae26d9 | bigcode/the-stack | train |
09f02968e381ff44e4d0985d | train | function | @random_seed_fn
def rand_phased(shape, inds, tags=None, dtype=complex):
"""Generate a random tensor with specified shape and inds, and randomly
'phased' (distributed on the unit circle) data, such that
``T.H @ T == T.norm()**2 == T.size``.
Parameters
----------
shape : sequence of int
S... | @random_seed_fn
def rand_phased(shape, inds, tags=None, dtype=complex):
| """Generate a random tensor with specified shape and inds, and randomly
'phased' (distributed on the unit circle) data, such that
``T.H @ T == T.norm()**2 == T.size``.
Parameters
----------
shape : sequence of int
Size of each dimension.
inds : sequence of str
Names of each ... | ) level.
Returns
-------
Tensor
"""
data = randn(shape, dtype=dtype)
return Tensor(data=data, inds=inds, tags=tags, left_inds=left_inds)
@random_seed_fn
def rand_phased(shape, inds, tags=None, dtype=complex):
| 64 | 64 | 173 | 20 | 44 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | rand_phased | rand_phased | 54 | 76 | 54 | 55 | f632f120b9a76bd7967bb1058027534110f28b23 | bigcode/the-stack | train |
be8834c35c2eee74746478ea | train | function | def MPO_identity(L, phys_dim=2, dtype='float64', cyclic=False, **mpo_opts):
"""Generate an identity MPO of size ``L``.
Parameters
----------
L : int
The number of sites.
phys_dim : int, optional
The physical (site) dimensions, defaults to 2.
dtype : {float, complex} or numpy dty... | def MPO_identity(L, phys_dim=2, dtype='float64', cyclic=False, **mpo_opts):
| """Generate an identity MPO of size ``L``.
Parameters
----------
L : int
The number of sites.
phys_dim : int, optional
The physical (site) dimensions, defaults to 2.
dtype : {float, complex} or numpy dtype, optional
Data type of the tensor network.
cyclic : bool, opt... | =dtype) for _ in range(L)]
psi = MPS_product_state(arrays, **mps_opts)
if squeeze:
psi.squeeze_()
return psi
# --------------------------------------------------------------------------- #
# MPOs #
# ---------------------------... | 74 | 74 | 248 | 23 | 51 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | MPO_identity | MPO_identity | 906 | 932 | 906 | 906 | bb16c81901322f72466b8be9a1e0dcc296cf0bce | bigcode/the-stack | train |
db0743e860892903f59f6111 | train | function | def TN2D_classical_ising_partition_function(
Lx,
Ly,
beta,
h=0.0,
cyclic=False,
site_tag_id='I{},{}',
row_tag_id='ROW{}',
col_tag_id='COL{}',
):
"""The tensor network representation of the 2D classical ising model
partition function.
Parameters
----------
Lx : int
... | def TN2D_classical_ising_partition_function(
Lx,
Ly,
beta,
h=0.0,
cyclic=False,
site_tag_id='I{},{}',
row_tag_id='ROW{}',
col_tag_id='COL{}',
):
| """The tensor network representation of the 2D classical ising model
partition function.
Parameters
----------
Lx : int
Length of side x.
Ly : int
Length of side y.
beta : float
The inverse temperature.
h : float, optional
The magnetic field strength.
... | j, k), ind_id.format(i, (j + 1) % Ly, k)
ts.append(Tensor(S, inds=inds))
if k < Lz - 1 or cyclic_z:
inds = ind_id.format(i, j, k), ind_id.format(i, j, (k + 1) % Lz)
ts.append(Tensor(S, inds=inds))
if h != 0.0:
ts.append(Tensor(H, inds=(ind_id.format(i, ... | 176 | 176 | 587 | 58 | 118 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | TN2D_classical_ising_partition_function | TN2D_classical_ising_partition_function | 493 | 574 | 493 | 502 | 8bf18ea14f722cfac451676a42f8b99505e2c384 | bigcode/the-stack | train |
0f44a941b6180e033db7fd25 | train | function | @random_seed_fn
def TN3D_rand(
Lx,
Ly,
Lz,
D,
cyclic=False,
site_tag_id='I{},{},{}',
dtype='float64',
):
"""A random scalar 3D lattice tensor network.
Parameters
----------
Lx : int
Length of side x.
Ly : int
Length of side y.
Lz : int
Length ... | @random_seed_fn
def TN3D_rand(
Lx,
Ly,
Lz,
D,
cyclic=False,
site_tag_id='I{},{},{}',
dtype='float64',
):
| """A random scalar 3D lattice tensor network.
Parameters
----------
Lx : int
Length of side x.
Ly : int
Length of side y.
Lz : int
Length of side z.
D : int
The bond dimension connecting sites.
cyclic : bool or (bool, bool, bool), optional
Whether... | - 1) % Lx, j), (i, j)])
ts.append(Tensor(
data=randn([D] * len(inds), dtype=dtype),
inds=inds,
tags=[site_tag_id.format(i, j),
row_tag_id.format(i),
col_tag_id.format(j)]))
tn = TensorNetwork(ts)
return tn.view_as_(
Tens... | 174 | 174 | 583 | 47 | 127 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | TN3D_rand | TN3D_rand | 213 | 284 | 213 | 222 | 1bea306a59795b6f85ab2fd0dc062491a1b57be6 | bigcode/the-stack | train |
09a9ae7eea36fa7ca8820c63 | train | function | def MPS_sampler(L, dtype=complex, squeeze=True, **mps_opts):
"""A product state for sampling tensor network traces. Seen as a vector it
has the required property that ``psi.H @ psi == d`` always for hilbert
space size ``d``.
"""
arrays = [rand_phase(2, dtype=dtype) for _ in range(L)]
psi = MPS_p... | def MPS_sampler(L, dtype=complex, squeeze=True, **mps_opts):
| """A product state for sampling tensor network traces. Seen as a vector it
has the required property that ``psi.H @ psi == d`` always for hilbert
space size ``d``.
"""
arrays = [rand_phase(2, dtype=dtype) for _ in range(L)]
psi = MPS_product_state(arrays, **mps_opts)
if squeeze:
psi.... | bond_dim, bond_dim, phys_dim), dtype=dtype)
yield np.zeros((bond_dim, *cyc_dim, phys_dim), dtype=dtype)
return MatrixProductState(gen_arrays(), **mps_opts)
def MPS_sampler(L, dtype=complex, squeeze=True, **mps_opts):
| 64 | 64 | 110 | 18 | 46 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | MPS_sampler | MPS_sampler | 890 | 899 | 890 | 890 | 8b0466c5e929e1bf70afb803dbdbcd240114cad0 | bigcode/the-stack | train |
3478d815688525569688d53a | train | function | @random_seed_fn
def TN2D_rand(
Lx,
Ly,
D,
cyclic=False,
site_tag_id='I{},{}',
row_tag_id='ROW{}',
col_tag_id='COL{}',
dtype='float64',
):
"""A random scalar 2D lattice tensor network.
Parameters
----------
Lx : int
Length of side x.
Ly : int
Length of... | @random_seed_fn
def TN2D_rand(
Lx,
Ly,
D,
cyclic=False,
site_tag_id='I{},{}',
row_tag_id='ROW{}',
col_tag_id='COL{}',
dtype='float64',
):
| """A random scalar 2D lattice tensor network.
Parameters
----------
Lx : int
Length of side x.
Ly : int
Length of side y.
D : int
The bond dimension connecting sites.
cyclic : bool or (bool, bool), optional
Whether to use periodic boundary conditions. X and Y... | nx.random_degree_sequence_graph([reg] * n, seed=None)
ts = []
for i in range(n):
t = Tensor(tags=site_tag_id.format(i))
if phys_dim is not None:
t.new_ind(site_ind_id.format(i), size=phys_dim)
ts.append(t)
for i, j in G.edges:
new_bond(ts[i], ts[j], size=D)
... | 168 | 168 | 562 | 57 | 110 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | TN2D_rand | TN2D_rand | 133 | 210 | 133 | 143 | 146e1200fc6b40bae2ce75db1c1cc33f201c3ed4 | bigcode/the-stack | train |
f1ec536633d4111aca4f0c71 | train | function | def MPS_neel_state(L, down_first=False, dtype='float64', **mps_opts):
"""Generate the neel state in Matrix Product State form.
Parameters
----------
L : int
The number of spins.
down_first : bool, optional
Whether to start with '1' (down) or '0' (up) first.
mps_opts
Supp... | def MPS_neel_state(L, down_first=False, dtype='float64', **mps_opts):
| """Generate the neel state in Matrix Product State form.
Parameters
----------
L : int
The number of spins.
down_first : bool, optional
Whether to start with '1' (down) or '0' (up) first.
mps_opts
Supplied to MatrixProductState constructor.
"""
binary_str = "01" ... | type),
}
def gen_arrays():
for s in binary:
yield array_map[str(s)]
return MPS_product_state(tuple(gen_arrays()), cyclic=cyclic, **mps_opts)
def MPS_neel_state(L, down_first=False, dtype='float64', **mps_opts):
| 64 | 64 | 161 | 22 | 42 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | MPS_neel_state | MPS_neel_state | 764 | 779 | 764 | 764 | 688a765b3df7a2ddeae3df2de2a6c3a76a0d7c3c | bigcode/the-stack | train |
a7d1a7144d72f3b7666c1d2e | train | class | class _TermAdder:
"""Simple class to allow ``SpinHam1D`` syntax like
``builder[i, j] += (1/2, 'Z', 'X')``. This object is temporarily created
by the getitem call, accumulates the new term, then has its the new
combined list of terms extracted in the setitem call.
"""
def __init__(self, terms, n... | class _TermAdder:
| """Simple class to allow ``SpinHam1D`` syntax like
``builder[i, j] += (1/2, 'Z', 'X')``. This object is temporarily created
by the getitem call, accumulates the new term, then has its the new
combined list of terms extracted in the setitem call.
"""
def __init__(self, terms, nsite):
sel... | :
HL = H[-1, :, :, :]
HR = H[:, 0, :, :]
if which == 'L':
return HL
elif which == 'R':
return HR
elif which == 'A':
return HL, H, HR
class _TermAdder:
| 64 | 64 | 176 | 5 | 58 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | _TermAdder | _TermAdder | 1,138 | 1,158 | 1,138 | 1,138 | 042c8184a4df0b9b9269e158d900150876840ddb | bigcode/the-stack | train |
55303a5d039f52f90237b870 | train | function | def _ham_bilinear_biquadratic(theta, *, S=1 / 2, cyclic=False):
H = SpinHam1D(S=S, cyclic=cyclic)
H += np.cos(theta), 'X', 'X'
H += np.cos(theta), 'Y', 'Y'
H += np.cos(theta), 'Z', 'Z'
XX = spin_operator('X', S=S) @ spin_operator('X', S=S)
YY = spin_operator('Y', S=S) @ spin_operator('Y', S=S)... | def _ham_bilinear_biquadratic(theta, *, S=1 / 2, cyclic=False):
| H = SpinHam1D(S=S, cyclic=cyclic)
H += np.cos(theta), 'X', 'X'
H += np.cos(theta), 'Y', 'Y'
H += np.cos(theta), 'Z', 'Z'
XX = spin_operator('X', S=S) @ spin_operator('X', S=S)
YY = spin_operator('Y', S=S) @ spin_operator('Y', S=S)
ZZ = spin_operator('Z', S=S) @ spin_operator('Z', S=S)
... | =cyclic, **local_ham_1d_opts)
NNI_ham_XXZ = deprecated(ham_1d_XXZ, 'NNI_ham_XXZ', 'ham_1d_XXZ')
def _ham_bilinear_biquadratic(theta, *, S=1 / 2, cyclic=False):
| 72 | 72 | 240 | 23 | 49 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | _ham_bilinear_biquadratic | _ham_bilinear_biquadratic | 1,847 | 1,868 | 1,847 | 1,847 | 0ccf2464c0923620ee0c74437c5aaaed3863dbcc | bigcode/the-stack | train |
d816314015ea96fc44ce6f63 | train | function | def HTN2D_classical_ising_partition_function(
Lx,
Ly,
beta,
h=0.0,
j=1.0,
ind_id='s{},{}',
cyclic=False,
):
"""Hyper tensor network representation of the 2D classical ising model
partition function. The indices will be shared by 4 or 5 tensors depending
on whether ``h`` is non-ze... | def HTN2D_classical_ising_partition_function(
Lx,
Ly,
beta,
h=0.0,
j=1.0,
ind_id='s{},{}',
cyclic=False,
):
| """Hyper tensor network representation of the 2D classical ising model
partition function. The indices will be shared by 4 or 5 tensors depending
on whether ``h`` is non-zero. As opposed to the 'normal' tensor network,
here each classical spin is still a single index, which is easier to
contract exa... | 0):
"""The single effective TN site for the 2D classical ising model.
"""
return classical_ising_T_matrix(beta, h, directions)
@functools.lru_cache(128)
def classical_ising_T3d_matrix(beta, directions='lrudab', h=0.0):
"""The single effective TN site for the 3D classical ising model.
"""
retur... | 147 | 147 | 491 | 49 | 98 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | HTN2D_classical_ising_partition_function | HTN2D_classical_ising_partition_function | 348 | 414 | 348 | 356 | ba4d09f503d4adef83b933f050c36e60db80fc58 | bigcode/the-stack | train |
8e557f5ff15f232ef474a5b7 | train | function | def MPO_ham_ising(L, j=1.0, bx=0.0, *, S=1 / 2, cyclic=False, **mpo_opts):
r"""Ising Hamiltonian in MPO form.
.. math::
H_\mathrm{Ising} =
J \sum_{i} \sigma^Z_i \sigma^Z_{i + 1} -
B_x \sum_{i} \sigma^X_i
Note the default convention of antiferromagnetic interactions and spin
op... | def MPO_ham_ising(L, j=1.0, bx=0.0, *, S=1 / 2, cyclic=False, **mpo_opts):
| r"""Ising Hamiltonian in MPO form.
.. math::
H_\mathrm{Ising} =
J \sum_{i} \sigma^Z_i \sigma^Z_{i + 1} -
B_x \sum_{i} \sigma^X_i
Note the default convention of antiferromagnetic interactions and spin
operators not Pauli matrices.
Parameters
----------
L : int
... | .0, *, S=1 / 2, cyclic=False):
H = SpinHam1D(S=1 / 2, cyclic=cyclic)
H += j, 'Z', 'Z'
H -= bx, 'X'
return H
def MPO_ham_ising(L, j=1.0, bx=0.0, *, S=1 / 2, cyclic=False, **mpo_opts):
| 92 | 92 | 308 | 36 | 55 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | MPO_ham_ising | MPO_ham_ising | 1,471 | 1,504 | 1,471 | 1,471 | 83185d8011d7d839f91f9a69a5fff6ea5bad9270 | bigcode/the-stack | train |
2d762f60688b68bb0bda1801 | train | function | def MPO_ham_XXZ(L, delta, jxy=1.0, *, S=1 / 2, cyclic=False, **mpo_opts):
r"""XXZ-Hamiltonian in MPO form.
.. math::
H_\mathrm{XXZ} =
\sum_{i} (
J_X \sigma^X_i \sigma^X_{i + 1} +
J_Y \sigma^Y_i \sigma^Y_{i + 1} +
\Delta \sigma^Z_i \sigma^Z_{i + 1}
... | def MPO_ham_XXZ(L, delta, jxy=1.0, *, S=1 / 2, cyclic=False, **mpo_opts):
| r"""XXZ-Hamiltonian in MPO form.
.. math::
H_\mathrm{XXZ} =
\sum_{i} (
J_X \sigma^X_i \sigma^X_{i + 1} +
J_Y \sigma^Y_i \sigma^Y_{i + 1} +
\Delta \sigma^Z_i \sigma^Z_{i + 1}
)
- B_Z \sum_{i} \sigma^Z_i
Note the default convention of ... | H = _ham_heis(j=j, bz=bz, S=S, cyclic=cyclic)
return H.build_local_ham(L=L, **local_ham_1d_opts)
NNI_ham_heis = deprecated(ham_1d_heis, 'NNI_ham_heis', 'ham_1d_heis')
def MPO_ham_XXZ(L, delta, jxy=1.0, *, S=1 / 2, cyclic=False, **mpo_opts):
| 106 | 106 | 355 | 34 | 72 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | MPO_ham_XXZ | MPO_ham_XXZ | 1,759 | 1,796 | 1,759 | 1,759 | 928bdd34438f8bba729fa5cb1a455cf279b9f5a1 | bigcode/the-stack | train |
73254f4e2d3e3a1a8f0624ab | train | function | def MPO_identity_like(mpo, **mpo_opts):
"""Return an identity matrix operator with the same physical index and
inds/tags as ``mpo``.
"""
return MPO_identity(L=mpo.L, phys_dim=mpo.phys_dim(), dtype=mpo.dtype,
site_tag_id=mpo.site_tag_id, cyclic=mpo.cyclic,
... | def MPO_identity_like(mpo, **mpo_opts):
| """Return an identity matrix operator with the same physical index and
inds/tags as ``mpo``.
"""
return MPO_identity(L=mpo.L, phys_dim=mpo.phys_dim(), dtype=mpo.dtype,
site_tag_id=mpo.site_tag_id, cyclic=mpo.cyclic,
upper_ind_id=mpo.upper_ind_id,
... | (L - 2):
yield II.reshape(1, 1, phys_dim, phys_dim)
yield II.reshape(1, *cyc_dim, phys_dim, phys_dim)
return MatrixProductOperator(gen_arrays(), **mpo_opts)
def MPO_identity_like(mpo, **mpo_opts):
| 64 | 64 | 108 | 12 | 52 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | MPO_identity_like | MPO_identity_like | 935 | 942 | 935 | 935 | 2577f573b8e81853ae2ee264fd731d443a60fa71 | bigcode/the-stack | train |
872d2e5b1b0ea299729f8bd8 | train | function | def MPS_zero_state(L, bond_dim=1, phys_dim=2, cyclic=False,
dtype='float64', **mps_opts):
"""The all-zeros MPS state, of given bond-dimension.
Parameters
----------
L : int
The number of sites.
bond_dim : int, optional
The bond dimension, defaults to 1.
phys_d... | def MPS_zero_state(L, bond_dim=1, phys_dim=2, cyclic=False,
dtype='float64', **mps_opts):
| """The all-zeros MPS state, of given bond-dimension.
Parameters
----------
L : int
The number of sites.
bond_dim : int, optional
The bond dimension, defaults to 1.
phys_dim : int, optional
The physical (site) dimensions, defaults to 2.
cyclic : bool, optional
... | quimb.tensor.tensor_1d.MatrixProductState`.
"""
cstr = (choice(('0', '1')) for _ in range(L))
return MPS_computational_state(cstr, dtype=dtype, **mps_opts)
def MPS_zero_state(L, bond_dim=1, phys_dim=2, cyclic=False,
dtype='float64', **mps_opts):
| 82 | 82 | 274 | 31 | 51 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | MPS_zero_state | MPS_zero_state | 859 | 887 | 859 | 860 | a81159b62046a97f95b54f11e590148121ef566d | bigcode/the-stack | train |
f30108d81606e8bb85060701 | train | function | def ham_2d_heis(Lx, Ly, j=1.0, bz=0.0, **local_ham_2d_opts):
r"""Heisenberg Hamiltonian in
:class:`~quimb.tensor.tensor_2d_tebd.LocalHam2D`. form.
.. math::
H_\mathrm{Heis} =
\sum_{<ij>} (
J_X \sigma^X_i \sigma^X_{j} +
J_Y \sigma^Y_i \sigma^Y_{j} +
J_Z \... | def ham_2d_heis(Lx, Ly, j=1.0, bz=0.0, **local_ham_2d_opts):
| r"""Heisenberg Hamiltonian in
:class:`~quimb.tensor.tensor_2d_tebd.LocalHam2D`. form.
.. math::
H_\mathrm{Heis} =
\sum_{<ij>} (
J_X \sigma^X_i \sigma^X_{j} +
J_Y \sigma^Y_i \sigma^Y_{j} +
J_Z \sigma^Z_i \sigma^Z_{j}
)
- B_Z \sum_{i} \... | is(2, j=(0, 0, j), cyclic=False)
if bx == 0.0:
H1 = None
else:
H1 = -bx * spin_operator('X').real
return LocalHam2D(Lx, Ly, H2=H2, H1=H1, **local_ham_2d_opts)
def ham_2d_heis(Lx, Ly, j=1.0, bz=0.0, **local_ham_2d_opts):
| 113 | 113 | 379 | 33 | 80 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | ham_2d_heis | ham_2d_heis | 2,089 | 2,128 | 2,089 | 2,089 | 303ba65cd5496e7e7eb708118bafe9babc2bc6af | bigcode/the-stack | train |
a346077cd419abe04c88fad3 | train | function | def ham_1d_XXZ(L=None, delta=None, jxy=1.0, *,
S=1 / 2, cyclic=False, **local_ham_1d_opts):
r"""XXZ-Hamiltonian in
:class:`~quimb.tensor.tensor_1d_tebd.LocalHam1D` form.
.. math::
H_\mathrm{XXZ} =
\sum_{i} (
J_X \sigma^X_i \sigma^X_{i + 1} +
J_Y \sigm... | def ham_1d_XXZ(L=None, delta=None, jxy=1.0, *,
S=1 / 2, cyclic=False, **local_ham_1d_opts):
| r"""XXZ-Hamiltonian in
:class:`~quimb.tensor.tensor_1d_tebd.LocalHam1D` form.
.. math::
H_\mathrm{XXZ} =
\sum_{i} (
J_X \sigma^X_i \sigma^X_{i + 1} +
J_Y \sigma^Y_i \sigma^Y_{i + 1} +
\Delta \sigma^Z_i \sigma^Z_{i + 1}
)
- B_Z \sum_{i... | MPO with periodic boundary conditions or not, default is
open boundary conditions.
mpo_opts
Supplied to :class:`~quimb.tensor.tensor_1d.MatrixProductOperator`.
Returns
-------
MatrixProductOperator
"""
return MPO_ham_heis(L, j=(jxy, jxy, delta), S=S, cyclic=cyclic, **mpo_opts)
... | 125 | 125 | 418 | 42 | 83 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | ham_1d_XXZ | ham_1d_XXZ | 1,799 | 1,841 | 1,799 | 1,800 | 481606ff35f281a26ec8e40fda504fb3a5cc169f | bigcode/the-stack | train |
ea38a7b2c4f6a9624def92a0 | train | function | def spin_ham_mpo_tensor(one_site_terms, two_site_terms, S=1 / 2,
left_two_site_terms=None, which=None, cyclic=False):
"""Generate tensor(s) for a spin hamiltonian MPO.
Parameters
----------
one_site_terms : sequence of (scalar, operator)
The terms that act on a single si... | def spin_ham_mpo_tensor(one_site_terms, two_site_terms, S=1 / 2,
left_two_site_terms=None, which=None, cyclic=False):
| """Generate tensor(s) for a spin hamiltonian MPO.
Parameters
----------
one_site_terms : sequence of (scalar, operator)
The terms that act on a single site, each ``operator`` can be a string
suitable to be sent to :func:`spin_operator` or an actual 2d-array.
two_site_terms : sequenc... | ProductOperator(arrays, **mpo_opts)
if normalize:
rmpo /= (rmpo.H @ rmpo)**0.5
return rmpo
@random_seed_fn
def MPO_rand_herm(L, bond_dim, phys_dim=2, normalize=True,
dtype='float64', **mpo_opts):
"""Generate a random hermitian matrix product operator.
See :class:`~quimb.ten... | 232 | 232 | 775 | 35 | 196 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | spin_ham_mpo_tensor | spin_ham_mpo_tensor | 1,052 | 1,135 | 1,052 | 1,053 | 53c18abf8693b65c76182559b1c21a803a0e86c0 | bigcode/the-stack | train |
f3763e0d8f8ac3a1267e5ef7 | train | function | def ham_1d_heis(L=None, j=1.0, bz=0.0, *, S=1 / 2,
cyclic=False, **local_ham_1d_opts):
r"""Heisenberg Hamiltonian in
:class:`~quimb.tensor.tensor_1d_tebd.LocalHam1D` form.
.. math::
H_\mathrm{Heis} =
\sum_{i} (
J_X \sigma^X_i \sigma^X_{i + 1} +
J_Y \... | def ham_1d_heis(L=None, j=1.0, bz=0.0, *, S=1 / 2,
cyclic=False, **local_ham_1d_opts):
| r"""Heisenberg Hamiltonian in
:class:`~quimb.tensor.tensor_1d_tebd.LocalHam1D` form.
.. math::
H_\mathrm{Heis} =
\sum_{i} (
J_X \sigma^X_i \sigma^X_{i + 1} +
J_Y \sigma^Y_i \sigma^Y_{i + 1} +
J_Z \sigma^Z_i \sigma^Z_{i + 1}
)
- B_Z \s... |
open boundary conditions.
mpo_opts
Supplied to :class:`~quimb.tensor.tensor_1d.MatrixProductOperator`.
Returns
-------
MatrixProductOperator
"""
H = _ham_heis(j=j, bz=bz, S=S, cyclic=cyclic)
return H.build_mpo(L, **mpo_opts)
def ham_1d_heis(L=None, j=1.0, bz=0.0, *, S=1 / 2... | 119 | 119 | 397 | 43 | 76 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | ham_1d_heis | ham_1d_heis | 1,714 | 1,753 | 1,714 | 1,715 | ebd669d5a6aa32ec66a5f0fb060c363b93328b64 | bigcode/the-stack | train |
1ce558306afcf11c8f216f30 | train | function | def _ham_mbl(L, dh, j=1.0, seed=None, S=1 / 2, *, cyclic=False,
dh_dist='s', dh_dim=1, beta=None):
# start with the heisenberg builder
H = _ham_heis(j, S=S, cyclic=cyclic)
dhds, rs = _gen_mbl_random_factors(L, dh, dh_dim, dh_dist, seed, beta)
# generate noise, potentially in all direction... | def _ham_mbl(L, dh, j=1.0, seed=None, S=1 / 2, *, cyclic=False,
dh_dist='s', dh_dim=1, beta=None):
# start with the heisenberg builder
| H = _ham_heis(j, S=S, cyclic=cyclic)
dhds, rs = _gen_mbl_random_factors(L, dh, dh_dim, dh_dist, seed, beta)
# generate noise, potentially in all directions, each with own strength
for i in range(L):
dh_r_xyzs = zip(dhds, rs[:, i], 'XYZ')
for dh, r, xyz in dh_r_xyzs:
H[i] +=... | _1d_bilinear_biquadratic')
def _ham_mbl(L, dh, j=1.0, seed=None, S=1 / 2, *, cyclic=False,
dh_dist='s', dh_dim=1, beta=None):
# start with the heisenberg builder
| 64 | 64 | 165 | 53 | 11 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | _ham_mbl | _ham_mbl | 1,935 | 1,948 | 1,935 | 1,937 | 89b45ca7ab1125a202272353143205968b2a664f | bigcode/the-stack | train |
484233e24ee8d57465a8fb3c | train | function | def MPS_w_state(L, dtype='float64', **mps_opts):
"""Build the chi=2 OBC MPS representation of the W state.
Parameters
----------
L : int
Number of qubits.
dtype : {'float64', 'complex128', 'float32', 'complex64'}, optional
The underlying data type.
mps_opts
Supplied to :... | def MPS_w_state(L, dtype='float64', **mps_opts):
| """Build the chi=2 OBC MPS representation of the W state.
Parameters
----------
L : int
Number of qubits.
dtype : {'float64', 'complex128', 'float32', 'complex64'}, optional
The underlying data type.
mps_opts
Supplied to :class:`~quimb.tensor.tensor_1d.MatrixProductState... | 0.],
[0., 1.]]]).astype(dtype)
yield np.array([[1., 0.],
[0., 1.]]).astype(dtype)
return MatrixProductState(gen_arrays(), **mps_opts)
def MPS_w_state(L, dtype='float64', **mps_opts):
| 68 | 68 | 228 | 17 | 51 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | MPS_w_state | MPS_w_state | 811 | 837 | 811 | 811 | e3f4e86bead095b0673a976100e5f1049584ec9e | bigcode/the-stack | train |
4fb36b99552373885a7c67ac | train | function | def ham_1d_mbl(L, dh, j=1.0, seed=None, S=1 / 2, *, cyclic=False,
dh_dist='s', dh_dim=1, beta=None, **local_ham_1d_opts):
r"""The many-body-localized spin hamiltonian in
:class:`~quimb.tensor.tensor_1d_tebd.LocalHam1D` form.
.. math::
H_\mathrm{MBL} =
\sum_{i} (
... | def ham_1d_mbl(L, dh, j=1.0, seed=None, S=1 / 2, *, cyclic=False,
dh_dist='s', dh_dim=1, beta=None, **local_ham_1d_opts):
| r"""The many-body-localized spin hamiltonian in
:class:`~quimb.tensor.tensor_1d_tebd.LocalHam1D` form.
.. math::
H_\mathrm{MBL} =
\sum_{i} (
J_X \sigma^X_i \sigma^X_{i + 1} +
J_Y \sigma^Y_i \sigma^Y_{i + 1} +
J_Z \sigma^Z_i \sigma^Z_{i + 1}
)... | , only if ``dh_dist='qr'``.
mpo_opts
Supplied to :class:`MatrixProductOperator`.
Returns
-------
MatrixProductOperator
"""
H = _ham_mbl(L, dh=dh, j=j, seed=seed, S=S, cyclic=cyclic,
dh_dist=dh_dist, dh_dim=dh_dim, beta=beta)
return H.build_mpo(L, **mpo_opts)
def ham... | 150 | 150 | 501 | 54 | 96 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | ham_1d_mbl | ham_1d_mbl | 1,999 | 2,045 | 1,999 | 2,000 | 1e16bd11479dc44d16306998604f21ab94ba2dcf | bigcode/the-stack | train |
042bf8ff1fc7a9ee77fece3b | train | function | def ham_1d_ising(L=None, j=1.0, bx=0.0, *, S=1 / 2,
cyclic=False, **local_ham_1d_opts):
r"""Ising Hamiltonian in
:class:`~quimb.tensor.tensor_1d_tebd.LocalHam1D` form.
.. math::
H_\mathrm{Ising} =
J \sum_{i} \sigma^Z_i \sigma^Z_{i + 1} -
B_x \sum_{i} \sigma^X_i
... | def ham_1d_ising(L=None, j=1.0, bx=0.0, *, S=1 / 2,
cyclic=False, **local_ham_1d_opts):
| r"""Ising Hamiltonian in
:class:`~quimb.tensor.tensor_1d_tebd.LocalHam1D` form.
.. math::
H_\mathrm{Ising} =
J \sum_{i} \sigma^Z_i \sigma^Z_{i + 1} -
B_x \sum_{i} \sigma^X_i
Note the default convention of antiferromagnetic interactions and spin
operators not Pauli matrices... | ~quimb.tensor.tensor_1d.MatrixProductOperator`.
Returns
-------
MatrixProductOperator
"""
H = _ham_ising(j=j, bx=bx, S=S, cyclic=cyclic)
return H.build_mpo(L, **mpo_opts)
def ham_1d_ising(L=None, j=1.0, bx=0.0, *, S=1 / 2,
cyclic=False, **local_ham_1d_opts):
| 102 | 102 | 343 | 43 | 59 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | ham_1d_ising | ham_1d_ising | 1,507 | 1,542 | 1,507 | 1,508 | 42a83c0b82de0b57e13f656e90233fc7bc27166b | bigcode/the-stack | train |
9c543189696b55a5d98c8b05 | train | function | def MPO_ham_XY(L, j=1.0, bz=0.0, *, S=1 / 2, cyclic=False, **mpo_opts):
r"""XY-Hamiltonian in MPO form.
.. math::
H_\mathrm{XY} =
\sum_{i} (
J_X \sigma^X_i \sigma^X_{i + 1} +
J_Y \sigma^Y_i \sigma^Y_{i + 1}
)
- B_x \sum_{i} \sigma^Z_i
Note the d... | def MPO_ham_XY(L, j=1.0, bz=0.0, *, S=1 / 2, cyclic=False, **mpo_opts):
| r"""XY-Hamiltonian in MPO form.
.. math::
H_\mathrm{XY} =
\sum_{i} (
J_X \sigma^X_i \sigma^X_{i + 1} +
J_Y \sigma^Y_i \sigma^Y_{i + 1}
)
- B_x \sum_{i} \sigma^Z_i
Note the default convention of antiferromagnetic interactions and spin
operato... | ness
H += jx / 2, '+', '-'
H += jx / 2, '-', '+'
else:
H += jx, 'X', 'X'
H += jy, 'Y', 'Y'
H -= bz, 'Z'
return H
def MPO_ham_XY(L, j=1.0, bz=0.0, *, S=1 / 2, cyclic=False, **mpo_opts):
| 101 | 101 | 338 | 36 | 64 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | MPO_ham_XY | MPO_ham_XY | 1,569 | 1,605 | 1,569 | 1,569 | f2f2daccedc57a4c7185c04c1d384f166f1b3c6e | bigcode/the-stack | train |
0ad81f1ea3b7bb1137fcdf25 | train | function | def maybe_make_real(X):
"""Check if ``X`` is real, if so, convert to contiguous array.
"""
if np.allclose(X.imag, np.zeros_like(X)):
return np.ascontiguousarray(X.real)
return X
| def maybe_make_real(X):
| """Check if ``X`` is real, if so, convert to contiguous array.
"""
if np.allclose(X.imag, np.zeros_like(X)):
return np.ascontiguousarray(X.real)
return X
| See :class:`~quimb.tensor.tensor_gen.MPO_rand`.
"""
return MPO_rand(L, bond_dim, phys_dim=phys_dim, normalize=normalize,
dtype=dtype, herm=True, **mpo_opts)
# ---------------------------- MPO hamiltonians ----------------------------- #
def maybe_make_real(X):
| 64 | 64 | 53 | 6 | 58 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | maybe_make_real | maybe_make_real | 1,044 | 1,049 | 1,044 | 1,044 | 4f5effc2120d87e7fea969c757f74d5d742eaa93 | bigcode/the-stack | train |
315d701b46436a6d0dc7c3cc | train | function | @functools.lru_cache(128)
def classical_ising_S_matrix(beta, j=1.0):
"""The interaction term for the classical ising model.
"""
S = np.array(
[[math.exp(j * beta), math.exp(-j * beta)],
[math.exp(-j * beta), math.exp(j * beta)]])
make_immutable(S)
return S
| @functools.lru_cache(128)
def classical_ising_S_matrix(beta, j=1.0):
| """The interaction term for the classical ising model.
"""
S = np.array(
[[math.exp(j * beta), math.exp(-j * beta)],
[math.exp(-j * beta), math.exp(j * beta)]])
make_immutable(S)
return S
| ] * len(inds), dtype=dtype),
inds=inds,
tags=[site_tag_id.format(i, j, k)]))
tn = TensorNetwork(ts)
return tn
@functools.lru_cache(128)
def classical_ising_S_matrix(beta, j=1.0):
| 64 | 64 | 85 | 24 | 39 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | classical_ising_S_matrix | classical_ising_S_matrix | 287 | 295 | 287 | 288 | 0fda0152d990c2ebb25c21c9ace838e552d0a37d | bigcode/the-stack | train |
9e7b0777b6dd584572d3c14e | train | function | def MPS_computational_state(binary, dtype='float64', cyclic=False, **mps_opts):
"""A computational basis state in Matrix Product State form.
Parameters
----------
binary : str or sequence of int
String specifying the state, e.g. ``'00101010111'`` or ``[0, 0, 1]``.
cyclic : bool, optional
... | def MPS_computational_state(binary, dtype='float64', cyclic=False, **mps_opts):
| """A computational basis state in Matrix Product State form.
Parameters
----------
binary : str or sequence of int
String specifying the state, e.g. ``'00101010111'`` or ``[0, 0, 1]``.
cyclic : bool, optional
Generate a MPS with periodic boundary conditions or not, default open
... | 1, -1)
mps_arrays = (asarray(array).reshape(*shape)
for array, shape in zip(arrays, gen_array_shapes()))
return MatrixProductState(mps_arrays, shape='lrp', **mps_opts)
def MPS_computational_state(binary, dtype='float64', cyclic=False, **mps_opts):
| 74 | 74 | 249 | 22 | 52 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | MPS_computational_state | MPS_computational_state | 736 | 761 | 736 | 736 | 51bf0334c1e53d4c895c0434807bc960110adb54 | bigcode/the-stack | train |
3ad1be0cdab4c8ec09c3888f | train | function | @random_seed_fn
def MPO_rand_herm(L, bond_dim, phys_dim=2, normalize=True,
dtype='float64', **mpo_opts):
"""Generate a random hermitian matrix product operator.
See :class:`~quimb.tensor.tensor_gen.MPO_rand`.
"""
return MPO_rand(L, bond_dim, phys_dim=phys_dim, normalize=normalize,
... | @random_seed_fn
def MPO_rand_herm(L, bond_dim, phys_dim=2, normalize=True,
dtype='float64', **mpo_opts):
| """Generate a random hermitian matrix product operator.
See :class:`~quimb.tensor.tensor_gen.MPO_rand`.
"""
return MPO_rand(L, bond_dim, phys_dim=phys_dim, normalize=normalize,
dtype=dtype, herm=True, **mpo_opts)
| if normalize:
rmpo /= (rmpo.H @ rmpo)**0.5
return rmpo
@random_seed_fn
def MPO_rand_herm(L, bond_dim, phys_dim=2, normalize=True,
dtype='float64', **mpo_opts):
| 64 | 64 | 95 | 35 | 28 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | MPO_rand_herm | MPO_rand_herm | 1,032 | 1,039 | 1,032 | 1,034 | 32ac129f02c74a8a82f627b33c0f7617a2abf91d | bigcode/the-stack | train |
5d618844145f69b9c0de467e | train | function | def TN3D_classical_ising_partition_function(
Lx,
Ly,
Lz,
beta,
h=0.0,
cyclic=False,
site_tag_id='I{},{},{}',
):
"""Tensor network representation of the 3D classical ising model
partition function.
Parameters
----------
Lx : int
Length of side x.
Ly : int
... | def TN3D_classical_ising_partition_function(
Lx,
Ly,
Lz,
beta,
h=0.0,
cyclic=False,
site_tag_id='I{},{},{}',
):
| """Tensor network representation of the 3D classical ising model
partition function.
Parameters
----------
Lx : int
Length of side x.
Ly : int
Length of side y.
Lz : int
Length of side z.
beta : float
The inverse temperature.
h : float, optional
... | inds.append(bonds[((i - 1) % Lx, j), (i, j)])
ts.append(Tensor(
data=classical_ising_T2d_matrix(beta, directions, h=h),
inds=inds,
tags=[site_tag_id.format(i, j),
row_tag_id.format(i),
col_tag_id.format(j)]))
tn = TensorNetwork(ts)
... | 182 | 182 | 607 | 48 | 134 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | TN3D_classical_ising_partition_function | TN3D_classical_ising_partition_function | 577 | 652 | 577 | 585 | da00d6ed3d4718df7039ac67783beee06d65d528 | bigcode/the-stack | train |
c91158d004da165f50eb8ef8 | train | function | def _ham_heis(j=1.0, bz=0.0, *, S=1 / 2, cyclic=False):
H = SpinHam1D(S=S, cyclic=cyclic)
try:
jx, jy, jz = j
except (TypeError, ValueError):
jx = jy = jz = j
if jx == jy:
# easy way to enforce realness
H += jx / 2, '+', '-'
H += jx / 2, '-', '+'
else:
... | def _ham_heis(j=1.0, bz=0.0, *, S=1 / 2, cyclic=False):
| H = SpinHam1D(S=S, cyclic=cyclic)
try:
jx, jy, jz = j
except (TypeError, ValueError):
jx = jy = jz = j
if jx == jy:
# easy way to enforce realness
H += jx / 2, '+', '-'
H += jx / 2, '-', '+'
else:
H += jx, 'X', 'X'
H += jy, 'Y', 'Y'
H += ... | 1d_opts)
NNI_ham_XY = deprecated(ham_1d_XY, 'NNI_ham_XY', 'ham_1d_XY')
def _ham_heis(j=1.0, bz=0.0, *, S=1 / 2, cyclic=False):
| 64 | 64 | 168 | 28 | 36 | cbwang2016/quimb | quimb/tensor/tensor_gen.py | Python | _ham_heis | _ham_heis | 1,652 | 1,671 | 1,652 | 1,652 | 553e929c03ff36d4497141befd5a8cf22757cd0c | bigcode/the-stack | train |
8097c852be15eb514f69a04a | train | class | class NotAuthorized(ZunException):
message = _("Not authorized.")
code = 403
| class NotAuthorized(ZunException):
| message = _("Not authorized.")
code = 403
| .
class InvalidParameterValue(Invalid):
message = _("%(err)s")
class InvalidParam(Invalid):
message = _('Invalid param %(param)s')
class PatchError(Invalid):
message = _("Couldn't apply patch '%(patch)s'. Reason: %(reason)s")
class NotAuthorized(ZunException):
| 64 | 64 | 20 | 7 | 57 | cooldharma06/zun_glance_tag | zun/common/exception.py | Python | NotAuthorized | NotAuthorized | 330 | 332 | 330 | 330 | c85df4571c742307dfc59ccbb4f46d0b64fe6b5d | bigcode/the-stack | train |
97737be03ee2e0ceb6c6a58d | train | class | class PollTimeOut(ZunException):
message = _("Polling request timed out.")
| class PollTimeOut(ZunException):
| message = _("Polling request timed out.")
| .")
class InvalidStateException(ZunException):
message = _("Cannot %(action)s container %(id)s in %(actual_state)s state")
code = 409
class DockerError(ZunException):
message = _("Docker internal error: %(error_msg)s.")
class PollTimeOut(ZunException):
| 63 | 64 | 17 | 8 | 55 | cooldharma06/zun_glance_tag | zun/common/exception.py | Python | PollTimeOut | PollTimeOut | 437 | 438 | 437 | 437 | 56f331fd969bc7b8c1367ec8e38dffa58dae45e2 | bigcode/the-stack | train |
dd34ff5d211d9ef28479c9ba | train | class | class ValidationError(ZunException):
message = _("Validation error")
| class ValidationError(ZunException):
| message = _("Validation error")
| to connect to remote host")
class SocketException(ZunException):
message = _("Socket exceptions")
class InvalidWebsocketUrl(ZunException):
message = _("Websocket Url invalid")
class InvalidWebsocketToken(ZunException):
message = _("Websocket token is invalid")
class ValidationError(ZunException):
| 64 | 64 | 14 | 7 | 57 | cooldharma06/zun_glance_tag | zun/common/exception.py | Python | ValidationError | ValidationError | 521 | 522 | 521 | 521 | 0f8040049c35371a2c4b163516ba8c12105632d4 | bigcode/the-stack | train |
811262bdc77fe9a0485b8812 | train | class | class CPUUnpinningInvalid(Invalid):
message = _("CPU set to unpin %(requested)s must be a subset of "
"pinned CPU set %(pinned)s")
| class CPUUnpinningInvalid(Invalid):
| message = _("CPU set to unpin %(requested)s must be a subset of "
"pinned CPU set %(pinned)s")
| unpin %(requested)s must be a subset of "
"known CPU set %(cpuset)s")
class CPUPinningInvalid(Invalid):
message = _("CPU set to pin %(requested)s must be a subset of "
"free CPU set %(free)s")
class CPUUnpinningInvalid(Invalid):
| 64 | 64 | 38 | 9 | 55 | cooldharma06/zun_glance_tag | zun/common/exception.py | Python | CPUUnpinningInvalid | CPUUnpinningInvalid | 482 | 484 | 482 | 482 | 6cfb87834a589ec1168b30e75e7bf16cc21ceddb | bigcode/the-stack | train |
e5920ebcef7a4352a6c43472 | train | class | class NotFound(ZunException):
message = _("Resource could not be found.")
code = 404
| class NotFound(ZunException):
| message = _("Resource could not be found.")
code = 404
| pin %(requested)s must be a subset of "
"free CPU set %(free)s")
class CPUUnpinningInvalid(Invalid):
message = _("CPU set to unpin %(requested)s must be a subset of "
"pinned CPU set %(pinned)s")
class NotFound(ZunException):
| 64 | 64 | 23 | 7 | 57 | cooldharma06/zun_glance_tag | zun/common/exception.py | Python | NotFound | NotFound | 487 | 489 | 487 | 487 | 0b4bea2cfec45ecd2f6a9f42d63b76b8ec58b0a6 | bigcode/the-stack | train |
29972a5ddc1ec87c30b8705c | train | class | class NoInteractiveFlag(Invalid):
message = _("%(msg)s")
| class NoInteractiveFlag(Invalid):
| message = _("%(msg)s")
| )s (%(name)s) could not be found.")
class CommandError(ZunException):
message = _("The command: %(cmd)s failed on the system.")
class NoValidHost(ZunException):
message = _("No valid host was found. %(reason)s")
class NoInteractiveFlag(Invalid):
| 64 | 64 | 16 | 7 | 57 | cooldharma06/zun_glance_tag | zun/common/exception.py | Python | NoInteractiveFlag | NoInteractiveFlag | 463 | 464 | 463 | 463 | 6f282f751d49cb9e1c7d0915309370a2fb4e8017 | bigcode/the-stack | train |
a2916bfeda73a2c554600197 | train | class | class ResourcesUnavailable(ZunException):
message = _("Insufficient compute resources: %(reason)s.")
| class ResourcesUnavailable(ZunException):
| message = _("Insufficient compute resources: %(reason)s.")
| message = _("Socket exceptions")
class InvalidWebsocketUrl(ZunException):
message = _("Websocket Url invalid")
class InvalidWebsocketToken(ZunException):
message = _("Websocket token is invalid")
class ValidationError(ZunException):
message = _("Validation error")
class ResourcesUnavailable(ZunExcept... | 64 | 64 | 20 | 7 | 57 | cooldharma06/zun_glance_tag | zun/common/exception.py | Python | ResourcesUnavailable | ResourcesUnavailable | 525 | 526 | 525 | 525 | de77e54c1d11bce2faf943c9b636d5041d4a3e7b | bigcode/the-stack | train |
72527820e081b42db71fa257 | train | class | class InvalidParameterValue(Invalid):
message = _("%(err)s")
| class InvalidParameterValue(Invalid):
| message = _("%(err)s")
| ):
pass
class Conflict(ZunException):
message = _('Conflict.')
code = 409
class InvalidState(Conflict):
message = _("Invalid resource state.")
# Cannot be templated as the error syntax varies.
# msg needs to be constructed when raised.
class InvalidParameterValue(Invalid):
| 64 | 64 | 16 | 7 | 57 | cooldharma06/zun_glance_tag | zun/common/exception.py | Python | InvalidParameterValue | InvalidParameterValue | 318 | 319 | 318 | 318 | 1d5bcde89cbc964f83919825ee2bd883e628f62b | bigcode/the-stack | train |
62b7a199fe92b64e4faed331 | train | class | class ImageNotFound(HTTPNotFound):
message = _("Image %(image)s could not be found.")
| class ImageNotFound(HTTPNotFound):
| message = _("Image %(image)s could not be found.")
| not be found.")
class NetworkNotFound(HTTPNotFound):
message = _("Neutron network %(network)s could not be found.")
class PortNotFound(HTTPNotFound):
message = _("Neutron port %(port)s could not be found.")
class ImageNotFound(HTTPNotFound):
| 63 | 64 | 22 | 9 | 54 | cooldharma06/zun_glance_tag | zun/common/exception.py | Python | ImageNotFound | ImageNotFound | 363 | 364 | 363 | 363 | 0412a94dbb67c04f10ac4606ade580872144beaf | bigcode/the-stack | train |
5e59be019b2d750b7e4209d0 | train | function | def wrap_pecan_controller_exception(func):
"""This decorator wraps pecan controllers to handle exceptions."""
def _func_server_error(log_correlation_id, status_code):
pecan.response.status = status_code
return {
'status_code': status_code,
'title': woutil.status_reasons[s... | def wrap_pecan_controller_exception(func):
| """This decorator wraps pecan controllers to handle exceptions."""
def _func_server_error(log_correlation_id, status_code):
pecan.response.status = status_code
return {
'status_code': status_code,
'title': woutil.status_reasons[status_code],
'description': six... | with an obfuscated message
return func_server_error(log_correlation_id, http_error_code)
else:
# raise a client error the original message
LOG.debug(excp)
return func_client_error(excp, http_error_code)
return wrapped
def wrap_pecan_contro... | 64 | 64 | 163 | 9 | 54 | cooldharma06/zun_glance_tag | zun/common/exception.py | Python | wrap_pecan_controller_exception | wrap_pecan_controller_exception | 132 | 152 | 132 | 132 | bd7a25a78da64afad5e1c4c69ef395ce00745bca | bigcode/the-stack | train |
c031ae3301b3153236c4353a | train | class | class InvalidValue(Invalid):
message = _("Received value '%(value)s' is invalid for type %(type)s.")
| class InvalidValue(Invalid):
| message = _("Received value '%(value)s' is invalid for type %(type)s.")
| )s of %(objname)s is not supported')
class OrphanedObjectError(ZunException):
message = _('Cannot call %(method)s on orphaned %(objtype)s object')
class Invalid(ZunException):
message = _("Unacceptable parameters.")
code = 400
class InvalidValue(Invalid):
| 64 | 64 | 25 | 6 | 57 | cooldharma06/zun_glance_tag | zun/common/exception.py | Python | InvalidValue | InvalidValue | 262 | 263 | 262 | 262 | 700077077a74ea4307cf8fe02a6b3d1c1adb41bd | bigcode/the-stack | train |
0c8a88da103a0fe5d99cb814 | train | class | class ContainerNotFound(HTTPNotFound):
message = _("Container %(container)s could not be found.")
| class ContainerNotFound(HTTPNotFound):
| message = _("Container %(container)s could not be found.")
| message = _("Not authorized.")
code = 403
class ConfigInvalid(ZunException):
message = _("Invalid configuration file. %(error_msg)s")
class PolicyNotAuthorized(NotAuthorized):
message = _("Policy doesn't allow %(action)s to be performed.")
class ContainerNotFound(HTTPNotFound):
| 63 | 64 | 22 | 9 | 54 | cooldharma06/zun_glance_tag | zun/common/exception.py | Python | ContainerNotFound | ContainerNotFound | 343 | 344 | 343 | 343 | e3113cea78256333bfaf291614aa6e444c657830 | bigcode/the-stack | train |
82a2f38b0544621422a13957 | train | class | class PolicyNotAuthorized(NotAuthorized):
message = _("Policy doesn't allow %(action)s to be performed.")
| class PolicyNotAuthorized(NotAuthorized):
| message = _("Policy doesn't allow %(action)s to be performed.")
| message = _("Couldn't apply patch '%(patch)s'. Reason: %(reason)s")
class NotAuthorized(ZunException):
message = _("Not authorized.")
code = 403
class ConfigInvalid(ZunException):
message = _("Invalid configuration file. %(error_msg)s")
class PolicyNotAuthorized(NotAuthorized):
| 64 | 64 | 21 | 7 | 57 | cooldharma06/zun_glance_tag | zun/common/exception.py | Python | PolicyNotAuthorized | PolicyNotAuthorized | 339 | 340 | 339 | 339 | 84d3fdb77cd31f5b07c31022d681aff2fb87d8c4 | bigcode/the-stack | train |
a7376f7926e71f39441bf61d | train | class | class InvalidParam(Invalid):
message = _('Invalid param %(param)s')
| class InvalidParam(Invalid):
| message = _('Invalid param %(param)s')
| .')
code = 409
class InvalidState(Conflict):
message = _("Invalid resource state.")
# Cannot be templated as the error syntax varies.
# msg needs to be constructed when raised.
class InvalidParameterValue(Invalid):
message = _("%(err)s")
class InvalidParam(Invalid):
| 64 | 64 | 16 | 6 | 58 | cooldharma06/zun_glance_tag | zun/common/exception.py | Python | InvalidParam | InvalidParam | 322 | 323 | 322 | 322 | 563d3a83a2b4b1c6d49bb7ffa96c97cd79a92a07 | bigcode/the-stack | train |
3253be80533aeb96e28ad9b6 | train | class | class PortBindingFailed(Invalid):
message = _("Binding failed for port %(port)s, please check neutron "
"logs for more information.")
| class PortBindingFailed(Invalid):
| message = _("Binding failed for port %(port)s, please check neutron "
"logs for more information.")
| resource class with %(field)s %(value)s already exists.")
class PortNotUsable(Invalid):
message = _("Port %(port)s not usable for the container.")
class PortInUse(Invalid):
message = _("Port %(port)s is still in use.")
class PortBindingFailed(Invalid):
| 63 | 64 | 30 | 7 | 56 | cooldharma06/zun_glance_tag | zun/common/exception.py | Python | PortBindingFailed | PortBindingFailed | 419 | 421 | 419 | 419 | e6e8f1f1bf6e76962d0b90e0f8bf901a6f62d4a5 | bigcode/the-stack | train |
9c562c824cb027aae20af4da | train | class | class ResourceExists(ObjectNotUnique):
message = _("The %(name)s resource already exists.")
code = 409
| class ResourceExists(ObjectNotUnique):
| message = _("The %(name)s resource already exists.")
code = 409
| could not be found.")
class ObjectNotUnique(ZunException):
message = _("The %(name)s already exists.")
class ResourceNotFound(ObjectNotFound):
message = _("The %(name)s resource %(id)s could not be found.")
code = 404
class ResourceExists(ObjectNotUnique):
| 64 | 64 | 25 | 7 | 56 | cooldharma06/zun_glance_tag | zun/common/exception.py | Python | ResourceExists | ResourceExists | 236 | 238 | 236 | 236 | 722e37dc9b6e163897d70422545fd802c42e5178 | bigcode/the-stack | train |
04fc42761049385f76e9098e | train | class | class ResourceProviderNotFound(HTTPNotFound):
message = _("Resource provider %(resource_provider)s could not be found.")
| class ResourceProviderNotFound(HTTPNotFound):
| message = _("Resource provider %(resource_provider)s could not be found.")
| ImageNotFound(HTTPNotFound):
message = _("Image %(image)s could not be found.")
class ZunServiceNotFound(HTTPNotFound):
message = _("Zun service %(binary)s on host %(host)s could not be found.")
class ResourceProviderNotFound(HTTPNotFound):
| 63 | 64 | 25 | 10 | 53 | cooldharma06/zun_glance_tag | zun/common/exception.py | Python | ResourceProviderNotFound | ResourceProviderNotFound | 371 | 372 | 371 | 371 | 9d071e9b9fcd5af8ee17501f6c1530a09042df9b | bigcode/the-stack | train |
ea8770f71b8054bff5403302 | train | class | class ApiVersionsIntersect(ZunException):
message = _("Version of %(name)s %(min_ver)s %(max_ver)s intersects "
"with another versions.")
| class ApiVersionsIntersect(ZunException):
| message = _("Version of %(name)s %(min_ver)s %(max_ver)s intersects "
"with another versions.")
| code = 404
class SchedulerHostFilterNotFound(NotFound):
message = _("Scheduler Host Filter %(filter_name)s could not be found.")
class ClassNotFound(NotFound):
message = _("Class %(class_name)s could not be found: %(exception)s")
class ApiVersionsIntersect(ZunException):
| 64 | 64 | 33 | 8 | 56 | cooldharma06/zun_glance_tag | zun/common/exception.py | Python | ApiVersionsIntersect | ApiVersionsIntersect | 500 | 502 | 500 | 500 | ecb7d25c29ca979717b0b915970270676099e970 | bigcode/the-stack | train |
a487e59c0fdf499f1d8eea6b | train | class | class InvalidWebsocketUrl(ZunException):
message = _("Websocket Url invalid")
| class InvalidWebsocketUrl(ZunException):
| message = _("Websocket Url invalid")
| _("Version of %(name)s %(min_ver)s %(max_ver)s intersects "
"with another versions.")
class ConnectionFailed(ZunException):
message = _("Failed to connect to remote host")
class SocketException(ZunException):
message = _("Socket exceptions")
class InvalidWebsocketUrl(ZunException):
| 64 | 64 | 18 | 9 | 55 | cooldharma06/zun_glance_tag | zun/common/exception.py | Python | InvalidWebsocketUrl | InvalidWebsocketUrl | 513 | 514 | 513 | 513 | bee9906ba46b62911b4c479fc549546beccd92e9 | bigcode/the-stack | train |
d9e61c2fe64b90828f985f11 | train | class | class ContainerHostNotUp(ZunException):
message = _("Container %(container)s host %(host)s is not up.")
| class ContainerHostNotUp(ZunException):
| message = _("Container %(container)s host %(host)s is not up.")
| _("Invalid configuration file. %(error_msg)s")
class PolicyNotAuthorized(NotAuthorized):
message = _("Policy doesn't allow %(action)s to be performed.")
class ContainerNotFound(HTTPNotFound):
message = _("Container %(container)s could not be found.")
class ContainerHostNotUp(ZunException):
| 63 | 64 | 25 | 9 | 54 | cooldharma06/zun_glance_tag | zun/common/exception.py | Python | ContainerHostNotUp | ContainerHostNotUp | 347 | 348 | 347 | 347 | aca1cc068a84c562df4ec9e4515e6f563ba2215f | bigcode/the-stack | train |
33c09c681201b7ba1b07f8f0 | train | class | class IncompatibleObjectVersion(ZunException):
message = _('Version %(objver)s of %(objname)s is not supported')
| class IncompatibleObjectVersion(ZunException):
| message = _('Version %(objver)s of %(objname)s is not supported')
| %(name)s resource already exists.")
code = 409
class AuthorizationFailure(ZunException):
message = _("%(client)s connection failed. %(message)s")
class UnsupportedObjectError(ZunException):
message = _('Unsupported object type %(objtype)s')
class IncompatibleObjectVersion(ZunException):
| 64 | 64 | 27 | 9 | 55 | cooldharma06/zun_glance_tag | zun/common/exception.py | Python | IncompatibleObjectVersion | IncompatibleObjectVersion | 249 | 250 | 249 | 249 | 73ac5a09c7944c288b1c6f4cdcbbadbef1364671 | bigcode/the-stack | train |
19f50eee83c2e19fd6b88531 | train | class | class ComputeNodeNotFound(HTTPNotFound):
message = _("Compute node %(compute_node)s could not be found.")
| class ComputeNodeNotFound(HTTPNotFound):
| message = _("Compute node %(compute_node)s could not be found.")
| to be performed.")
class ContainerNotFound(HTTPNotFound):
message = _("Container %(container)s could not be found.")
class ContainerHostNotUp(ZunException):
message = _("Container %(container)s host %(host)s is not up.")
class ComputeNodeNotFound(HTTPNotFound):
| 63 | 64 | 25 | 10 | 53 | cooldharma06/zun_glance_tag | zun/common/exception.py | Python | ComputeNodeNotFound | ComputeNodeNotFound | 351 | 352 | 351 | 351 | f69d86ec188b5a1fb95b0abaa59cafbb94696e58 | bigcode/the-stack | train |
24d0dac5ae430811a84542e9 | train | class | class PatchError(Invalid):
message = _("Couldn't apply patch '%(patch)s'. Reason: %(reason)s")
| class PatchError(Invalid):
| message = _("Couldn't apply patch '%(patch)s'. Reason: %(reason)s")
| _("Invalid resource state.")
# Cannot be templated as the error syntax varies.
# msg needs to be constructed when raised.
class InvalidParameterValue(Invalid):
message = _("%(err)s")
class InvalidParam(Invalid):
message = _('Invalid param %(param)s')
class PatchError(Invalid):
| 64 | 64 | 24 | 6 | 58 | cooldharma06/zun_glance_tag | zun/common/exception.py | Python | PatchError | PatchError | 326 | 327 | 326 | 326 | 6d5f58835f3c920ee8d0fc186256e78459bf1e4e | bigcode/the-stack | train |
dd014e8784094391c88efd79 | train | class | class ComputeNodeAlreadyExists(ResourceExists):
message = _("A compute node with %(field)s %(value)s already exists.")
| class ComputeNodeAlreadyExists(ResourceExists):
| message = _("A compute node with %(field)s %(value)s already exists.")
| %(inventory)s could not be found.")
class AllocationNotFound(HTTPNotFound):
message = _("Allocation %(allocation)s could not be found.")
class ContainerAlreadyExists(ResourceExists):
message = _("A container with %(field)s %(value)s already exists.")
class ComputeNodeAlreadyExists(ResourceExists):
| 63 | 64 | 25 | 8 | 55 | cooldharma06/zun_glance_tag | zun/common/exception.py | Python | ComputeNodeAlreadyExists | ComputeNodeAlreadyExists | 391 | 392 | 391 | 391 | 243cf5fb3ea29727ec9fc188fba6eb08bec86652 | bigcode/the-stack | train |
cb8d2b7be739ddbb60b7151d | train | class | class NoValidHost(ZunException):
message = _("No valid host was found. %(reason)s")
| class NoValidHost(ZunException):
| message = _("No valid host was found. %(reason)s")
| %(status_reason)s"')
class EntityNotFound(ZunException):
message = _("The %(entity)s (%(name)s) could not be found.")
class CommandError(ZunException):
message = _("The command: %(cmd)s failed on the system.")
class NoValidHost(ZunException):
| 63 | 64 | 22 | 8 | 55 | cooldharma06/zun_glance_tag | zun/common/exception.py | Python | NoValidHost | NoValidHost | 459 | 460 | 459 | 459 | ca546cc4877d935aaeff2aef6fd9cdb3f35e1f27 | bigcode/the-stack | train |
1ccbd415ac55ce80558f1855 | train | class | class AllocationNotFound(HTTPNotFound):
message = _("Allocation %(allocation)s could not be found.")
| class AllocationNotFound(HTTPNotFound):
| message = _("Allocation %(allocation)s could not be found.")
| could not be found.")
class ResourceClassNotFound(HTTPNotFound):
message = _("Resource class %(resource_class)s could not be found.")
class InventoryNotFound(HTTPNotFound):
message = _("Inventory %(inventory)s could not be found.")
class AllocationNotFound(HTTPNotFound):
| 63 | 64 | 22 | 9 | 54 | cooldharma06/zun_glance_tag | zun/common/exception.py | Python | AllocationNotFound | AllocationNotFound | 383 | 384 | 383 | 383 | eb38d53ac8381a3306722313aaf3f5e2682ced14 | bigcode/the-stack | train |
d282e9101122238416f0aa49 | train | class | class PciDeviceWrongAddressFormat(ZunException):
message = _("The PCI address %(address)s has an incorrect format.")
| class PciDeviceWrongAddressFormat(ZunException):
| message = _("The PCI address %(address)s has an incorrect format.")
| ):
message = _("Validation error")
class ResourcesUnavailable(ZunException):
message = _("Insufficient compute resources: %(reason)s.")
class PciConfigInvalidWhitelist(ZunException):
message = _("Invalid PCI devices Whitelist config %(reason)s")
class PciDeviceWrongAddressFormat(ZunException):
| 64 | 64 | 26 | 11 | 53 | cooldharma06/zun_glance_tag | zun/common/exception.py | Python | PciDeviceWrongAddressFormat | PciDeviceWrongAddressFormat | 533 | 534 | 533 | 533 | 4467028a24008ca81f179d3b13a1b362f7036c28 | bigcode/the-stack | train |
6c0a5488c863233d6113ea10 | train | class | class PciDeviceNotFoundById(NotFound):
message = _("PCI device %(id)s not found")
| class PciDeviceNotFoundById(NotFound):
| message = _("PCI device %(id)s not found")
| = _("The PCI address %(address)s has an incorrect format.")
class PciDeviceInvalidDeviceName(ZunException):
message = _("Invalid PCI Whitelist: "
"The PCI whitelist can specify devname or address,"
" but not both")
class PciDeviceNotFoundById(NotFound):
| 64 | 64 | 23 | 11 | 53 | cooldharma06/zun_glance_tag | zun/common/exception.py | Python | PciDeviceNotFoundById | PciDeviceNotFoundById | 543 | 544 | 543 | 543 | 8eefb749ef54ef93d040b004112e913a3d084184 | bigcode/the-stack | train |
daf9818c95dc346eb348f455 | train | class | class ZunException(Exception):
"""Base Zun Exception
To correctly use this class, inherit from it and define
a 'message' property. That message will get printf'd
with the keyword arguments provided to the constructor.
"""
message = _("An unknown exception occurred.")
code = 500
def __... | class ZunException(Exception):
| """Base Zun Exception
To correctly use this class, inherit from it and define
a 'message' property. That message will get printf'd
with the keyword arguments provided to the constructor.
"""
message = _("An unknown exception occurred.")
code = 500
def __init__(self, message=None, **kw... | func(*args, **kwargs)
except keystone_exceptions.AuthorizationFailure:
raise AuthorizationFailure(
client=func.__name__, message="reason: %s" % sys.exc_info()[1])
except keystone_exceptions.ClientException:
raise AuthorizationFailure(
client=func.... | 94 | 94 | 315 | 6 | 87 | cooldharma06/zun_glance_tag | zun/common/exception.py | Python | ZunException | ZunException | 172 | 220 | 172 | 172 | 804d4c501c4f847e2db7edbf67eda62e17d09e66 | bigcode/the-stack | train |
ffc3dd3c49336424edce55e4 | train | class | class EntityNotFound(ZunException):
message = _("The %(entity)s (%(name)s) could not be found.")
| class EntityNotFound(ZunException):
| message = _("The %(entity)s (%(name)s) could not be found.")
| message = _('Went to status %(resource_status)s due to '
'"%(status_reason)s"')
class ServerUnknownStatus(ZunException):
message = _('%(result)s - Unknown status %(resource_status)s due to '
'"%(status_reason)s"')
class EntityNotFound(ZunException):
| 64 | 64 | 26 | 8 | 56 | cooldharma06/zun_glance_tag | zun/common/exception.py | Python | EntityNotFound | EntityNotFound | 451 | 452 | 451 | 451 | e3d3fcf15d5992e8f25d8cf4fff2a8e6aeab6688 | bigcode/the-stack | train |
b1aa9c96c4edbd146f16c857 | train | class | class ObjectNotFound(ZunException):
message = _("The %(name)s %(id)s could not be found.")
| class ObjectNotFound(ZunException):
| message = _("The %(name)s %(id)s could not be found.")
| self.message.encode('utf-8')
def __unicode__(self):
return self.message
def format_message(self):
if self.__class__.__name__.endswith('_Remote'):
return self.args[0]
else:
return six.text_type(self)
class ObjectNotFound(ZunException):
| 64 | 64 | 24 | 8 | 56 | cooldharma06/zun_glance_tag | zun/common/exception.py | Python | ObjectNotFound | ObjectNotFound | 223 | 224 | 223 | 223 | 39ec574713ca50b30ef83b335a088a26a28678ff | bigcode/the-stack | train |
7aeb3d8e22c61b17c332621e | train | class | class InvalidWebsocketToken(ZunException):
message = _("Websocket token is invalid")
| class InvalidWebsocketToken(ZunException):
| message = _("Websocket token is invalid")
| with another versions.")
class ConnectionFailed(ZunException):
message = _("Failed to connect to remote host")
class SocketException(ZunException):
message = _("Socket exceptions")
class InvalidWebsocketUrl(ZunException):
message = _("Websocket Url invalid")
class InvalidWebsocketToken(ZunException):
| 64 | 64 | 19 | 9 | 55 | cooldharma06/zun_glance_tag | zun/common/exception.py | Python | InvalidWebsocketToken | InvalidWebsocketToken | 517 | 518 | 517 | 517 | ef8558b03aef7b91f5bb73abcb15864152d637a3 | bigcode/the-stack | train |
73e4560a4603fe68a11426d1 | train | class | class ClassNotFound(NotFound):
message = _("Class %(class_name)s could not be found: %(exception)s")
| class ClassNotFound(NotFound):
| message = _("Class %(class_name)s could not be found: %(exception)s")
| inned CPU set %(pinned)s")
class NotFound(ZunException):
message = _("Resource could not be found.")
code = 404
class SchedulerHostFilterNotFound(NotFound):
message = _("Scheduler Host Filter %(filter_name)s could not be found.")
class ClassNotFound(NotFound):
| 63 | 64 | 25 | 7 | 56 | cooldharma06/zun_glance_tag | zun/common/exception.py | Python | ClassNotFound | ClassNotFound | 496 | 497 | 496 | 496 | ef90541a69eee9d3613fb82e780245668728acef | bigcode/the-stack | train |
1dc14e7abed9a4fe78428e6d | train | class | class ObjectNotUnique(ZunException):
message = _("The %(name)s already exists.")
| class ObjectNotUnique(ZunException):
| message = _("The %(name)s already exists.")
| ):
if self.__class__.__name__.endswith('_Remote'):
return self.args[0]
else:
return six.text_type(self)
class ObjectNotFound(ZunException):
message = _("The %(name)s %(id)s could not be found.")
class ObjectNotUnique(ZunException):
| 63 | 64 | 19 | 8 | 55 | cooldharma06/zun_glance_tag | zun/common/exception.py | Python | ObjectNotUnique | ObjectNotUnique | 227 | 228 | 227 | 227 | ac6af60dc91626063963ce4df78d4bdb35a98026 | bigcode/the-stack | train |
8fe4d50548e2f40a2297d868 | train | class | class CommandError(ZunException):
message = _("The command: %(cmd)s failed on the system.")
| class CommandError(ZunException):
| message = _("The command: %(cmd)s failed on the system.")
| (ZunException):
message = _('%(result)s - Unknown status %(resource_status)s due to '
'"%(status_reason)s"')
class EntityNotFound(ZunException):
message = _("The %(entity)s (%(name)s) could not be found.")
class CommandError(ZunException):
| 63 | 64 | 22 | 7 | 56 | cooldharma06/zun_glance_tag | zun/common/exception.py | Python | CommandError | CommandError | 455 | 456 | 455 | 455 | 881691006194662bc6a8d3c2877f27f10aba65ae | bigcode/the-stack | train |
ff922b363ad1fd1aecca731d | train | class | class InvalidState(Conflict):
message = _("Invalid resource state.")
| class InvalidState(Conflict):
| message = _("Invalid resource state.")
| uuid or int but received %(identity)s.")
class InvalidCsr(Invalid):
message = _("Received invalid csr %(csr)s.")
class HTTPNotFound(ResourceNotFound):
pass
class Conflict(ZunException):
message = _('Conflict.')
code = 409
class InvalidState(Conflict):
| 64 | 64 | 14 | 6 | 57 | cooldharma06/zun_glance_tag | zun/common/exception.py | Python | InvalidState | InvalidState | 312 | 313 | 312 | 312 | ba30f7790e5a528eb588e916060d6b958a28cd1c | bigcode/the-stack | train |
4d18e92dfbd5ccf9bcdc2a91 | train | class | class SchemaValidationError(ValidationError):
message = "%(detail)s"
| class SchemaValidationError(ValidationError):
| message = "%(detail)s"
| Exception):
message = _("Unacceptable parameters.")
code = 400
class InvalidValue(Invalid):
message = _("Received value '%(value)s' is invalid for type %(type)s.")
class ValidationError(Invalid):
message = "%(detail)s"
class SchemaValidationError(ValidationError):
| 64 | 64 | 16 | 8 | 56 | cooldharma06/zun_glance_tag | zun/common/exception.py | Python | SchemaValidationError | SchemaValidationError | 270 | 271 | 270 | 270 | f128cf5553b87fbbfa16680e82506cb46f46f1f6 | bigcode/the-stack | train |
5927c2d3cdcf11e903827a05 | train | class | class SchedulerHostFilterNotFound(NotFound):
message = _("Scheduler Host Filter %(filter_name)s could not be found.")
| class SchedulerHostFilterNotFound(NotFound):
| message = _("Scheduler Host Filter %(filter_name)s could not be found.")
| (Invalid):
message = _("CPU set to unpin %(requested)s must be a subset of "
"pinned CPU set %(pinned)s")
class NotFound(ZunException):
message = _("Resource could not be found.")
code = 404
class SchedulerHostFilterNotFound(NotFound):
| 64 | 64 | 25 | 9 | 54 | cooldharma06/zun_glance_tag | zun/common/exception.py | Python | SchedulerHostFilterNotFound | SchedulerHostFilterNotFound | 492 | 493 | 492 | 492 | c864cf15c9f47b7eafc18fbde2415703123b1b38 | bigcode/the-stack | train |
def6a6dff65909caa8bc0bc3 | train | class | class AuthorizationFailure(ZunException):
message = _("%(client)s connection failed. %(message)s")
| class AuthorizationFailure(ZunException):
| message = _("%(client)s connection failed. %(message)s")
| )
class ResourceNotFound(ObjectNotFound):
message = _("The %(name)s resource %(id)s could not be found.")
code = 404
class ResourceExists(ObjectNotUnique):
message = _("The %(name)s resource already exists.")
code = 409
class AuthorizationFailure(ZunException):
| 64 | 64 | 22 | 7 | 56 | cooldharma06/zun_glance_tag | zun/common/exception.py | Python | AuthorizationFailure | AuthorizationFailure | 241 | 242 | 241 | 241 | 0323aad9913bd53ff13294522ba9b2c86051ce81 | bigcode/the-stack | train |
102748207d1739a403801bb6 | train | class | class ServerInError(ZunException):
message = _('Went to status %(resource_status)s due to '
'"%(status_reason)s"')
| class ServerInError(ZunException):
| message = _('Went to status %(resource_status)s due to '
'"%(status_reason)s"')
| container %(id)s in %(actual_state)s state")
code = 409
class DockerError(ZunException):
message = _("Docker internal error: %(error_msg)s.")
class PollTimeOut(ZunException):
message = _("Polling request timed out.")
class ServerInError(ZunException):
| 63 | 64 | 30 | 8 | 55 | cooldharma06/zun_glance_tag | zun/common/exception.py | Python | ServerInError | ServerInError | 441 | 443 | 441 | 441 | 470253aef1888677f9038d6382c408ecb012998d | bigcode/the-stack | train |
6fa20a51a67caf4aa1794c67 | train | class | class ImageAlreadyExists(ResourceExists):
message = _("An image with tag %(tag)s and repo %(repo)s already exists.")
| class ImageAlreadyExists(ResourceExists):
| message = _("An image with tag %(tag)s and repo %(repo)s already exists.")
| )s could not be found.")
class ContainerAlreadyExists(ResourceExists):
message = _("A container with %(field)s %(value)s already exists.")
class ComputeNodeAlreadyExists(ResourceExists):
message = _("A compute node with %(field)s %(value)s already exists.")
class ImageAlreadyExists(ResourceExists):
| 63 | 64 | 26 | 7 | 56 | cooldharma06/zun_glance_tag | zun/common/exception.py | Python | ImageAlreadyExists | ImageAlreadyExists | 395 | 396 | 395 | 395 | 76121af1ccf6f8d390e63652065c71a733b6d7c8 | bigcode/the-stack | train |
27d9291c60fc172c6b53a80f | train | class | class ResourceNotFound(ObjectNotFound):
message = _("The %(name)s resource %(id)s could not be found.")
code = 404
| class ResourceNotFound(ObjectNotFound):
| message = _("The %(name)s resource %(id)s could not be found.")
code = 404
| ]
else:
return six.text_type(self)
class ObjectNotFound(ZunException):
message = _("The %(name)s %(id)s could not be found.")
class ObjectNotUnique(ZunException):
message = _("The %(name)s already exists.")
class ResourceNotFound(ObjectNotFound):
| 63 | 64 | 31 | 8 | 55 | cooldharma06/zun_glance_tag | zun/common/exception.py | Python | ResourceNotFound | ResourceNotFound | 231 | 233 | 231 | 231 | 86b1de9298bf69f4efc8ea30e64b3b7c8395f920 | bigcode/the-stack | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.