qmtensor

classes/tensors

class qmetro.qmtensor.classes.tensors.ConstTensor(spaces, choi=None, sdict=<qmetro.qmtensor.classes.tensors.SpaceDict object>, array=None, name=None, output_spaces=None, comb_structure=None)[source]

Bases: GeneralTensor

Class of tensors that are constant during the optimization.

Parameters:
  • spaces (list[Hashable]) – Tensor spaces.

  • choi (np.ndarray | None, optional) – Choi matrix which from which the tensor will be constructed. If None then it will be initialized from the array argument, by default None.

  • sdict (SpaceDict, optional) – Space dictionary, by default DEFAULT_SDICT.

  • array (np.ndarray | None, optional) – Tensor as numpy array, by default None.

  • name (str | None, optional) – Tensor name, by default None.

  • output_spaces (list[Hashable] | None, optional) – Tensor output spaces, by default None.

  • comb_structure (list[tuple[list[Hashable], list[Hashable]]] | None) – Comb (causal) structure in a form of [(input_0, output_0), (input_1, output_1), …] where input_i (output_i) is a list of input (output) spaces of the i-th tooth.

array

Tensor as numpy array. The order of indices corresponds to the order of spaces in self.spaces.

Type:

np.ndarray

Attributes:
comb_structure

Comb (causal) structure in a form of

dimensions

Dimensions of the tensor spaces.

input_dim

Input dimension, that is the product of the all input spaces dimensions.

input_spaces

List of the input spaces.

is_choi_like

Whether the tensor is Choi-like.

is_comb

Whether the tensor has comb (causal) structure.

output_dim

Output dimension, that is the product of the all output spaces dimensions.

output_spaces

List of the output spaces.

shape

Tensor shape, that is index ranges of self.spaces.

Parameters:
  • spaces (list[Hashable])

  • choi (np.ndarray | None)

  • sdict (SpaceDict)

  • array (np.ndarray | None)

  • name (str | None)

  • output_spaces (list[Hashable] | None)

  • comb_structure (list[tuple[list[Hashable], list[Hashable]]] | None)

Methods

choi(spaces)

Compute Choi matrix for the Choi-like tensor.

choi_T(*spaces[, full])

Computes partial transposition of Choi-like tensor and for other tensors it does transpose-like reshuffling of entries on physcial spaces.

choi_matmul(other)

For two Choi-like tensors compute the tensor of their Choi matrices multiplication.

choi_trace(*spaces[, full])

For Choi-like tensor compute partial trace of the Choi matrix and return its tensor form.

choi_transpose(*spaces[, full])

Computes partial transposition of Choi-like tensor and for other tensors it does transpose-like reshuffling of entries on physcial spaces.

contr(*others)

Contract tensors.

copy()

Make a copy.

from_mps(array, spaces[, sdict, ...])

Computess a constant tensor of density MPO element from the array of MPS element.

krauses([input_spaces, output_spaces])

Computes Kraus operators of the Choi matrix of the Choi-like tensor.

kron(*others)

For Choi-like tensors it computes their Kronecker product and for other tensors it is just contraction where there are no doubled indices (no index gets contracted).

reorder(new_spaces)

Change the order of spaces.

respace([spaces, space_map, sdict, name, ...])

Make a copy of self but with renamed spaces.

square_without(spaces)

Computes Choi matrix square on spaces different than given spaces.

to_mps(spaces[, cutoff])

Converts tensor form of density MPO component into MPS component(s).

to_qchannel([input_spaces, output_spaces])

Returns a quantum channel of the Choi matrix of the Choi-like tensor.

update_choi(spaces, matrix)

Set tensor entries to make it Choi matrix equal to the given matrix.

choi(spaces)[source]

Compute Choi matrix for the Choi-like tensor.

Parameters:
  • spaces (list[Hashable]) – List of spaces defining the order of spaces of the result.

  • self (ConstTensor)

Returns:

matrix – Choi matrix.

Return type:

np.ndarray

choi_T(*spaces, full=False)[source]

Computes partial transposition of Choi-like tensor and for other tensors it does transpose-like reshuffling of entries on physcial spaces.

Parameters:
  • full (bool, optional) – If True tranposes all spaces, by default False.

  • spaces (Hashable)

Returns:

transpostion – Tensor of the transposed matrix.

Return type:

ConstTensor

choi_matmul(other)[source]

For two Choi-like tensors compute the tensor of their Choi matrices multiplication.

Parameters:

other (ConstTensor) – Tensor to multiply.

Returns:

product – Tensor of the product.

Return type:

ConstTensor

choi_trace(*spaces, full=False)[source]

For Choi-like tensor compute partial trace of the Choi matrix and return its tensor form.

Parameters:
  • spaces[0...*] (Hashable) – Spaces to be traced out.

  • full (bool, optional) – If True then computes the trace over all spaces and returns a complex number, by default False.

  • spaces (Hashable)

Returns:

tensor – Tensor form of the result.

Return type:

Tensor | complex

choi_transpose(*spaces, full=False)[source]

Computes partial transposition of Choi-like tensor and for other tensors it does transpose-like reshuffling of entries on physcial spaces.

Parameters:
  • full (bool, optional) – If True tranposes all spaces, by default False.

  • spaces (Hashable)

Returns:

transpostion – Tensor of the transposed matrix.

Return type:

ConstTensor

contr_count = 0
copy()[source]

Make a copy.

Returns:

copy – Tensor copy.

Return type:

ConstTensor

static from_mps(array, spaces, sdict=<qmetro.qmtensor.classes.tensors.SpaceDict object>, output_spaces=None, name=None)[source]

Computess a constant tensor of density MPO element from the array of MPS element.

Parameters:
  • array (np.ndarray) – Array of MPS element.

  • spaces (list[Hashable]) – Array’s order of spaces.

  • sdict (SpaceDict, optional) – Space dictionary, by default DEFAULT_SDICT.

  • output_spaces (list[Hashable] | None, optional) – Output spaces, by default None.

  • name (str | None, optional) – New tensor name, by default None.

Returns:

tensor – Density MPO element.

Return type:

ConstTensor

krauses(input_spaces=None, output_spaces=None)[source]

Computes Kraus operators of the Choi matrix of the Choi-like tensor.

Parameters:
  • input_spaces (list[Hashable] | None, optional) – Input spaces. If None then self.input_spaces, by default None.

  • output_spaces (list[Hashable] | None, optional) – Output spaces. If None then self.output_spaces, by default None.

Returns:

krauses – List of Kraus operators.

Return type:

list[np.ndarray]

name_prefix = 'CONST TENSOR '
reorder(new_spaces)[source]

Change the order of spaces.

Parameters:

new_spaces (list[Hashable]) – Spaces names in the new order.

Returns:

self – self

Return type:

ConstTensor

respace(spaces=None, space_map=None, sdict=None, name=None, make_copy=False)[source]

Make a copy of self but with renamed spaces.

