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
fc19af69
Commit
fc19af69
authored
Feb 15, 2019
by
Zachary Parks
Browse files
Python API changes to allow variables in IRGenerator declarations
Signed-off-by:
Zachary Parks
<
1zp@ornl.gov
>
parent
1c531f68
Changes
1
Hide whitespace changes
Inline
Side-by-side
python/xacc.py
View file @
fc19af69
from
_pyxacc
import
*
import
os
,
time
,
json
import
platform
import
sys
import
sys
,
re
import
sysconfig
import
argparse
import
inspect
...
...
@@ -163,6 +163,9 @@ class DecoratorFunction(ABC):
self
.
__dict__
.
update
(
kwargs
)
self
.
accelerator
=
None
self
.
src
=
'
\n
'
.
join
(
inspect
.
getsource
(
self
.
function
).
split
(
'
\n
'
)[
1
:])
self
.
processVariables
()
compiler
=
getCompiler
(
'xacc-py'
)
if
self
.
accelerator
==
None
:
if
'accelerator'
in
self
.
kwargs
:
...
...
@@ -186,7 +189,19 @@ class DecoratorFunction(ABC):
def
overrideAccelerator
(
self
,
acc
):
self
.
accelerator
=
acc
def
processVariables
(
self
):
g
=
re
.
findall
(
'=(\w+)'
,
self
.
src
)
frame
=
inspect
.
currentframe
()
for
thing
in
g
:
if
thing
in
frame
.
f_back
.
f_locals
[
'f'
].
__globals__
:
if
isinstance
(
frame
.
f_back
.
f_locals
[
'f'
].
__globals__
[
thing
],
str
):
real
=
"'"
+
frame
.
f_back
.
f_locals
[
'f'
].
__globals__
[
thing
]
+
"'"
else
:
real
=
str
(
frame
.
f_back
.
f_locals
[
'f'
].
__globals__
[
thing
])
self
.
src
=
self
.
src
.
replace
(
'='
+
thing
,
'='
+
real
)
del
frame
def
nParameters
(
self
):
return
self
.
getFunction
().
nParameters
()
...
...
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