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
cdd00fdb
Commit
cdd00fdb
authored
Feb 02, 2018
by
Mccaskey, Alex
Browse files
Adding xacc.setCredentials python function
Signed-off-by:
Alex McCaskey
<
mccaskeyaj@ornl.gov
>
parent
cdf048f4
Changes
1
Hide whitespace changes
Inline
Side-by-side
python/xacc-py.cpp
View file @
cdd00fdb
...
...
@@ -24,6 +24,54 @@ std::shared_ptr<GateInstruction> create(const std::string& name, std::vector<int
return
g
;
}
void
setCredentials
(
const
std
::
string
&
accelerator
,
const
std
::
string
&
apiKey
,
const
std
::
string
&
url
=
""
,
const
std
::
string
&
userId
=
""
)
{
std
::
string
filename
=
std
::
string
(
std
::
getenv
(
"HOME"
))
+
"/"
;
std
::
stringstream
s
;
if
(
accelerator
==
"ibm"
)
{
filename
+=
".ibm_config"
;
std
::
string
tmpUrl
=
url
;
if
(
url
.
empty
())
{
tmpUrl
=
"https://quantumexperience.mybluemix.net"
;
}
s
<<
"url: "
<<
tmpUrl
<<
"
\n
"
;
s
<<
"key: "
<<
apiKey
<<
"
\n
"
;
}
else
if
(
accelerator
==
"rigetti"
)
{
filename
+=
".pyquil_config"
;
if
(
userId
.
empty
())
{
xacc
::
error
(
"You must provide your Rigetti QVM User Id."
);
}
std
::
string
tmpUrl
=
url
;
if
(
url
.
empty
())
{
tmpUrl
=
"https://api.rigetti.com/qvm"
;
}
s
<<
"url: "
<<
tmpUrl
<<
"
\n
"
;
s
<<
"key: "
<<
apiKey
<<
"
\n
"
;
s
<<
"user_id: "
<<
userId
<<
"
\n
"
;
}
else
if
(
accelerator
==
"dwave"
)
{
filename
+=
".dwave_config"
;
std
::
string
tmpUrl
=
url
;
if
(
url
.
empty
())
{
tmpUrl
=
"https://qubist.dwavesys.com"
;
}
s
<<
"url: "
<<
tmpUrl
<<
"
\n
"
;
s
<<
"key: "
<<
apiKey
<<
"
\n
"
;
}
if
(
!
s
.
str
().
empty
())
{
std
::
ofstream
out
(
filename
);
out
<<
s
.
str
();
out
.
close
();
}
return
;
}
PYBIND11_MODULE
(
pyxacc
,
m
)
{
m
.
doc
()
=
"Python bindings for XACC. XACC provides a plugin infrastructure for "
"programming, compiling, and executing quantum kernels in a language and "
...
...
@@ -185,7 +233,13 @@ PYBIND11_MODULE(pyxacc, m) {
gateqir
.
def
(
py
::
init
<>
(),
"The constructor"
);
gateqir
.
def
(
"addKernel"
,
&
xacc
::
quantum
::
GateQIR
::
addKernel
,
"Add an Kernel to this GateQIR."
);
gatesub
.
def
(
"create"
,
&
create
,
""
,
py
::
arg
(
"name"
),
py
::
arg
(
"qbits"
),
py
::
arg
(
"params"
)
=
std
::
vector
<
InstructionParameter
>
{});
gatesub
.
def
(
"create"
,
&
create
,
""
,
py
::
arg
(
"name"
),
py
::
arg
(
"qbits"
),
py
::
arg
(
"params"
)
=
std
::
vector
<
InstructionParameter
>
{
});
m
.
def
(
"setCredentials"
,
&
setCredentials
,
"This function sets the users credentials for the given accelerator. URL and UserId are optional parameters."
,
py
::
arg
(
"accelerator"
),
py
::
arg
(
"apiKey"
),
py
::
arg
(
"url"
)
=
std
::
string
(
""
),
py
::
arg
(
"userId"
)
=
std
::
string
(
""
));
}
...
...
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