Parameters:
  • spaces (list[Hashable] | None, optional) – The change of spaces will take the form self.spaces[i] -> spaces[i]. If None then change of spaces will be carried out using space_map, by default None.

  • space_map (Callable[[Hashable], Hashable] | None, optional) – The change of spaces will take the form space -> space_map(space), by default None

  • sdict (SpaceDict | None, optional) – Space dictionary of the copy. If None then it will be self.sdict, by default None.

  • name (str | None, optional) – Name of the copy. If None then it will be self.name, by default None.

  • make_copy (bool, optional) – Whether to make a copy of self.array, by default False.

Returns:

copy – New tensor with renamed spaces.

Return type:

ConstTensor

square_without(spaces)[source]

Computes Choi matrix square on spaces different than given spaces.

For tensor T[a0, a1, a2, a3] and spaces [a0, a1] computes a new tensor U such that

U[a0, a1].choi == T[a0, a1].choi @ T[a0, a1].choi.

It can be used to compute matrix squares for tensor networks. For example for physcial spaces p0, p1 and bond space b0 and tensors:

V[p0, p1] = T[p0, b0] * U[b0, p1],

it satifies:

V.choi([p0, p1]) @ V.choi([p0, p1]) == (T.square_wiyhout([b0]) * U.square_wiyhout([b0])).choi([p0, p1]).

Note that this requires T.square_wiyhout([b0]) to have two b0 spaces. This is solved by adding b0’ space using SpaceDictionar primed method.

Only physical spaces can be squared.

Parameters:

spaces (list[Hashable]) – Spaces to be omitted.

Returns:

tensor – Matrix square without given spaces.

Return type:

ConstTensor

to_mps(spaces, cutoff=1e-10)[source]

Converts tensor form of density MPO component into MPS component(s).

Parameters:
  • spaces (list[Hashable]) – Order of spaces for the result.

  • cutoff (float, optional) – Cutoff for small eigenvalues. The default is 1e-10.

Returns:

List of MPS components. Each component is a numpy array of shape (sqrt(range_s) for s in spaces). For pure states it should be a list of length 1.

Return type:

list[np.ndarray]

to_qchannel(input_spaces=None, output_spaces=None)[source]

Returns a quantum channel of the Choi matrix of the Choi-like tensor.

Parameters:
  • input_spaces (list[Hashable] | None, optional) – Input spaces. If None then self.input_spaces, by default None.

  • output_spaces (list[Hashable] | None, optional) – Output spaces. If None then self.output_spaces, by default None.

Returns:

channel – Quantum channel of the Choi matrix.

Return type:

Callable[[np.ndarray], ConstTensor]

update_choi(spaces, matrix)[source]

Set tensor entries to make it Choi matrix equal to the given matrix.

Parameters:
  • spaces (list[Hashable]) – Spaces names,

  • matrix (np.ndarray) – Choi matrix.

class qmetro.qmtensor.classes.tensors.GeneralTensor(spaces, sdict=<qmetro.qmtensor.classes.tensors.SpaceDict object>, name=None, output_spaces=None, comb_structure=None)[source]

Bases: object

Generalized tensor class.

Parameters:
  • spaces (list[Hashable]) – Tensor spaces.

  • sdict (SpaceDict, optional) – Space dictionary, by default DEFAULT_SDICT.

  • name (str | None, optional) – Tensor name, by default None.

  • output_spaces (list[Hashable] | None, optional) – Tensor output spaces, by default None

  • comb_structure (list[tuple[list[Hashable], list[Hashable]]] | None) – Comb (causal) structure in a form of [(input_0, output_0), (input_1, output_1), …] where input_i (output_i) is a list of input (output) spaces of the i-th tooth.

spaces

List of all tensor spaces.

Type:

list[Hashable]

sdict

Space dictionary.

Type:

SpaceDict

name

Tensor name.

Type:

str

physical_spaces

List of physical spaces.

Type:

list[Hashable]

bond_spaces

List of bond spaces.

Type:

list[Hashable]

dimension

Product of dimensions of all tensor spaces.

Type:

int

physical_dim

Product of dimensions of physical spaces.

Type:

int

Attributes:
comb_structure

Comb (causal) structure in a form of

dimensions

Dimensions of the tensor spaces.

input_dim

Input dimension, that is the product of the all input spaces dimensions.

input_spaces

List of the input spaces.

is_choi_like

Whether the tensor is Choi-like.

is_comb

Whether the tensor has comb (causal) structure.

output_dim

Output dimension, that is the product of the all output spaces dimensions.

output_spaces

List of the output spaces.

shape

Tensor shape, that is index ranges of self.spaces.

Parameters:
  • spaces (list[Hashable])

  • sdict (SpaceDict)

  • name (str | None)

  • output_spaces (list[Hashable] | None)

  • comb_structure (list[tuple[list[Hashable], list[Hashable]]] | None)

Methods

choi_trace(*spaces[, full])

For Choi-like tensor compute partial trace of the Choi matrix.

contr(*others)

Contract tensors.

copy()

Make a copy.

kron(*others)

For Choi-like tensors it computes their Kronecker product and for other tensors it is just contraction where there are no doubled indices (no index gets contracted).

respace([spaces, space_map, sdict, name])

Make a copy of self but with renamed spaces.

bond_spaces: list[Hashable]
choi_trace(*spaces, full=False)[source]

For Choi-like tensor compute partial trace of the Choi matrix.

Parameters:
  • spaces[0...*] (Hashable) – Spaces to be traced out.

  • full (bool, optional) – If True then computes the trace over all spaces and returns a complex number, by default False.

  • spaces (Hashable)

Returns:

tensor – Tensor of the result.

Return type:

Tensor | complex

property comb_structure: list[tuple[list[Hashable], list[Hashable]]] | None

Comb (causal) structure in a form of

[(input_0, output_0), (input_1, output_1), ...],

where input_i (output_i) is a list of input (output) spaces of the i-th tooth.

Returns:

Comb structure.

Return type:

list[tuple[list[Hashable], list[Hashable]]] | None

contr(*others)[source]

Contract tensors.

Parameters:
Returns:

tensor – Contraction result.

Return type:

Tensor

copy()[source]

Make a copy.

Returns:

copy – Tensor copy.

Return type:

Tensor

counter = 0
property dimensions: list[int]

Dimensions of the tensor spaces.

Returns:

dims – List of dimensions of self.spaces.

Return type:

list[int]

property input_dim: int

Input dimension, that is the product of the all input spaces dimensions.

Returns:

dim – Input dimension.

Return type:

int

property input_spaces: list[Hashable]

List of the input spaces.

Returns:

input_spaces – List of input spaces.

Return type:

list[Hashable]

property is_choi_like: bool

Whether the tensor is Choi-like. The tensor is Choi-like if all its spaces are physical.

Returns:

is_choi_like – Whether the tensor is Choi-like.

Return type:

bool

property is_comb: bool

Whether the tensor has comb (causal) structure.

Returns:

is_comb – Whether the tensor has comb structure.

Return type:

bool

kron(*others)[source]

For Choi-like tensors it computes their Kronecker product and for other tensors it is just contraction where there are no doubled indices (no index gets contracted).

Parameters:
Returns:

tensor – Kronecker product.

Return type:

Tensor

name_prefix = 'GENERAL TENSOR '
property output_dim: int

Output dimension, that is the product of the all output spaces dimensions.

Returns:

dim – Output dimension.

Return type:

int

property output_spaces: list[Hashable]

List of the output spaces.

Returns:

output_spaces – List of output spaces.

Return type:

list[Hashable]

physical_spaces: list[Hashable]
respace(spaces=None, space_map=None, sdict=None, name=None)[source]

Make a copy of self but with renamed spaces.

Parameters:
  • spaces (list[Hashable] | None, optional) – The change of spaces will take the form self.spaces[i] -> spaces[i]. If None then change of spaces will be carried out using space_map, by default None.

  • space_map (Callable[[Hashable], Hashable] | None, optional) – The change of spaces will take the form space -> space_map(space), by default None

  • sdict (SpaceDict | None, optional) – Space dictionary of the copy. If None then it will be self.sdict, by default None.

  • name (str | None, optional) – Name of the copy. If None then it will be self.name, by default None.

  • self (GeneralTensor)

Returns:

copy – New tensor with renamed spaces.

Return type:

GeneralTensor

property shape: tuple[int, ...]

Tensor shape, that is index ranges of self.spaces.

Returns:

shape – Tensor shape.

Return type:

tuple[int, …]

class qmetro.qmtensor.classes.tensors.ParamTensor(spaces, choi=None, sdict=<qmetro.qmtensor.classes.tensors.SpaceDict object>, array=None, name=None, dchoi=None, darray=None, output_spaces=None, comb_structure=None)[source]

Bases: ConstTensor

Class of parametrised tensor. It is a const tensor with additional attribute dtensor which represents its derivative in the parameter at the point.

Parameters:
  • spaces (list[Hashable]) – Tensor spaces.

  • choi_matrix (np.ndarray | None, optional) – Choi matrix which from which the tensor will be constructed. If None then it will be initialized from the array argument, by default None.

  • sdict (SpaceDict, optional) – Space dictionary, by default DEFAULT_SDICT.

  • array (np.ndarray | None, optional) – Tensor as numpy array, by default None.

  • name (str | None, optional) – Tensor name, by default None.

  • dchoi_matrix (np.ndarray | None, optional) – Choi matrix which from which the dtensor will be constructed. If None then it will be initialized from the darray argument, by default None.

  • darray (np.ndarray | None, optional) – Derivative as numpy array, by default None.

  • output_spaces (list[Hashable] | None, optional) – Tensor output spaces, by default None.

  • comb_structure (list[tuple[list[Hashable], list[Hashable]]] | None) – Comb (causal) structure in a form of [(input_0, output_0), (input_1, output_1), ...] where input_i (output_i) is a list of input (output) spaces of the i-th tooth.

  • choi (np.ndarray | None)

  • dchoi (np.ndarray | None)

dtensor

Tensor representing the derivative.

Type:

ConstTensor

Attributes:
comb_structure

Comb (causal) structure in a form of

dimensions

Dimensions of the tensor spaces.

input_dim

Input dimension, that is the product of the all input spaces dimensions.

input_spaces

List of the input spaces.

is_choi_like

Whether the tensor is Choi-like.

is_comb

Whether the tensor has comb (causal) structure.

output_dim

Output dimension, that is the product of the all output spaces dimensions.

output_spaces

List of the output spaces.

shape

Tensor shape, that is index ranges of self.spaces.

Parameters:
  • spaces (list[Hashable])

  • choi (np.ndarray | None)

  • sdict (SpaceDict)

  • array (np.ndarray | None)

  • name (str | None)

  • dchoi (np.ndarray | None)

  • darray (np.ndarray | None)

  • output_spaces (list[Hashable] | None)

  • comb_structure (list[tuple[list[Hashable], list[Hashable]]] | None)

Methods

choi(spaces)

Compute Choi matrix for the Choi-like tensor.

choi_T(*spaces[, full])

Computes partial transposition of Choi-like tensor and for other tensors it does transpose-like reshuffling of entries on physcial spaces.

choi_matmul(other)

For two Choi-like tensors compute the tensor of their Choi matrices multiplication.

choi_trace(*spaces[, full])

For Choi-like tensor compute partial trace of the Choi matrix and return its tensor form.

choi_transpose(*spaces[, full])

Computes partial transposition of Choi-like tensor and for other tensors it does transpose-like reshuffling of entries on physcial spaces.

contr(*others)

Contract tensors.

copy()

Make a copy.

dchoi(spaces)

Compute derivative of Choi matrix for the Choi-like tensor.

dkrauses([input_spaces, output_spaces])

Computes Kraus operatiors of the Choi matrix of the Choi-like tensor.

from_const(tensor[, name])

Get a parametrized tensor from a constant tensor.

from_mps(array, spaces[, sdict, ...])

Computess a constant tensor of density MPO element from the array of MPS element.

krauses([input_spaces, output_spaces])

Computes Kraus operators of the Choi matrix of the Choi-like tensor.

kron(*others)

For Choi-like tensors it computes their Kronecker product and for other tensors it is just contraction where there are no doubled indices (no index gets contracted).

reorder(new_spaces)

Change the order of spaces.

respace([spaces, space_map, sdict, name, ...])

Make a copy of self but with renamed spaces.

square_without(spaces)

Computes Choi matrix square on spaces different than given spaces.

to_const(tensor[, name])

Discards the derivative and returns the constant tensor.

to_mps(spaces[, cutoff])

Converts tensor form of density MPO component into MPS component(s).

to_qchannel([input_spaces, output_spaces])

Returns a quantum channel of the Choi matrix of the Choi-like tensor.

update_choi(spaces, matrix)

Set tensor entries to make it Choi matrix equal to the given matrix.

choi_transpose(*spaces, full=False)[source]

Computes partial transposition of Choi-like tensor and for other tensors it does transpose-like reshuffling of entries on physcial spaces.

Parameters:
  • full (bool, optional) – If True tranposes all spaces, by default False.

  • spaces (Hashable)

Returns:

transpostion – Tensor of the transposed matrix.

Return type:

ParamTensor

property comb_structure: list[tuple[list[Hashable], list[Hashable]]] | None

Comb (causal) structure in a form of

[(input_0, output_0), (input_1, output_1), ...],

where input_i (output_i) is a list of input (output) spaces of the i-th tooth.

Returns:

Comb structure.

Return type:

list[tuple[list[Hashable], list[Hashable]]] | None

copy()[source]

Make a copy.

Returns:

copy – Tensor copy.

Return type:

ParamTensor

dchoi(spaces)[source]

Compute derivative of Choi matrix for the Choi-like tensor.

Parameters:

spaces (list[Hashable]) – List of spaces defining the order of spaces of the result.

Returns:

matrix – Derivative of Choi matrix.

Return type:

np.ndarray

dkrauses(input_spaces=None, output_spaces=None)[source]

Computes Kraus operatiors of the Choi matrix of the Choi-like tensor.

Parameters:
  • input_spaces (list[Hashable] | None, optional) – Input spaces. If None then self.input_spaces, by default None.

  • output_spaces (list[Hashable] | None, optional) – Output spaces. If None then self.output_spaces, by default None.

Returns:

  • krauses (list[np.ndarray]) – List of Kraus operators.

  • dkrause L list[np.ndarray] – List of derivatives of Kraus operators.

Return type:

tuple[list[ndarray], list[ndarray]]

dtensor: ConstTensor
static from_const(tensor, name=None)[source]

Get a parametrized tensor from a constant tensor. The derivative is assumed to be 0.

Parameters:
  • tensor (ConstTensor) – Conastant tensor.

  • name (str | None, optional) – Tensor name. If None then tensor.name, by default None.

Returns:

tensor – The same tensor but with defined derivative.

Return type:

ParamTensor

property input_spaces: list[Hashable]

List of the input spaces.

Returns:

input_spaces – List of input spaces.

Return type:

list[Hashable]

name_prefix = 'PARAM TENSOR '
property output_spaces: list[Hashable]

List of the output spaces.

Returns:

output_spaces – List of output spaces.

Return type:

list[Hashable]

reorder(new_spaces)[source]

Change the order of spaces.

Parameters:

new_spaces (list[Hashable]) – Spaces names in the new order.

Returns:

self – self

Return type:

ParamTensor

respace(spaces=None, space_map=None, sdict=None, name=None, make_copy=False)[source]

Make a copy of self but with renamed spaces.

Parameters:
  • spaces (list[Hashable] | None, optional) – The change of spaces will take the form self.spaces[i] -> spaces[i]. If None then change of spaces will be carried out using space_map, by default None.

  • space_map (Callable[[Hashable], Hashable] | None, optional) – The change of spaces will take the form space -> space_map(space), by default None

  • sdict (SpaceDict | None, optional) – Space dictionary of the copy. If None then it will be self.sdict, by default None.

  • name (str | None, optional) – Name of the copy. If None then it will be self.name, by default None.

  • make_copy (bool, optional) – Whether to make a copy of self.array and self.dtensor.array, by default False.

Returns:

copy – New tensor with renamed spaces.

Return type:

ParamTensor

square_without(spaces)[source]

Computes Choi matrix square on spaces different than given spaces.

For tensor T[a0, a1, a2, a3] and spaces [a0, a1] computes a new tensor U such that

U[a0, a1].choi == T[a0, a1].choi @ T[a0, a1].choi.

It can be used to compute matrix squares for tensor networks. For example for physcial spaces p0, p1 and bond space b0 and tensors:

V[p0, p1] = T[p0, b0] * U[b0, p1],

it satifies:

V.choi([p0, p1]) @ V.choi([p0, p1]) == (T.square_wiyhout([b0]) * U.square_wiyhout([b0])).choi([p0, p1]).

Note that this requires T.square_wiyhout([b0]) to have two b0 spaces. This is solved by adding b0’ space using SpaceDictionar primed method.

Only physical spaces can be squared.

Parameters:

spaces (list[Hashable]) – Spaces to be omitted.

Returns:

tensor – Matrix square without given spaces.

Return type:

ConstTensor

static to_const(tensor, name=None)[source]

Discards the derivative and returns the constant tensor.

Parameters:
  • tensor (ParamTensor | ConstTensor) – Parametrized or constant tensor.

  • name (str | None, optional) – Tensor name. If None then tensor.name, by default None.

Returns:

tensor – Tensor without the derivative.

Return type:

ConstTensor

class qmetro.qmtensor.classes.tensors.SpaceDict(name='')[source]

Bases: object

Dictionary connecting spaces to their dimensions.

Parameters:

name (str, optional) – Name of the dictionary. If equal to ‘’ then the name will be set to a number of previously existing quantum system. By default ‘’.

name

Name of the dictionary.

Type:

str

spaces

Dictionary connecting spaces to their dimensions.

Type:

dict[Hashable, int]

bond_spaces

Set of bond spaces.

Type:

set[Hashable]

prime

Suffix for primed spaces.

Type:

str

primed_spaces

Dictionary connecting primed spaces to unprimed ones.

Type:

dict[Hashable, Hashable]

Attributes:
irange

Index range of spaces.

Parameters:

name (str)

Methods

arrange_bonds(shape, dim[, prefix])

Add spaces with names:

arrange_spaces(shape, dim[, prefix])

Add spaces with names:

choi_identity([spaces])

Creates Choi-like constant tensor of identity matrix with sdict=self.

ctensor(spaces, **kwargs)

Creates constant tensor with sdict=self.

get_dimension(space)

Get space dimension.

make_primed(*spaces)

Adds given spaces to the dictionary of primed spaces (self.primed_spaces).

primed(space)

For spaces returns space' where space' = (space, self.prime).

set_bond(space, dim)

Set space dimension and mark it as bond space.

set_dimension(space, dimension)

Set space dimension.

unprimed(space)

If space' is in self returns space else returns space.

zero([spaces])

Creates constant tensor filled with zeros with sdict=self.

arrange_bonds(shape, dim, prefix='BOND')[source]

Add spaces with names:

(prefix, i_0, …, i_r)

for i_k = 0, …, n_k and mark them as bond spaces.

Parameters:
  • shape (int | tuple[int, ...]) – Shape of the index tuple (n_0, …, n_r).

  • dim (int) – Dimension of added spaces.

  • prefix (Hashable, optional) – Prefix, by default ‘BOND’.

Returns:

r-dimensional list of spaces names.

Return type:

list

arrange_spaces(shape, dim, prefix='SPACE')[source]

Add spaces with names:

(prefix, i_0, …, i_r)

for i_k = 0, …, n_k.

Parameters:
  • shape (int | tuple[int, ...]) – Shape of the index tuple (n_0, …, n_r).

  • dim (int) – Dimension of added spaces.

  • prefix (Hashable, optional) – Prefix, by default ‘SPACE’.

Returns:

r-dimensional list of spaces names.

Return type:

list

choi_identity(spaces=None, **kwargs)[source]

Creates Choi-like constant tensor of identity matrix with sdict=self.

Parameters:
  • spaces (list[Hashable] | None) – Tensor spaces, by default empty list.

  • **kwargs – Key-word arguments passed to ConstTensor constructor.

Returns:

tensor – Choi-like constant tensor of identity matrix.

Return type:

ConstTensor

counter = 0
ctensor(spaces, **kwargs)[source]

Creates constant tensor with sdict=self.

Parameters:
  • spaces (list[Hashable]) – Tensor spaces.

  • **kwargs – Key-word arguments passed to ConstTensor constructor.

Returns:

