Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ORNL Quantum Computing Institute
exatn
Commits
1d81b176
Commit
1d81b176
authored
Jul 07, 2019
by
Dmitry I. Lyakh
Browse files
Merge branch 'devel'
parents
85686637
3694cd21
Changes
3
Hide whitespace changes
Inline
Sidebyside
src/numerics/spaces.cpp
View file @
1d81b176
/** ExaTN::Numerics: Space
Basi
s
REVISION: 2019/0
6
/0
6
/** ExaTN::Numerics: Space
s/Subspace
s
REVISION: 2019/0
7
/0
7
Copyright (C) 20182019 Dmitry I. Lyakh (Liakh)
Copyright (C) 20182019 Oak Ridge National Laboratory (UTBattelle) **/
...
...
src/numerics/tensor_network.cpp
View file @
1d81b176
/** ExaTN::Numerics: Tensor network
REVISION: 2019/07/0
2
REVISION: 2019/07/0
7
Copyright (C) 20182019 Dmitry I. Lyakh (Liakh)
Copyright (C) 20182019 Oak Ridge National Laboratory (UTBattelle) **/
...
...
@@ 16,7 +16,7 @@ namespace numerics{
TensorNetwork
::
TensorNetwork
(
const
std
::
string
&
name
)
:
name_
(
name
)
{
tensors_
.
emplace
(
tensors_
.
emplace
(
//output tensor (id = 0)
std
::
make_pair
(
0U
,
TensorConn
(
std
::
make_shared
<
Tensor
>
(
name
),
0U
,
std
::
vector
<
TensorLeg
>
())
...
...
@@ 26,7 +26,7 @@ name_(name)
TensorNetwork
::
TensorNetwork
()
{
tensors_
.
emplace
(
tensors_
.
emplace
(
//output tensor (id = 0)
std
::
make_pair
(
0U
,
TensorConn
(
std
::
make_shared
<
Tensor
>
(
"_SMOKY_TENSOR_"
),
0U
,
std
::
vector
<
TensorLeg
>
())
...
...
@@ 42,11 +42,64 @@ void TensorNetwork::printIt() const
return
;
}
bool
TensorNetwork
::
isEmpty
()
const
{
return
(
tensors_
.
size
()
==
1
);
//only output tensor exists => empty
}
unsigned
int
TensorNetwork
::
getNumTensors
()
const
{
return
static_cast
<
unsigned
int
>
(
tensors_
.
size
()

1
);
//output tensor is not counted
}
const
std
::
string
&
TensorNetwork
::
getName
()
const
{
return
name_
;
}
const
TensorConn
*
TensorNetwork
::
getTensorConn
(
unsigned
int
tensor_id
)
const
{
auto
it
=
tensors_
.
find
(
tensor_id
);
if
(
it
==
tensors_
.
end
())
return
nullptr
;
return
&
(
it
>
second
);
}
std
::
shared_ptr
<
Tensor
>
TensorNetwork
::
getTensor
(
unsigned
int
tensor_id
)
{
auto
it
=
tensors_
.
find
(
tensor_id
);
if
(
it
==
tensors_
.
end
())
return
std
::
shared_ptr
<
Tensor
>
(
nullptr
);
return
(
it
>
second
).
getTensor
();
}
bool
TensorNetwork
::
appendTensor
(
unsigned
int
tensor_id
,
//in: tensor id (unique within the tensor network)
std
::
shared_ptr
<
Tensor
>
tensor
,
//in: appended tensor
const
std
::
vector
<
TensorLeg
>
&
connections
)
//in: tensor connections
{
//`Finish
return
true
;
}
bool
TensorNetwork
::
appendTensor
(
unsigned
int
tensor_id
,
//in: tensor id (unique within the tensor network)
std
::
shared_ptr
<
Tensor
>
tensor
,
//in: appended tensor
const
std
::
vector
<
std
::
pair
<
unsigned
int
,
unsigned
int
>>
&
pairing
)
//in: leg pairing: output tensor mode > appended tensor mode
{
//`Finish
return
true
;
}
bool
TensorNetwork
::
appendTensorNetwork
(
TensorNetwork
&&
network
,
//in: appended tensor network
const
std
::
vector
<
std
::
pair
<
unsigned
int
,
unsigned
int
>>
&
pairing
)
//in: leg pairing: output tensor mode (primary) > output tensor mode (appended)
{
//`Finish
return
true
;
}
bool
TensorNetwork
::
reoderOutputModes
(
const
std
::
vector
<
unsigned
int
>
&
order
)
{
//`Finish
return
true
;
}
}
//namespace numerics
}
//namespace exatn
src/numerics/tensor_network.hpp
View file @
1d81b176
/** ExaTN::Numerics: Tensor network
REVISION: 2019/07/0
2
REVISION: 2019/07/0
7
Copyright (C) 20182019 Dmitry I. Lyakh (Liakh)
Copyright (C) 20182019 Oak Ridge National Laboratory (UTBattelle) **/
/** Rationale:
(a) A tensor network is a set of connected tensors.
(b)
Each tensor in a tensor network can be connected to
Each tensor in a tensor network can be connected to
other tensors in that tensor network via tensor legs.
(c) Each tensor leg in a given tensor is uniquely associated
with one of its dimensions, one tensor leg per tensor dimension.
(d) A tensor leg can connect a given tensor with one or more
other tensors in the same tensor network. Thus, tensor
legs can be binary, ternary, etc.
(e) A tensor network is always closed, which requires introducing
Each tensor leg in a given tensor is uniquely associated
with one of its modes, one tensor leg per tensor mode. The
numeration of tensor modes is contiguous and starts from 0.
A tensor leg can connect a given tensor with one or more
other tensors in the same tensor network. Thus, tensor legs
can be binary, ternary, etc., in general (binary is common choice).
(b) A tensor network is always closed, which requires introducing
an explicit output tensor collecting all open legs of the original
tensor network. If the original tensor network does not have open
legs, the output tensor is simply a scalar which the original tensor
network evaluates to; otherwise, a tensor network evaluates to a tensor.
(f) Tensor enumeration:
0: Output tensor/scalar which the tensor network evaluates to;
1..N: Input tensors/scalars constituting the original tensor network;
N+1..M: Intermediate tensors obtained by contractions of input tensors.
(c) Current tensor enumeration (it is just one option):
0: Output tensor/scalar which the tensor network evaluates to;
1..N: Input tensors/scalars constituting the original tensor network;
N+1..M: Intermediate tensors obtained by contractions of the input tensors.
In general, only the output tensor is required to have id = 0; any other
tensor in the tensor network may have any unique positive id.
(d) Building a tensor network:
Option 1: A new tensor can be appended into a tensor network by either:
(1) Matching the tensor modes with the modes of the input tensors
already present in the tensor network.
(2) Matching the tensor modes with the modes of the output tensor
of the tensor network.
In both cases, the unmatched modes of the newly appended tensor
will be appended to the output tensor of the tensor network,
succeeding the existing modes of the output tensor.
Option 2: A tensor network can be appended to another tensor network by
matching the modes of the output tensors of both tensor networks.
The unmatched modes of the output tensor of the appended tensor
network will be appended to the output tensor of the primary
tensor network (at the end). The appended tensor network will
cease to exist after being absorbed by the primary tensor network.
(e) The modes of the output tensor of a tensor network can be examined and reordered.
**/
#ifndef EXATN_NUMERICS_TENSOR_NETWORK_HPP_
...
...
@@ 32,7 +51,9 @@ Copyright (C) 20182019 Oak Ridge National Laboratory (UTBattelle) **/
#include
"tensor_op_factory.hpp"
#include
<unordered_map>
#include
<vector>
#include
<string>
#include
<memory>
namespace
exatn
{
...
...
@@ 59,10 +80,51 @@ public:
/** Prints **/
void
printIt
()
const
;
/** Returns TRUE if the tensor network is empty, FALSE otherwise. **/
bool
isEmpty
()
const
;
/** Returns the number of input tensors in the tensor network.
Note that the output tensor (tensor #0) is not counted here. **/
unsigned
int
getNumTensors
()
const
;
/** Returns the name of the tensor network. **/
const
std
::
string
&
getName
()
const
;
/** Returns a nonowning pointer to a given tensor of the tensor network
together with its connections (legs). If not found, returns nullptr. **/
const
TensorConn
*
getTensorConn
(
unsigned
int
tensor_id
)
const
;
/** Returns a given tensor of the tensor network without its connections (legs).
If not found, returns nullptr. **/
std
::
shared_ptr
<
Tensor
>
getTensor
(
unsigned
int
tensor_id
);
/** Appends a new tensor to the tensor network by matching the tensor modes
with the modes of the input tensors already present in the tensor network.
The unmatched modes of the newly appended tensor will be appended to the
existing modes of the output tensor of the tensor network (at the end). **/
bool
appendTensor
(
unsigned
int
tensor_id
,
//in: tensor id (unique within the tensor network)
std
::
shared_ptr
<
Tensor
>
tensor
,
//in: appended tensor
const
std
::
vector
<
TensorLeg
>
&
connections
);
//in: tensor connections
/** Appends a new tensor to the tensor network by matching the tensor modes
with the modes of the output tensor of the tensor network. The unmatched modes
of the newly appended tensor will be appended to the existing modes of the
output tensor of the tensor network (at the end). **/
bool
appendTensor
(
unsigned
int
tensor_id
,
//in: tensor id (unique within the tensor network)
std
::
shared_ptr
<
Tensor
>
tensor
,
//in: appended tensor
const
std
::
vector
<
std
::
pair
<
unsigned
int
,
unsigned
int
>>
&
pairing
);
//in: leg pairing: output tensor mode > appended tensor mode
/** Appends a tensor network to the current tensor network by matching the modes
of the output tensors of both tensor networks. The unmatched modes of the
output tensor of the appended tensor network will be appended to the output
tensor of the primary tensor network (at the end). The appended tensor network
will cease to exist after being absorbed by the primary tensor network. **/
bool
appendTensorNetwork
(
TensorNetwork
&&
network
,
//in: appended tensor network
const
std
::
vector
<
std
::
pair
<
unsigned
int
,
unsigned
int
>>
&
pairing
);
//in: leg pairing: output tensor mode (primary) > output tensor mode (appended)
/** Reoders the modes of the output tensor of the tensor network. **/
bool
reoderOutputModes
(
const
std
::
vector
<
unsigned
int
>
&
order
);
//in: new order of the output tensor modes (N2O)
private:
std
::
string
name_
;
//tensor network name
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment