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
xacc
Commits
e5594bc2
Commit
e5594bc2
authored
Apr 20, 2020
by
Mccaskey, Alex
Browse files
adding a couple functions to qreg for use in qcor
Signed-off-by:
Alex McCaskey
<
mccaskeyaj@ornl.gov
>
parent
98ca9c07
Pipeline
#97952
passed with stage
in 9 minutes and 55 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
xacc/compiler/qalloc.cpp
View file @
e5594bc2
...
...
@@ -27,8 +27,14 @@ void qreg::store() {
buffer
,
empty_delete
<
AcceleratorBuffer
>
());
xacc
::
storeBuffer
(
buffer_as_shared
);
}
int
qreg
::
size
()
{
return
buffer
->
size
();
}
void
qreg
::
addChild
(
qreg
&
q
)
{
for
(
auto
&
child
:
buffer
->
getChildren
())
{
results
()
->
appendChild
(
child
->
name
(),
child
);
}
}
void
qreg
::
print
()
{
buffer
->
print
();}
void
qreg
::
print
()
{
buffer
->
print
();
}
double
qreg
::
weighted_sum
(
Observable
*
obs
)
{
auto
terms
=
obs
->
getNonIdentitySubTerms
();
...
...
@@ -37,20 +43,21 @@ double qreg::weighted_sum(Observable *obs) {
auto
children
=
buffer
->
getChildren
();
double
sum
=
0.0
;
if
(
terms
.
size
()
!=
children
.
size
())
{
xacc
::
error
(
"[qreg::weighted_sum()] error, number of observable terms != number of children buffers."
);
xacc
::
error
(
"[qreg::weighted_sum()] error, number of observable terms != "
"number of children buffers."
);
}
for
(
int
i
=
0
;
i
<
children
.
size
();
i
++
)
{
//
std::cout << children[i]->name() << ", "
//
<< children[i]->getExpectationValueZ() << ", "
//
<< terms[i]->coefficient() << "\n";
// std::cout << children[i]->name() << ", "
// << children[i]->getExpectationValueZ() << ", "
// << terms[i]->coefficient() << "\n";
sum
+=
children
[
i
]
->
getExpectationValueZ
()
*
std
::
real
(
terms
[
i
]
->
coefficient
());
sum
+=
children
[
i
]
->
getExpectationValueZ
()
*
std
::
real
(
terms
[
i
]
->
coefficient
());
}
if
(
id
)
{
sum
+=
std
::
real
(
id
->
coefficient
());
sum
+=
std
::
real
(
id
->
coefficient
());
}
return
sum
;
}
...
...
xacc/compiler/qalloc.hpp
View file @
e5594bc2
...
...
@@ -33,6 +33,8 @@ public:
std
::
map
<
std
::
string
,
int
>
counts
();
double
exp_val_z
();
void
reset
();
int
size
();
void
addChild
(
qreg
&
q
);
void
setName
(
const
char
*
name
);
void
setNameAndStore
(
const
char
*
name
);
void
store
();
...
...
xacc/utils/heterogeneous.hpp
View file @
e5594bc2
...
...
@@ -257,6 +257,7 @@ template const int& HeterogeneousMap::get<int>(const std::string key) const;
template
const
double
&
HeterogeneousMap
::
get
<
double
>(
const
std
::
string
key
)
const
;
template
const
std
::
vector
<
std
::
complex
<
double
>
>&
HeterogeneousMap
::
get
<
std
::
vector
<
std
::
complex
<
double
>>>
(
const
std
::
string
key
)
const
;
template
const
std
::
vector
<
double
>
&
HeterogeneousMap
::
get
<
std
::
vector
<
double
>>
(
const
std
::
string
key
)
const
;
template
const
std
::
vector
<
double
>
&
HeterogeneousMap
::
get_with_throw
<
std
::
vector
<
double
>>
(
const
std
::
string
key
)
const
;
template
<
typename
...
Types
>
class
Variant
:
public
mpark
::
variant
<
Types
...
>
{
...
...
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