tensor – Added tensor.

Return type:

ConstTensor

get_dimension(space)[source]

Get space dimension.

Parameters:

space (str) – Space name.

Returns:

dim – Space dimension.

Return type:

int

property irange: dict[Hashable, int]

Index range of spaces. Index range for physical space is its dimension squared and for bond space it is just its dimension.

Returns:

irange – Dictionary of spaces and their ranges.

Return type:

dict[Hashable, int]

make_primed(*spaces)[source]

Adds given spaces to the dictionary of primed spaces (self.primed_spaces).

Parameters:

spaces (Hashable)

primed(space)[source]

For spaces returns space’ where space’ = (space, self.prime).

Parameters:

space (Hashable) – Space name.

Returns:

new_space – New space (space’).

Return type:

Hashable

primed_spaces: dict[Hashable, Hashable]
set_bond(space, dim)[source]

Set space dimension and mark it as bond space.

Parameters:
  • space (Hashable) – Space name.

  • dimension (int) – Space dimension.

  • dim (int)

set_dimension(space, dimension)[source]

Set space dimension.

Parameters:
  • space (Hashable) – Space name.

  • dimension (int) – Space dimension.

spaces: dict[Hashable, int]
unprimed(space)[source]

If space’ is in self returns space else returns space.

Parameters:

space (Hashable) – Space name.

Returns:

unprimed_space – Space name without a prime.

Return type:

Hashable

zero(spaces=None, **kwargs)[source]

Creates constant tensor filled with zeros with sdict=self.

Parameters:
  • spaces (list[Hashable]) – Tensor spaces, by default empty list.

  • **kwargs – Key-word arguments passed to ConstTensor constructor.

Returns:

tensor – Zero const tensor.

Return type:

ConstTensor

class qmetro.qmtensor.classes.tensors.TensorNetwork(tensors=None, sdict=<qmetro.qmtensor.classes.tensors.SpaceDict object>, name=None)[source]

Bases: GeneralTensor

Class of tensor network.

Parameters:
  • tensors (list[GeneralTensor | Scalar] | None, optional) – Nodes of the network (or other network), by default None.

  • sdict (SpaceDict, optional) – Space dictionary, by default DEFAULT_SDICT.

  • name (str | None, optional) – Network name, by default None.

tensors

Dictionary of tensors in the network where keys are tensor names and values are tensors.

Type:

dict[str, ConstTensor | ParamTensor | VarTensor]

edges

Dictionary of edges where keys are space names and values are lists of tensor names connected by the edge.

Type:

dict[Hashable, list[str]]

contr_spaces

Set of spaces that connect two tensors (i.e. are contracted) and as such are not visible outside the network.

Type:

set[Hashable]

free_spaces

Set of spaces such that only one tensor is connected to them (i.e. are not contracted).

Type:

set[Hashable]

free_dimension

Dimension of the free space (product of dimensions of free spaces).

Type:

int

multiplier

Multiplier resulting from contraction with trivial tensors (scalars).

Type:

complex

Attributes:
comb_structure

Comb (causal) structure in a form of

dimensions

Dimensions of the tensor spaces.

input_dim

Input dimension, that is the product of the all input spaces dimensions.

input_spaces

List of the input spaces.

is_choi_like

Whether the tensor is Choi-like.

is_comb

Whether the tensor has comb (causal) structure.

output_dim

Output dimension, that is the product of the all output spaces dimensions.

output_spaces

List of the output spaces.

shape

Tensor shape, that is index ranges of self.spaces.

spaces
Parameters:

Methods

choi_trace(*spaces[, full])

For Choi-like tensor compute partial trace of the Choi matrix.

compress([name, ignore])

Make those contraction of constant nodes that do not increase used memory space.

connected_components([subgraph, removed])

Get list of connected components.

contr(*others)

Contract tensors.

copy()

Make a copy.

kron(*others)

For Choi-like tensors it computes their Kronecker product and for other tensors it is just contraction where there are no doubled indices (no index gets contracted).

neighbors(name)

Get set of neighbors.

plot(**kwargs)

Plot the network using matplotlib.pyplot.

remove(names)

Remove tensors from the network.

respace([spaces, space_map, qsystem, name])

Make a copy of self but with renamed spaces.

compress(name=None, ignore=None)[source]

Make those contraction of constant nodes that do not increase used memory space.

Parameters:
  • name (str | None, optional) – Name of the new tensor network, by default None.

  • ignore (list[str] | None, optional) – Names of tensors that cannot be contracted, by default None.

Returns:

Compressed tensor network.

Return type:

TensorNetwork

connected_components(subgraph=None, removed=None)[source]

Get list of connected components.

Parameters:
  • subgraph (set[str] | None, optional) – Nodes defining subgraph for which the computation is performed, by default None.

  • removed (set[str] | None, optional) – Nodes assumed to be removed from the network, by default None.

Returns:

components – List of lists of names.

Return type:

list[list[str]]

copy()[source]

Make a copy.

Returns:

copy – Tensor network copy.

Return type:

TensorNetwork

edges: dict[Hashable, list[str]]
name_prefix = 'TENSOR NETWORK '
neighbors(name)[source]

Get set of neighbors.

Parameters:

name (str) – Node name.

Returns:

neighbors – Set of neighbors’ names.

Return type:

set[str]

plot(**kwargs)[source]

Plot the network using matplotlib.pyplot.

Parameters:

kwargs (Any)

remove(names)[source]

Remove tensors from the network.

Parameters:

names (list[str]) – Names of the tensors to remove.

respace(spaces=None, space_map=None, qsystem=None, name=None)[source]

Make a copy of self but with renamed spaces.

Parameters:
  • spaces (list[Hashable] | None, optional) – The change of spaces will take the form self.spaces[i] -> spaces[i]. If None then change of spaces will be carried out using space_map, by default None.

  • space_map (Callable[[Hashable], Hashable] | None, optional) – The change of spaces will take the form space -> space_map(space), by default None

  • sdict (SpaceDict | None, optional) – Space dictionary of the copy. If None then it will be self.sdict, by default None.

  • name (str | None, optional) – Name of the copy. If None then it will be self.name, by default None.

  • self (TensorNetwork)

  • qsystem (SpaceDict | None)

Returns:

copy – New tensor with renamed spaces.

Return type:

GeneralTensor

property spaces: list[Hashable]
tensors: dict[str, ConstTensor | ParamTensor | VarTensor]
class qmetro.qmtensor.classes.tensors.VarTensor(spaces, sdict=<qmetro.qmtensor.classes.tensors.SpaceDict object>, name=None, output_spaces=None, is_unital=False, is_measurement=False, comb_structure=None)[source]

Bases: GeneralTensor

Class of tensors that are optimized by iss.

Parameters:
  • spaces (list[Hashable]) – Tensor spaces.

  • sdict (SpaceDict, optional) – Space dictionary, by default DEFAULT_SDICT.

  • name (str | None, optional) – Tensor name, by default None.

  • output_spaces (list[Hashable] | None, optional) – Tensor output spaces, by default None

  • is_unital (bool, optional) – Unitality constraint, by default False.

  • is_measurement (bool, optional) – Whether it is a measurment-like (SLD-like) variable, by default False.

  • comb_structure (list[tuple[list[Hashable], list[Hashable]]] | None) – Comb (causal) structure in a form of [(input_0, output_0), (input_1, output_1), …] where input_i (output_i) is a list of input (output) spaces of the i-th tooth.

is_unital

Whether the tensor is unital.

Type:

bool

is_measurement

Whether the tensor is measurement-like (SLD-like) variable.

Type:

bool

Attributes:
comb_structure

Comb (causal) structure in a form of

dimensions

Dimensions of the tensor spaces.

input_dim

Input dimension, that is the product of the all input spaces dimensions.

input_spaces

List of the input spaces.

is_choi_like

Whether the tensor is Choi-like.

is_comb

Whether the tensor has comb (causal) structure.

output_dim

Output dimension, that is the product of the all output spaces dimensions.

output_spaces

List of the output spaces.

shape

Tensor shape, that is index ranges of self.spaces.

Parameters:
  • spaces (list[Hashable])

  • sdict (SpaceDict)

  • name (str | None)

  • output_spaces (list[Hashable] | None)

  • is_unital (bool)

  • is_measurement (bool)

  • comb_structure (list[tuple[list[Hashable], list[Hashable]]] | None)

Methods

choi_trace(*spaces[, full])

For Choi-like tensor compute partial trace of the Choi matrix.

contr(*others)

Contract tensors.

copy()

Make a copy.

kron(*others)

For Choi-like tensors it computes their Kronecker product and for other tensors it is just contraction where there are no doubled indices (no index gets contracted).

random_choi([name])

Draw random tensor of CPTP Choi matrix.

random_comb([name])

Draw random tensor of comb Choi matrix.

random_mps_element([name])

Constant tensor of a density matrix MPO element from the random MPS element.

random_sld([name])

Constant tensor of random SLD matrix.

respace([spaces, space_map, sdict, name])

Make a copy of self but with renamed spaces.

name_prefix = 'VAR TENSOR '
random_choi(name=None)[source]

Draw random tensor of CPTP Choi matrix.

Parameters:

name (str | None, optional) – Tensor name. If None then self.name, by default None.

Returns:

tensor – Random tensor.

Return type:

ConstTensor

random_comb(name=None)[source]

Draw random tensor of comb Choi matrix.

Parameters:

name (str | None, optional) – Tensor name. If None then self.name, by default None.

Returns:

tensor – Random tensor.

Return type:

ConstTensor

random_mps_element(name=None)[source]

Constant tensor of a density matrix MPO element from the random MPS element.

Parameters:

name (str | None, optional) – Tensor name. If None then self.name, by default None.

Returns:

tensor – Random tensor.

Return type:

ConstTensor

random_sld(name=None)[source]

Constant tensor of random SLD matrix.

Parameters:

name (str | None, optional) – Tensor name. If None then self.name, by default None.

Returns:

tensor – Random SLD matrix.

Return type:

ConstTensor

respace(spaces=None, space_map=None, sdict=None, name=None)[source]

Make a copy of self but with renamed spaces.

Parameters:
  • spaces (list[Hashable] | None, optional) – The change of spaces will take the form self.spaces[i] -> spaces[i]. If None then change of spaces will be carried out using space_map, by default None.

  • space_map (Callable[[Hashable], Hashable] | None, optional) – The change of spaces will take the form space -> space_map(space), by default None.

  • sdict (SpaceDict | None, optional) – Space dictionary of the copy. If None then it will be self.sdict, by default None.

  • name (str | None, optional) – Name of the copy. If None then it will be self.name, by default None.

  • self (VarTensor)

Returns:

copy – New tensor with renamed spaces.

Return type:

VarTensor

creators/single

qmetro.qmtensor.creators.single.choi_identity(spaces=None, sdict=<qmetro.qmtensor.classes.tensors.SpaceDict object>, **kwargs)[source]

Creates tensor form of identity Choi matrix.

Parameters:
  • spaces (list[Hashable]) – Tensor spaces, by default empty list.

  • sdict (SpaceDict, optional) – Space dictionary, by default DEFAULT_SDICT

  • **kwargs – Key-word arguments passed to ConstTensor constructor.

Returns:

tensor – Choi-like constant tensor of identity matrix.

Return type:

ConstTensor

qmetro.qmtensor.creators.single.const_tensor_from_fun(fun, input_spaces, output_spaces, sdict=<qmetro.qmtensor.classes.tensors.SpaceDict object>, **kwargs)[source]

Returns a tensor form of Choi matrix created from a quantum channel using Choi-Jemiolkowski isomorphism.

Parameters:
  • fun (Callable[[np.ndarray], np.ndarray]) – Function defining the quantum channel.

  • input_spaces (list[Hashable]) – Input spaces.

  • output_spaces (list[Hashable]) – Output spaces.

  • sdict (SpaceDict, optional) – Space dictionary, by default DEFAULT_SDICT.

  • **kwargs – Key-word arguments passed to ConstTensor constructor.

Returns:

tensor – Tensor form of the Choi matrix.

Return type:

ConstTensor

qmetro.qmtensor.creators.single.cptp_var(input_spaces, output_spaces, name, sdict=<qmetro.qmtensor.classes.tensors.SpaceDict object>, **kwargs)[source]

Creates a CPTP variable.

Parameters:
  • input_spaces (list[Hashable]) – Input spaces.

  • output_spaces (list[Hashable]) – Output spaces.

  • sdict (SpaceDict, optional) – Space dictionary of the result, by default DEFAULT_SDICT.

  • **kwargs – Key-word arguments passed to VarTensor constructor.

  • name (str)

Returns:

tensor – CPTP variable.

Return type:

ParamTensor

qmetro.qmtensor.creators.single.tensor_from_krauses(krauses, input_spaces, output_spaces, sdict=<qmetro.qmtensor.classes.tensors.SpaceDict object>, dkrauses=None, **kwargs)[source]

Computes tensor form of a Choi matrix from Kraus operators and their derivatives.

Parameters:
  • krauses (list[np.ndarray]) – Kraus operators.

  • input_spaces (list[Hashable]) – Input spaces.

  • output_spaces (list[Hashable]) – Output spaces.

  • sdict (SpaceDict, optional) – Space dictionary of the result, by default DEFAULT_SDICT.

  • dkrauses (list[np.ndarray] | None, optional) – Derivatives of Kraus operators. If provided the result will be a ParamTensor with derivative coming from these operators, by default None.

  • **kwargs – Key-word arguments passed to ConstTensor/ParamTensor constructor.

Returns:

matrix – Tensor form of the Choi matrix.

Return type:

ConstTensor | ParamTensor

qmetro.qmtensor.creators.single.zero(spaces=None, sdict=<qmetro.qmtensor.classes.tensors.SpaceDict object>, **kwargs)[source]

