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
xacc
Commits
0c1b782d
Commit
0c1b782d
authored
Jun 15, 2020
by
Daniel Claudino
Browse files
Changed qubit indexing in UCCSD ansatz
Signed-off-by:
Daniel Claudino
<
6d3@ornl.gov
>
parent
6703c3ea
Changes
2
Show whitespace changes
Inline
Side-by-side
python/examples/uccsd.py
View file @
0c1b782d
import
xacc
xacc
.
set_verbose
(
True
)
opstr
=
'''(0.174073,0) Z
2
Z3 +
(0.1202,0) Z
1
Z3 +
opstr
=
'''(0.174073,0) Z
1
Z3 +
(0.1202,0) Z
2
Z3 +
(0.165607,0) Z1 Z2 +
(0.165607,0) Z0 Z3 +
(0.1202,0) Z0 Z
2
+
(-0.0454063,0) Y0 Y
1
X
2
X3 +
(0.1202,0) Z0 Z
1
+
(-0.0454063,0) Y0 Y
2
X
1
X3 +
(-0.220041,0) Z3 +
(-0.106477,0) +
(0.17028,0) Z0 +
(-0.220041,0) Z
2
+
(0.17028,0) Z
1
+
(-0.0454063,0) X0 X
1
Y
2
Y3 +
(0.0454063,0) X0 Y
1
Y
2
X3 +
(0.168336,0) Z0 Z
1
+
(0.0454063,0) Y0 X
1
X
2
Y3'''
(-0.220041,0) Z
1
+
(0.17028,0) Z
2
+
(-0.0454063,0) X0 X
2
Y
1
Y3 +
(0.0454063,0) X0 Y
2
Y
1
X3 +
(0.168336,0) Z0 Z
2
+
(0.0454063,0) Y0 X
2
X
1
Y3'''
op
=
xacc
.
getObservable
(
'pauli'
,
opstr
)
...
...
quantum/plugins/circuits/uccsd/uccsd.cpp
View file @
0c1b782d
...
...
@@ -44,6 +44,7 @@ bool UCCSD::expand(const xacc::HeterogeneousMap &runtimeOptions) {
// Compute the number of parameters
auto
_nOccupied
=
(
int
)
std
::
ceil
(
nElectrons
/
2.0
);
auto
_nVirtual
=
nQubits
/
2
-
_nOccupied
;
auto
_nOrbitals
=
_nOccupied
+
_nVirtual
;
auto
nSingle
=
_nOccupied
*
_nVirtual
;
auto
nDouble
=
nSingle
*
(
nSingle
+
1
)
/
2
;
auto
_nParameters
=
nSingle
+
nDouble
;
...
...
@@ -80,8 +81,8 @@ bool UCCSD::expand(const xacc::HeterogeneousMap &runtimeOptions) {
auto
singleParams
=
slice
(
params
,
0
,
nSingle
);
auto
doubleParams1
=
slice
(
params
,
nSingle
,
2
*
nSingle
);
auto
doubleParams2
=
slice
(
params
,
2
*
nSingle
);
std
::
vector
<
std
::
function
<
int
(
int
)
>>
fs
{[](
int
i
)
{
return
2
*
i
;
},
[](
int
i
)
{
return
2
*
i
+
1
;
}};
std
::
vector
<
std
::
function
<
int
(
int
,
int
)
>>
fs
{[](
int
i
,
int
n
)
{
return
i
;
},
[](
int
i
,
int
n
)
{
return
i
+
n
;
}};
using
OpType
=
std
::
vector
<
std
::
pair
<
int
,
bool
>>
;
int
count
=
0
;
...
...
@@ -94,10 +95,10 @@ bool UCCSD::expand(const xacc::HeterogeneousMap &runtimeOptions) {
for
(
int
s
=
0
;
s
<
2
;
s
++
)
{
auto
ti
=
fs
[
s
];
auto
oi
=
fs
[
1
-
s
];
auto
vt
=
ti
(
vs
);
auto
vo
=
oi
(
vs
);
auto
ot
=
ti
(
os
);
auto
oo
=
oi
(
os
);
auto
vt
=
ti
(
vs
,
_nOrbitals
);
auto
vo
=
oi
(
vs
,
_nOrbitals
);
auto
ot
=
ti
(
os
,
_nOrbitals
);
auto
oo
=
oi
(
os
,
_nOrbitals
);
OpType
op1
{{
vt
,
1
},
{
ot
,
0
}},
op2
{{
ot
,
1
},
{
vt
,
0
}};
FermionOperator
op
(
op1
,
1.0
,
singleParams
[
count
]);
...
...
@@ -152,10 +153,10 @@ bool UCCSD::expand(const xacc::HeterogeneousMap &runtimeOptions) {
auto
ia
=
fs
[
sa
];
auto
ib
=
fs
[
sb
];
auto
v1a
=
ia
(
vs1
);
auto
o1a
=
ia
(
os1
);
auto
v2b
=
ib
(
vs2
);
auto
o2b
=
ib
(
os2
);
auto
v1a
=
ia
(
vs1
,
_nOrbitals
);
auto
o1a
=
ia
(
os1
,
_nOrbitals
);
auto
v2b
=
ib
(
vs2
,
_nOrbitals
);
auto
o2b
=
ib
(
os2
,
_nOrbitals
);
OpType
op5
{{
v1a
,
1
},
{
o1a
,
0
},
{
v2b
,
1
},
{
o2b
,
0
}},
op6
{{
o2b
,
1
},
{
o1a
,
0
},
{
v2b
,
1
},
{
o2b
,
0
}};
...
...
@@ -268,10 +269,14 @@ bool UCCSD::expand(const xacc::HeterogeneousMap &runtimeOptions) {
}
}
for
(
int
i
=
nElectrons
-
1
;
i
>=
0
;
i
--
)
{
std
::
size_t
j
=
(
std
::
size_t
)
i
;
for
(
int
i
=
(
nElectrons
/
2
)
-
1
;
i
>=
0
;
i
--
)
{
std
::
size_t
alpha
=
(
std
::
size_t
)
i
;
auto
xGate
=
gateRegistry
->
createInstruction
(
"X"
,
std
::
vector
<
std
::
size_t
>
{
j
});
gateRegistry
->
createInstruction
(
"X"
,
std
::
vector
<
std
::
size_t
>
{
alpha
});
insertInstruction
(
0
,
xGate
);
std
::
size_t
beta
=
(
std
::
size_t
)(
i
+
_nOrbitals
);
xGate
=
gateRegistry
->
createInstruction
(
"X"
,
std
::
vector
<
std
::
size_t
>
{
beta
});
insertInstruction
(
0
,
xGate
);
}
return
true
;
...
...
Write
Preview
Markdown
is supported
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