Skip to content
GitLab
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
10a01bf8
Commit
10a01bf8
authored
Jul 18, 2019
by
Mccaskey, Alex
Browse files
Merge branch 'devel' of
https://github.com/ornl-qci/exatn
into devel
parents
51657237
2819459c
Pipeline
#63680
passed with stage
in 3 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/numerics/tensor_network.cpp
View file @
10a01bf8
/** ExaTN::Numerics: Tensor network
REVISION: 2019/07/1
7
REVISION: 2019/07/1
8
Copyright (C) 2018-2019 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2019 Oak Ridge National Laboratory (UT-Battelle) **/
...
...
@@ -218,7 +218,7 @@ bool TensorNetwork::appendTensor(unsigned int tensor_id, //i
++
mode
;
}
//Append the tensor to the tensor network:
auto
new_pos
=
tensors_
.
emplace
(
std
::
pair
<
unsigned
int
,
TensorConn
>
(
auto
new_pos
=
tensors_
.
emplace
(
std
::
make_pair
(
tensor_id
,
TensorConn
(
tensor
,
tensor_id
,
connections
)
)
);
...
...
@@ -324,7 +324,7 @@ bool TensorNetwork::appendTensor(unsigned int tensor_id,
}
++
mode
;
}
auto
new_pos
=
tensors_
.
emplace
(
std
::
pair
<
unsigned
int
,
TensorConn
>
(
auto
new_pos
=
tensors_
.
emplace
(
std
::
make_pair
(
tensor_id
,
TensorConn
(
tensor
,
tensor_id
,
new_tensor_legs
)
)
);
...
...
@@ -334,7 +334,7 @@ bool TensorNetwork::appendTensor(unsigned int tensor_id,
return
false
;
}
}
else
{
//scalar tensor
auto
new_pos
=
tensors_
.
emplace
(
std
::
pair
<
unsigned
int
,
TensorConn
>
(
auto
new_pos
=
tensors_
.
emplace
(
std
::
make_pair
(
tensor_id
,
TensorConn
(
tensor
,
tensor_id
,
std
::
vector
<
TensorLeg
>
())
)
);
...
...
@@ -536,21 +536,21 @@ bool TensorNetwork::deleteTensor(unsigned int tensor_id)
}
bool
TensorNetwork
::
contract
Tensors
(
unsigned
int
left_id
,
unsigned
int
right_id
,
unsigned
int
result_id
)
bool
TensorNetwork
::
merge
Tensors
(
unsigned
int
left_id
,
unsigned
int
right_id
,
unsigned
int
result_id
)
{
if
(
left_id
==
right_id
||
left_id
==
result_id
||
right_id
==
result_id
){
std
::
cout
<<
"#ERROR(TensorNetwork::
contract
Tensors): Invalid arguments: Cannot be identical: "
<<
std
::
cout
<<
"#ERROR(TensorNetwork::
merge
Tensors): Invalid arguments: Cannot be identical: "
<<
left_id
<<
" "
<<
right_id
<<
" "
<<
result_id
<<
std
::
endl
;
return
false
;
}
if
(
left_id
==
0
||
right_id
==
0
||
result_id
==
0
){
std
::
cout
<<
"#ERROR(TensorNetwork::
contract
Tensors): Invalid arguments: Output tensor #0 cannot participate: "
<<
std
::
cout
<<
"#ERROR(TensorNetwork::
merge
Tensors): Invalid arguments: Output tensor #0 cannot participate: "
<<
left_id
<<
" "
<<
right_id
<<
" "
<<
result_id
<<
std
::
endl
;
return
false
;
}
if
(
finalized_
==
0
){
std
::
cout
<<
"#ERROR(TensorNetwork::
contract
Tensors): Invalid request: "
<<
"
Contract
ing tensors in an unfinalized tensor network is forbidden!"
<<
std
::
endl
;
std
::
cout
<<
"#ERROR(TensorNetwork::
merge
Tensors): Invalid request: "
<<
"
Merg
ing tensors in an unfinalized tensor network is forbidden!"
<<
std
::
endl
;
return
false
;
}
//Get tensor info:
...
...
@@ -564,12 +564,10 @@ bool TensorNetwork::contractTensors(unsigned int left_id, unsigned int right_id,
const
auto
&
right_legs
=
right_tensor
->
getTensorLegs
();
//Count contracted and uncontracted legs:
unsigned
int
num_contracted
=
0
;
for
(
const
auto
&
leg
:
left_legs
){
if
(
leg
.
getTensorId
()
==
right_id
)
++
num_contracted
;
}
for
(
const
auto
&
leg
:
left_legs
){
if
(
leg
.
getTensorId
()
==
right_id
)
++
num_contracted
;}
unsigned
int
num_uncontracted
=
(
left_legs
.
size
()
+
right_legs
.
size
())
-
num_contracted
*
2
;
//Create the resulting legs and contraction pattern:
std
::
vector
<
TensorLeg
>
result_legs
(
num_uncontracted
,
TensorLeg
(
0
,
0
));
//placeholders for tensor legs
std
::
vector
<
TensorLeg
>
result_legs
(
num_uncontracted
,
TensorLeg
(
0
,
0
));
//placeholders for
result-
tensor legs
std
::
vector
<
TensorLeg
>
pattern
(
left_legs
.
size
()
+
right_legs
.
size
(),
TensorLeg
(
0
,
0
));
//tensor contraction pattern (placeholder)
unsigned
int
mode
=
0
;
unsigned
int
res_mode
=
0
;
...
...
@@ -605,7 +603,11 @@ bool TensorNetwork::contractTensors(unsigned int left_id, unsigned int right_id,
)
)
);
//`Finish
//Delete two original tensors:
assert
(
tensors_
.
erase
(
left_id
)
==
1
);
assert
(
tensors_
.
erase
(
right_id
)
==
1
);
//Update connections:
this
->
updateConnections
(
result_id
);
return
true
;
}
...
...
src/numerics/tensor_network.hpp
View file @
10a01bf8
/** ExaTN::Numerics: Tensor network
REVISION: 2019/07/1
6
REVISION: 2019/07/1
8
Copyright (C) 2018-2019 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2019 Oak Ridge National Laboratory (UT-Battelle) **/
...
...
@@ -159,13 +159,13 @@ public:
it will be deleted completely, resulting in a reduced rank of the output tensor. **/
bool
deleteTensor
(
unsigned
int
tensor_id
);
//in: id of the tensor to be deleted
/**
Contract
s two tensors in a finalized tensor network
, producing ano
ther
tensor
:
result = left * right.
/**
Merge
s two tensors in a finalized tensor network
by replacing them by
the
i
r
contracted product
:
result = left * right
: All participating tensor ids must be distinct and not equal to 0
.
The uncontracted modes of the left tensor will precede in-order the uncontracted
modes of the right tensor in the tensor-result. **/
bool
contract
Tensors
(
unsigned
int
left_id
,
//in: left tensor id (present in the tensor network)
unsigned
int
right_id
,
//in: right tensor id (present in the tensor network)
unsigned
int
result_id
);
//in: result tensor id (absent in the tensor network, to be appended)
bool
merge
Tensors
(
unsigned
int
left_id
,
//in: left tensor id (present in the tensor network)
unsigned
int
right_id
,
//in: right tensor id (present in the tensor network)
unsigned
int
result_id
);
//in: result tensor id (absent in the tensor network, to be appended)
/** Builds the tensor network from a template implemented by a custom tensor network builder.
Note that the tensor network must already contain the explicit fully specified output tensor. **/
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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