Creates constant tensor filled with zeros with sdict=self.

Parameters:
  • spaces (list[Hashable]) – Tensor spaces, by default empty list.

  • sdict (SpaceDict, optional) – Space dictionary, by default DEFAULT_SDICT

  • **kwargs – Key-word arguments passed to ConstTensor constructor.

Returns:

tensor – Zero const tensor.

Return type:

ConstTensor

creators/structures

qmetro.qmtensor.creators.structures.cmarkov_param_tnet(krauses, dkrauses, input_spaces, output_spaces, transition_mat, name, sdict=<qmetro.qmtensor.classes.tensors.SpaceDict object>, initial_prob=None, trace_end=True, **kwargs)[source]

Returns Choi matrices of channels whith classical Markovian correlation of their Kraus operators. The number of repetitions is derived from the number of lists in input_spaces.

Parameters:
  • krauses (list[np.ndarray]) – Kraus operators.

  • dkrauses (list[np.ndarray]) – Derivatives of Kraus operators.

  • input_spaces (list[list[Hashable]]) – List of lists of input spaces. The ith list is a list of input spaces of the ith channel.

  • output_spaces (list[list[Hashable]]) – List of lists of output spaces. The ith list is a list of output spaces of the ith channel.

  • transition_mat (np.ndarray) – Matrix M of conditional probabilities. The coefficient M[i, j] is equal to P(i|j) - the conditional probability of ith Kraus operator given the occurence of jth operator in the previous step.

  • name (str) – Name of the result. Elements have names in format f”{name}, {i}” where i is the element number and its input and output correlation spaces are (name, ‘ENVIRONMENT’, i) and (name, ‘ENVIRONMENT’, i+1) respectively.

  • sdict (SpaceDict, optional) – Space dictionary of the result, by default DEFAULT_SDICT.

  • initial_prob (np.ndarray | None, optional) – Initial probabilities in a Markov chain. If None then the input of the correlation space - (name, ‘ENVIRONMENT’, 0) is left open, by default None.

  • trace_end (bool, optional) – Whether to trace out the output of the correlation space - (name, ‘ENVIRONMENT’, n_of_repetitions), by default True.

  • **kwargs – Arguments passed to ParamTensor constructor.

Returns:

  • corrlated_channels (TensorNetwork) – Tensor network rerpresenting the Choi matrices of correlated channels.

  • channel_names (list[str]) – List of channels’ names. In order from i=0 to i=n-1.

  • environments (list[Hashable]) – List of environment spaces’ names. In order from i=0 to i=n-2.

Return type:

tuple[TensorNetwork, list[str], list[Hashable]]

qmetro.qmtensor.creators.structures.comb_var(structure, name, sdict=<qmetro.qmtensor.classes.tensors.SpaceDict object>, ancilla_dim=None, **kwargs)[source]

Creates a comb variable.

Parameters:
  • structure (list[tuple[list[Hashable], list[Hashable]]]) – List defining the spaces of every tooth. For i-th tooth and inp_i, out_i = structure[i] where inp_i (out_i) is a list of input (output) spaces of the i-th tooth excluding the ancilla.

  • name (str) – Name of the result. Elements have names in format f”{name}, {i}” where i is the element number and its input and output ancilla spaces are (name, ‘ANCILLA’, i-1) and (name, ‘ANCILLA’, i) respectively.

  • sdict (SpaceDict, optional) – Space dictionary, by default DEFAULT_SDICT.

  • ancilla_dim (int | None, optional) – Dimension of ancilla spaces. When this argument is: - a number: a tensor network of control operations will be created, - None: one comb-like variable tensor will be created, by default None.

  • **kwargs – Arguments passed to VarTensor constructor.

Returns:

Tensor of comb variable.

Return type:

VarTensor | TensorNetwork

qmetro.qmtensor.creators.structures.comb_var_tnet(structure, name, sdict=<qmetro.qmtensor.classes.tensors.SpaceDict object>, ancilla_dim=1, **kwargs)[source]

Returns a network of variable tensors representing channels in a sequence such that part of the output of one channel is a part of the input of the next one.

More precisely, it returns a network of n variable tensor representing channels called teeth:

T_i: L(I_i (x) A_i-1) -> L(O_i (x) A_i),

where: - I_i, O_i and A_i are input, output and ancilla Hilbert spaces, - (x) is a tensor product, - L(H) is a set of linear operators on H, - A_(-1) and A_n are trivial.

Parameters:
  • structure (list[tuple[list[Hashable], list[Hashable]]]) – List defining the spaces of every tooth. For i-th tooth and inp_i, out_i = structure[i] where inp_i (out_i) is a list of input (output) spaces of the i-th tooth excluding the ancilla.

  • name (str) – Name of the result. Elements have names in format f”{name}, {i}” where i is the element number and its input and output ancilla spaces are (name, ‘ANCILLA’, i-1) and (name, ‘ANCILLA’, i) respectively.

  • sdict (SpaceDict, optional) – Space dictionary, by default DEFAULT_SDICT.

  • ancilla_dim (int, optional) – Dimension of ancilla spaces, by default 1.

  • **kwargs – Arguments passed to VarTensor constructor.

Returns:

  • network (TensorNetwork) – Tensor network of a comb.

  • channel_names (list[str]) – List of teeth’s names: [T_0, T_1, ..., T_n-1].

  • ancillas (list[Hashable]) – List of ancilla spaces’ names: [A_0, A_1, ..., A_n-2].

Return type:

tuple[TensorNetwork, list[str], list[Hashable]]

qmetro.qmtensor.creators.structures.input_state_var(output_spaces, name, sdict=<qmetro.qmtensor.classes.tensors.SpaceDict object>, mps_bond_dim=None, **kwargs)[source]

Creates a state variable.

Parameters:
  • output_spaces (list[Hashable]) – Spaces of the state.

  • name (str) – Name of the result. If mps_bond_dim is provided it will use the naming convention of mps_var_tnet().

  • sdict (SpaceDict, optional) – Space dictionary of the result, by default DEFAULT_SDICT.

  • mps_bond_dim (int, optional) – Dimension of the MPS connecting (bond) spaces. If None then it will return the state on the whole product Hilbert space (as if bond dimension was infinite). By default None.

  • **kwargs – Arguments passed to VarTensor constructor.

Returns:

state – Tesnor representing the density matrix.

Return type:

VarTensor | TensorNetwork

Notes

In case one needs names of the MPS elements and bond spaces use mps_var_tnet.

qmetro.qmtensor.creators.structures.measure_var(input_spaces, name, sdict=<qmetro.qmtensor.classes.tensors.SpaceDict object>, bond_dim=None, **kwargs)[source]

Creates a measurement variable.

