Skip to content

Commit

Permalink
Merge pull request #60 from zpparks314/zpparks/pyxacc-work
Browse files Browse the repository at this point in the history
Changing pyxacc import/config to xacc
  • Loading branch information
Alex McCaskey authored Aug 28, 2018
2 parents f775cf2 + e83e973 commit 4081285
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 65 deletions.
8 changes: 4 additions & 4 deletions docker/expo_tutorial/deuteron/Deuteron_H2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
"from openfermionpsi4 import run_psi4\n",
"from openfermion.hamiltonians import MolecularData\n",
"import numpy as np\n",
"import pyxacc as xacc\n",
"from pyxacc import InstructionParameter\n",
"import pyxaccvqe as vqe\n",
"from pyxaccvqe import PauliOperator\n",
"import xacc\n",
"from xacc import InstructionParameter\n",
"import xaccvqe as vqe\n",
"from xaccvqe import PauliOperator\n",
"%matplotlib inline"
]
},
Expand Down
4 changes: 2 additions & 2 deletions docker/expo_tutorial/h2/H2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"outputs": [],
"source": [
"import numpy as np\n",
"import pyxacc as xacc\n",
"import pyxaccvqe as vqe\n",
"import xacc\n",
"import xaccvqe as vqe\n",
"from openfermion.hamiltonians import MolecularData\n",
"from openfermionpsi4 import run_psi4\n",
"from openfermion.transforms import get_fermion_operator"
Expand Down
16 changes: 8 additions & 8 deletions docs/source/dwave.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,28 @@ To install this plugin, run the following
$ git clone https://github.com/ornl-qci/xacc-dwave
$ cd xacc-dwave && mkdir build && cd build
$ cmake .. -DXACC_DIR=$HOME/.xacc
$ cmake .. -DXACC_DIR=$HOME/.xacc
Alternatively, if you installed the XACC Python bindings, then you can run
Alternatively, if you installed the XACC Python bindings, then you can run

.. code::
$ cmake .. -DXACC_DIR=$(python -m pyxacc -L)
$ cmake .. -DXACC_DIR=$(python -m xacc -L)
ensuring that the ``pyxacc`` module is in your ``PYTHONPATH``.
ensuring that the ``xacc`` module is in your ``PYTHONPATH``.

You have now installed the D-Wave plugin. It is located in ``$XACC_ROOT/plugins``,
You have now installed the D-Wave plugin. It is located in ``$XACC_ROOT/plugins``,
where ``XACC_ROOT`` is your XACC install prefix.

Setting Credentials
-------------------

In order to target the D-Wave Qubist remote resources you must provide
In order to target the D-Wave Qubist remote resources you must provide
XACC with your API key. By default
XACC will search for a config file at ``$HOME/.dwave_config``.

If you installed the XACC Python bindings, then you can run
If you installed the XACC Python bindings, then you can run

.. code::
$ python -m pyxacc -c dwave -k YOURAPIKEY
$ python -m xacc -c dwave -k YOURAPIKEY
20 changes: 9 additions & 11 deletions docs/source/ibm.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ To install this plugin, run the following
$ git clone https://github.com/ornl-qci/xacc-ibm
$ cd xacc-ibm && mkdir build && cd build
$ cmake .. -DXACC_DIR=$HOME/.xacc
$ cmake .. -DXACC_DIR=$HOME/.xacc
If you installed the XACC Python bindings, then you can run
If you installed the XACC Python bindings, then you can run

.. code::
$ cmake .. -DXACC_DIR=$(python -m pyxacc -L)
$ cmake .. -DXACC_DIR=$(python -m xacc -L)
ensuring that pyxacc is in your ``PYTHONPATH``.
ensuring that xacc is in your ``PYTHONPATH``.

You have now installed the IBM plugin. It is located in ``$XACC_ROOT/plugins``,
where ``XACC_ROOT`` is your XACC install prefix.
Expand All @@ -32,11 +32,11 @@ Setting Credentials

In order to target the IBM Quantum Experience, you must provide XACC with your API key.

If you installed the XACC Python bindings, then you can run
If you installed the XACC Python bindings, then you can run

.. code::
$ python -m pyxacc -c ibm -k YOURAPIKEY
$ python -m xacc -c ibm -k YOURAPIKEY
Alternatively, open the file ``$HOME/.ibm_config``, and add the following contents
Expand Down Expand Up @@ -94,13 +94,13 @@ kernel code for this example can be found in `Scalable Quantum Simulation of Mol
Ry(qreg[1], 7.8539752);
Rx(qreg[0], 1.57079);
}
__qpu__ g1Term (qbit qreg, float theta) {
initializeState(qreg, theta);
cbit creg[1];
creg[0] = MeasZ(qreg[0]);
}
__qpu__ g2Term (qbit qreg, float theta) {
initializeState(qreg, theta);
cbit creg[1];
Expand All @@ -120,7 +120,7 @@ kernel code for this example can be found in `Scalable Quantum Simulation of Mol
creg[1] = MeasZ(qreg[1]);
creg[0] = MeasZ(qreg[0]);
}
__qpu__ g5Term(qbit qreg, float theta) {
initializeState(qreg, theta);
cbit creg[2];
Expand Down Expand Up @@ -179,5 +179,3 @@ kernel code for this example can be found in `Scalable Quantum Simulation of Mol
return 0;
}
21 changes: 9 additions & 12 deletions docs/source/rigetti.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ To install this plugin, run the following
$ git clone https://github.com/ornl-qci/xacc-rigetti
$ cd xacc-rigetti && mkdir build && cd build
$ cmake .. -DXACC_DIR=$HOME/.xacc
$ cmake .. -DXACC_DIR=$HOME/.xacc
If you installed the XACC Python bindings, then you can run
If you installed the XACC Python bindings, then you can run

.. code::
$ cmake .. -DXACC_DIR=$(python -m pyxacc -L)
$ cmake .. -DXACC_DIR=$(python -m xacc -L)
ensuring that pyxacc is in your ``PYTHONPATH``.
ensuring that xacc is in your ``PYTHONPATH``.

You have now installed the Rigetti plugin. It is located in ``$XACC_ROOT/plugins``
and ``$XACC_ROOT/plugins``, where ``XACC_ROOT`` is your XACC install prefix.
Expand All @@ -34,11 +34,11 @@ In order to target the Rigetti QVM you must provide XACC with your API key. By d
XACC will use your PyQuil Config file at ``$HOME/.pyquil_config``.
See `Connecting to the Rigetti Forest <http://pyquil.readthedocs.io/en/latest/getting_started.html#connecting-to-the-rigetti-forest>`_ for information on creating this file.

If you installed the XACC Python bindings, then you can run
If you installed the XACC Python bindings, then you can run

.. code::
$ python -m pyxacc -c rigetti -k YOURAPIKEY -u YOURUSERID
$ python -m xacc -c rigetti -k YOURAPIKEY -u YOURUSERID
Rigetti Command Line Arguments
------------------------------
Expand All @@ -54,8 +54,8 @@ The Rigetti plugin exposes the following command line arguments

Rigetti QVM Tutorial
---------------------
Let's test out the Rigetti Accelerator by creating a code to
perform quantum teleportation.
Let's test out the Rigetti Accelerator by creating a code to
perform quantum teleportation.

Create a new directory called test-xacc-rigetti and cd into it. Let's now create a
test-xacc-rigetti.cpp file and get it started with the following boilerplate code:
Expand Down Expand Up @@ -313,7 +313,7 @@ the Hydrogen molecule (code taken from `Scalable Quantum Simulation of Molecular
import pyquil.api as forest
from pyquil.gates import X, Z, H, CNOT, RX, RY, RZ
import numpy as np
import pyxacc as xacc
import xacc
# Pyquil State Preparation circuit gen
def statePrep(qs, angle):
Expand Down Expand Up @@ -410,6 +410,3 @@ This will produce a file called ``pyquil_out.csv``. Plotting this shows the
correct expectation values from the simulation.
.. image:: ../assets/pyquil_out.png
11 changes: 5 additions & 6 deletions docs/source/tnqvm.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,15 @@ To install this plugin, run the following
$ git clone https://github.com/ornl-qci/tnqvm
$ cd tnqvm && mkdir build && cd build
$ cmake .. -DXACC_DIR=$HOME/.xacc
$ cmake .. -DXACC_DIR=$HOME/.xacc
If you installed the XACC Python bindings, then you can run
If you installed the XACC Python bindings, then you can run

.. code::
$ cmake .. -DXACC_DIR=$(python -m pyxacc -L)
$ cmake .. -DXACC_DIR=$(python -m xacc -L)
ensuring that pyxacc is in your ``PYTHONPATH``.
ensuring that xacc is in your ``PYTHONPATH``.

You have now installed the TNQVM plugin. It is located in ``$XACC_ROOT/plugins``,
You have now installed the TNQVM plugin. It is located in ``$XACC_ROOT/plugins``,
where ``XACC_ROOT`` is your XACC install prefix.

7 changes: 3 additions & 4 deletions docs/source/xacc-vqe.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@ To install this plugin, run the following
$ git clone https://github.com/ornl-qci/xacc-vqe
$ cd xacc-vqe && mkdir build && cd build
$ cmake .. -DXACC_DIR=$HOME/.xacc
$ cmake .. -DXACC_DIR=$HOME/.xacc
If you installed the XACC Python bindings, then you can run

.. code::
$ cmake .. -DXACC_DIR=$(python -m pyxacc -L)
$ cmake .. -DXACC_DIR=$(python -m xacc -L)
ensuring that pyxacc is in your ``PYTHONPATH``.
ensuring that xacc is in your ``PYTHONPATH``.

You have now installed the XACC-VQE plugin. It is located in ``$XACC_ROOT/plugins``,
where ``XACC_ROOT`` is your XACC install prefix.

36 changes: 18 additions & 18 deletions tools/framework/xacc-framework
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import multiprocessing
import platform

try:
import pyxacc as xacc
import xacc
except ImportError:
print('Error - cannot import XACC Python Bindings. Exiting')
sys.exit()
Expand All @@ -34,7 +34,7 @@ def parse_args(args):
parser.add_argument("-i", "--initialize", action='store_true', help="Initialize the framework.", required=False)
parser.add_argument("-L", "--location", action='store_true', help="Print the path to the XACC install location.", required=False)
parser.add_argument("-b", "--branch", default='master',type=str, help="Print the path to the XACC install location.", required=False)

opts = parser.parse_args(args)
return opts

Expand All @@ -43,14 +43,14 @@ availablePluginUrls = { 'xacc-scaffold' : ornlqci+'/xacc-scaffold',
'xacc-rigetti' : ornlqci+'/xacc-rigetti',
'xacc-dwave' : ornlqci+'/xacc-dwave',
'xacc-ibm' : ornlqci+'/xacc-ibm',
'xacc-python' : ornlqci+'/xacc-python',
'xacc-python' : ornlqci+'/xacc-python',
'tnqvm' : ornlqci+'/tnqvm',
'ibm' : ornlqci+'/xacc-ibm',
'rigetti' : ornlqci+'/xacc-rigetti',
'scaffold' : ornlqci+'/xacc-scaffold',
'dwave' : ornlqci+'/xacc-dwave',
'vqe' : ornlqci+'/xacc-vqe',
'xacc-dwsapi-embedding' : ornlqci+'/xacc-dwsapi-embedding',
'dwave' : ornlqci+'/xacc-dwave',
'vqe' : ornlqci+'/xacc-vqe',
'xacc-dwsapi-embedding' : ornlqci+'/xacc-dwsapi-embedding',
'xacc-projectq' : ornlqci+'/xacc-projectq' }

def mkdir_p(path):
Expand Down Expand Up @@ -83,8 +83,8 @@ def initialize():
file.close()

file = open(xaccHome+'/.internal_plugins', 'w')
xaccLocation = os.path.dirname(os.path.realpath(xacc.__file__))

xaccLocation = os.path.dirname(os.path.realpath(xacc.__file__))
if platform.system() == "Darwin":
libname1 = "libxacc-quantum-gate.dylib"
libname2 = "libxacc-quantum-aqc.dylib"
Expand All @@ -96,10 +96,10 @@ def initialize():
file.write(xaccLocation+'/lib/'+libname1+'\n')
if xaccLocation+'/lib/'+libname2+'\n' not in contents:
file.write(xaccLocation+'/lib/'+libname2+'\n')

file.write(contents)
file.close()

def main(argv=None):
opts = parse_args(sys.argv[1:])

Expand All @@ -109,18 +109,18 @@ def main(argv=None):

if not os.path.exists(os.environ['HOME']+'/.xacc/.internal_plugins'):
initialize()
# pyxacc can be installed in site-packages/xacc-...-egg or

# pyxacc can be installed in site-packages/xacc-...-egg or
# in ${XACC_DIR}/lib/python, we need to figure out which one
xaccLocation = os.path.dirname(os.path.realpath(xacc.__file__))
if opts.location:
print(xaccLocation)
sys.exit(0)
print('XACC Install Location = ', xaccLocation)
xacc_cwd = os.getcwd()

cpus = str(multiprocessing.cpu_count())
if not opts.make_threads == None:
if not opts.make_threads == None:
cpus = str(opts.make_threads)

branch = 'master'
Expand All @@ -145,7 +145,7 @@ def main(argv=None):
print("--------------------------- ERROR -----------------------------")
print("")
exit()

# Create a CMakeLists.txt file
cmakeContents = """
project(""" + plugin + """-project LANGUAGES CXX)
Expand All @@ -168,17 +168,17 @@ def main(argv=None):
mkdir_p(plugin+'-install/build')
os.chdir(plugin+'-install')

# Write the CMakeLists file
# Write the CMakeLists file
cmakelists = open("CMakeLists.txt", "w")
cmakelists.write("%s" % cmakeContents)
cmakelists.close()

# Execute the build
os.chdir('build')
cmakecmd = ['cmake', '..']
subprocess.check_call(cmakecmd, stderr=subprocess.STDOUT, shell=False)
subprocess.check_call(['make', '-j'+cpus], stderr=subprocess.STDOUT, shell=False)

os.chdir(xacc_cwd)

if __name__ == "__main__":
Expand Down

0 comments on commit 4081285

Please sign in to comment.