Parameters:
  • input_spaces (list[Hashable]) – Measured spaces.

  • name (str) – Name of the result. If mps_bond_dim is provided it will use the naming convention of mpo_measure_var_tnet.

  • sdict (SpaceDict) – Space dictionary of the result, by default DEFAULT_SDICT.

  • bond_dim (int | None, optional) – Dimension of the connecting (bond) spaces. If None then it will return the measurement on the whole product Hilbert space (as if bond dimension was infinite). By default None.

  • **kwargs – Arguments passed to VarTensor constructor.

Returns:

Tensor representing the measurement.

Return type:

VarTensor | TensorNetwork

Notes

In case one needs names of the MPS elements and bond spaces use mpo_measure_var_tnet.

qmetro.qmtensor.creators.structures.mpo_measure_var_tnet(input_spaces, name, sdict=<qmetro.qmtensor.classes.tensors.SpaceDict object>, bond_dim=1, **kwargs)[source]

Creates a variable measurement (SLD) matrix product operator (MPO).

The result is a network of variable tensors: T_0, T_1, …, T_n-1. The i-th tensor has inidices called: I_i, B_i-1, B_i where - I_i represent Hilbert spaces which are measured (input spaces), - B_i are bond spaces, - B_-1 and B_n-1 do not exist. Then the contraction of all tensors by the bond spaces with the same name yields a variable of a measurement on I_0 (x) ... (x) I_n-1.

Parameters:
  • input_spaces (list[Hashable]) – Measured spaces, i-th element is the space I_i.

  • name (str) – Name of the result. Elements will have names in format f”{name}, {i}” and connecting spaces in (name, ‘BOND’, i), where i is the element/space number.

  • sdict (SpaceDict, optional) – Space dictionary of the result, by default DEFAULT_SDICT.

  • bond_dim (int, optional) – Dimension of the connecting (bond) spaces, by default 1.

  • **kwargs – Arguments passed to VarTensor constructor.

Returns:

  • sld (TensorNetwork) – Tensor network representing MPO of the measurement (SLD).

  • elements (list[str]) – List of elements’ names. In order from i=0 to i=n-1.

  • bonds (list[Hashable]) – List of bond spaces’ names. In order from i=0 to i=n-2.

Return type:

tuple[TensorNetwork, list[str], list[Hashable]]

qmetro.qmtensor.creators.structures.mps_var_tnet(output_spaces, name, sdict=<qmetro.qmtensor.classes.tensors.SpaceDict object>, mps_bond_dim=1, **kwargs)[source]

Creates a variable density matrix of a pure matrix product state (MPS). This density matrix is a matrix product operaotr (MPO).

The result is a network of variable tensors:

T_0, T_1, …, T_n-1.

The i-th tensor has inidices called: O_i, B_i-1, B_i where - O_i represent Hilbert spaces on which the state acts (output spaces), - B_i are bond spaces, - B_-1 and B_n-1 do not exist. Then the contraction of all tensors by the bond spaces with the same name yields a density matrix of a pure state on

O_0 (x) ... (x) O_n-1.

Bond spaces are defined for MPO elements and thus their dimension is the square of the MPS bond dimension.

Parameters:
  • output_spaces (list[Hashable]) – Spaces of the state, i-th element is the space O_i.

  • name (str) – Name of the result. Tensors will have names in format f”{name}, {i}” and connecting spaces B_i = (name, ‘BOND’, i).

  • sdict (SpaceDict, optional) – Space dictionary of the result, by default DEFAULT_SDICT.

  • mps_bond_dim (int, optional) – Dimension of the MPS connecting (bond) spaces, by default 1.

  • **kwargs – Arguments passed to VarTensor constructor.

Returns:

  • mps (TensorNetwork) – Tensor network of variable tensors representing MPO of the density matrix.

  • tensor_names (list[str]) – List of tensors’ names. In order from i=0 to i=n-1.

  • bonds (list[Hashable]) – List of bond spaces’ names. In order from i=0 to i=n-2.

Return type:

tuple[TensorNetwork, list[str], list[Hashable]]

operations

qmetro.qmtensor.operations.Tr(tensor, *spaces, full=False)[source]

For Choi-like tensor compute partial trace of the Choi matrix.

Parameters:
  • spaces[0...*] (Hashable) – Spaces to be traced out.

  • full (bool, optional) – If True then computes the trace over all spaces and returns a complex number, by default False.

  • tensor (GeneralTensor | ParamTensor | VarTensor | TensorNetwork)

  • spaces (Hashable)

Returns:

tensor – Tensor of the result.

Return type:

Tensor | complex

qmetro.qmtensor.operations.contr(*args)[source]

Contract tensors.

Parameters:
Returns:

tensor – Contraction result.

Return type:

Tensor

qmetro.qmtensor.operations.is_comb_var(x)[source]
Parameters:

x (GeneralTensor | ParamTensor | VarTensor | TensorNetwork | int | float | complex)

Return type:

bool

qmetro.qmtensor.operations.is_const(x)[source]
Parameters:

x (GeneralTensor | ParamTensor | VarTensor | TensorNetwork)

Return type:

bool

qmetro.qmtensor.operations.is_cptp_var(x)[source]
Parameters:

x (GeneralTensor | ParamTensor | VarTensor | TensorNetwork | int | float | complex)

Return type:

bool

qmetro.qmtensor.operations.is_full_sld(x)[source]
Parameters:

x (GeneralTensor | ParamTensor | VarTensor | TensorNetwork | int | float | complex)

Return type:

bool

qmetro.qmtensor.operations.is_measurement(x)[source]
Parameters:

x (GeneralTensor | ParamTensor | VarTensor | TensorNetwork | int | float | complex)

Return type:

bool

qmetro.qmtensor.operations.is_mps(x)[source]
Parameters:

x (GeneralTensor | ParamTensor | VarTensor | TensorNetwork | int | float | complex)

Return type:

bool

qmetro.qmtensor.operations.is_mps_var(x)[source]
Parameters:

x (GeneralTensor | ParamTensor | VarTensor | TensorNetwork | int | float | complex)

Return type:

bool

qmetro.qmtensor.operations.is_param(x)[source]
Parameters:

x (GeneralTensor | ParamTensor | VarTensor | TensorNetwork | int | float | complex)

Return type:

bool

qmetro.qmtensor.operations.is_scalar(x)[source]
Parameters:

x (GeneralTensor | ParamTensor | VarTensor | TensorNetwork | int | float | complex)

Return type:

bool

qmetro.qmtensor.operations.is_sld_mpo(x)[source]
Parameters:

x (GeneralTensor | ParamTensor | VarTensor | TensorNetwork | int | float | complex)

Return type:

bool

qmetro.qmtensor.operations.is_var(x)[source]
Parameters:

x (GeneralTensor | ParamTensor | VarTensor | TensorNetwork | int | float | complex)

Return type:

bool

qmetro.qmtensor.operations.kron(*args)[source]

For Choi-like tensors it computes their Kronecker product and for other tensors it is just contraction where there are no doubled indices (no gets contracted).

Parameters:
Returns:

tensor – Kronecker product.

Return type:

Tensor