Skip to content

Commit

Permalink
Merge pull request #187 from entropicalabs/docker_aws
Browse files Browse the repository at this point in the history
Add docker tests
  • Loading branch information
vishal-ph authored Mar 21, 2023
2 parents f2787b5 + 985ad99 commit 9985058
Show file tree
Hide file tree
Showing 13 changed files with 365 additions and 111 deletions.
48 changes: 29 additions & 19 deletions .github/workflows/test_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ on:
jobs:
# This workflow contains a single job called "build"
build:
if : github.event.pull_request.draft == false
strategy:
fail-fast: false
matrix:
Expand All @@ -30,7 +31,10 @@ jobs:
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python }}

- name: Log in with Azure
uses: azure/login@v1
with:
creds: '${{ secrets.AZURE_CREDENTIALS }}'
- name: Install OpenQAOA
run: |
python -m pip install --user virtualenv
Expand All @@ -39,29 +43,34 @@ jobs:
python -m pip install --upgrade pip
pip install .[tests]
pip install ipykernel
- name: Install qvm
- name: Setup IBMQ account
env:
IBMQ_TOKEN: ${{ secrets.IBMQ_TOKEN }}
run: |
find /usr/lib -name "libffi.so*"
sudo ln -s /usr/lib/x86_64-linux-gnu/libffi.so /usr/lib/x86_64-linux-gnu/libffi.so.6
wget -q https://downloads.rigetti.com/qcs-sdk/forest-sdk-2.23.0-linux-deb.tar.bz2
tar -xf forest-sdk-2.23.0-linux-deb.tar.bz2
cd forest-sdk-2.23.0-linux-deb/
sudo apt-get update
sudo apt-get install -y screen libblas-dev libblas3 libgfortran5 liblapack-dev liblapack3
sudo ./forest-sdk-2.23.0-linux-deb.run
qvm --version
quilc --version
echo "Starting qvm and quilc"
screen -d -m qvm -S
screen -d -m quilc -S
cd ..
IBMQ_TOKEN=$IBMQ_TOKEN
source env/bin/activate
python -c'from qiskit import IBMQ; import os; IBMQ.save_account(os.environ.get("IBMQ_TOKEN"))'
- name: Setup AWS
env:
ACCESS_KEY: ${{ secrets.ACCESS_KEY }}
SECRET_ACCESS_KEY: ${{ secrets.SECRET_ACCESS_KEY }}
run: |
python -m pip install awscli
aws configure set aws_access_key_id $ACCESS_KEY
aws configure set aws_secret_access_key $SECRET_ACCESS_KEY
aws configure set region us-west-1
aws configure set output json
- name: Build the docker stack
run: |
docker login -u AWS -p $(aws ecr get-login-password --region us-east-1) 292282985366.dkr.ecr.us-east-1.amazonaws.com
docker network create local_bridge
docker build -t amazon-braket-oq-dev .
docker-compose up -d
- name: Run tests
run: |
source env/bin/activate
ipython kernel install --name "env" --user
python -m pytest -v -m 'not (qpu or api or docker_aws)' --cov --cov-report=xml:coverage.xml
pytest tests/ -v -m '(not qpu or sim)' --cov --cov-report=xml:coverage.xml
- name: Upload coverage reports to Codecov with GitHub Action
uses: codecov/codecov-action@v3
Expand All @@ -70,6 +79,7 @@ jobs:
files: ./coverage.xml

docs:
if : github.event.pull_request.draft == false
runs-on: ubuntu-latest
steps:
- name: Check out openqaoa
Expand Down
52 changes: 30 additions & 22 deletions .github/workflows/test_main_linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,19 @@ jobs:
# The type of runner that the job will run on
runs-on: ${{ matrix.os }}

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python }}

- name: Log in with Azure
uses: azure/login@v1
with:
creds: '${{ secrets.AZURE_CREDENTIALS }}'
- name: Install OpenQAOA
run: |
python -m pip install --user virtualenv
Expand All @@ -37,37 +40,42 @@ jobs:
python -m pip install --upgrade pip
pip install .[tests]
pip install ipykernel
- name: QVM on ubuntu
if: ${{ matrix.os=='ubuntu-latest' }}
- name: Setup IBMQ account
env:
IBMQ_TOKEN: ${{ secrets.IBMQ_TOKEN }}
run: |
find /usr/lib -name "libffi.so*"
sudo ln -s /usr/lib/x86_64-linux-gnu/libffi.so /usr/lib/x86_64-linux-gnu/libffi.so.6
wget -q https://downloads.rigetti.com/qcs-sdk/forest-sdk-2.23.0-linux-deb.tar.bz2
tar -xf forest-sdk-2.23.0-linux-deb.tar.bz2
cd forest-sdk-2.23.0-linux-deb/
sudo apt-get update
sudo apt-get install -y screen libblas-dev libblas3 libgfortran5 liblapack-dev liblapack3
sudo ./forest-sdk-2.23.0-linux-deb.run
qvm --version
quilc --version
echo "Starting qvm and quilc"
screen -d -m qvm -S
screen -d -m quilc -S
cd ..
IBMQ_TOKEN=$IBMQ_TOKEN
source env/bin/activate
python -c'from qiskit import IBMQ; import os; IBMQ.save_account(os.environ.get("IBMQ_TOKEN"))'
- name: Setup AWS
env:
ACCESS_KEY: ${{ secrets.ACCESS_KEY }}
SECRET_ACCESS_KEY: ${{ secrets.SECRET_ACCESS_KEY }}
run: |
python -m pip install awscli
aws configure set aws_access_key_id $ACCESS_KEY
aws configure set aws_secret_access_key $SECRET_ACCESS_KEY
aws configure set region us-west-1
aws configure set output json
- name: Build the docker stack
run: |
docker login -u AWS -p $(aws ecr get-login-password --region us-east-1) 292282985366.dkr.ecr.us-east-1.amazonaws.com
docker network create local_bridge
docker build -t amazon-braket-oq-dev .
docker-compose up -d
- name: Run tests
run: |
source env/bin/activate
ipython kernel install --name "env" --user
python -m pytest -v -m 'not (qpu or api or docker_aws)'
pytest tests/ -v -m '(not qpu or api)' --cov --cov-report=xml:coverage.xml
- name: Upload coverage reports to Codecov with GitHub Action
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
files: ./coverage.xml


docs:
runs-on: ubuntu-latest
steps:
Expand Down
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# The dockerfile for OpenQAOA braket jobs
FROM 292282985366.dkr.ecr.us-east-1.amazonaws.com/amazon-braket-pytorch-jobs:1.9.1-gpu-py38-cu111-ubuntu20.04

RUN mkdir -p /openqaoa

ADD ./ /openqaoa/

RUN pip3 install /openqaoa/.
28 changes: 28 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Docker compose mostly used for testing purposes: it provides dockers to interact with OQ's braket jobs and rigetti's QVM
version: '3'

networks:
local_bridge:
external: true

services:
amazon-braket-oq-dev:
image: amazon-braket-oq-dev
networks:
- local_bridge
qvm:
container_name: qvm
image: rigetti/qvm:latest
command: ["-S"]
networks:
- local_bridge
ports:
- 5000:5000
quilc:
container_name: quilc
image: rigetti/quilc:latest
command: ["-P", "-S" ]
networks:
- local_bridge
ports:
- 5555:5555
45 changes: 44 additions & 1 deletion examples/12_testing_azure.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Default QAOA on the IonQ Emulator"
"## Default QAOA on the IonQ Emulator\n",
"\n",
"Before using OpenQAOA with Azure quantum, you will be required to log in to your azure account through the Azure CLI. This can be done via `az login` in your command line terminal after installing the Azure CLI. After following the steps required for authentication, you will be able to use the Azure backend with OpenQAOA!"
]
},
{
Expand All @@ -37,6 +39,15 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"In order to create the Azure Device for OpenQAOA, you have to provide a valid resource ID that points to the Workspace that contains access to the QPU (and emulator) providers, `resource_id`, and the location of the azure server hosting that workspace, `az_location`."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Once you've created the Azure Device, you can use the OpenQAOA workflow like you normally do for other backends. (Only this time you pass in the Azure Device instead!)\n",
"\n",
"Let's generate a sample problem, and solve it using an OpenQAOA workflow"
]
},
Expand Down Expand Up @@ -209,13 +220,27 @@
"q.result.optimized"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"And that's it! You've completed your first OpenQAOA Workflow run on the Azure platform with the IonQ Emulator."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## A more advanced QAOA workflow on the Rigetti QVM"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's try another QAOA Workflow, but this time on the Rigetti QVM hosted on Azure."
]
},
{
"cell_type": "code",
"execution_count": 17,
Expand Down Expand Up @@ -366,6 +391,13 @@
"## RQAOA on a QVM"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The RQAOA Workflow also works with Azure. (Note: RQAOA requires multiple loops of the QAOA algorithm, this algorithm can require many executions on the QPU. Thus, it will take a while!)"
]
},
{
"cell_type": "code",
"execution_count": 22,
Expand Down Expand Up @@ -1643,6 +1675,17 @@
"source": [
"r.result"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"And there you have it! You've just performed QAOA and RQAOA on Emulators hosted by Azure.\n",
"Azure Quantum also contains QPUs hosted by hardware providers like Rigetti and IonQ. \n",
"We can't wait to see what you can do with OpenQAOA and this new backend!\n",
"If you find something that you'd like to have as a feature or a bug while using the Azure backend. \n",
"Raise an issue and we will keep in touch!"
]
}
],
"metadata": {
Expand Down
4 changes: 3 additions & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ markers =
api: marks tests that require a coonection to a QC cloud (deselect with '-m "not api"')
qvm: marks tests that require an attive Rigetti QVM and QILC compiler (deselect with '-m "not qvm"')
docker_aws: marks tests that require to build aws docker (deselect with '-m "not docker_aws"')
notebook: marks tests that run on jupyter noteboks (deselect with '-m "not notebook"')
braket_api: marks tests that require valid AWS credentials (no QPU) (deselect with '-m "not braket_api"')
notebook: marks tests that run on jupyter noteboks (deselect with '-m "not notebook"')
sim: marks tests that run on remote Simulators (deselect with '-m "not sim"')
4 changes: 2 additions & 2 deletions src/openqaoa-azure/backends/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ def __init__(self, device_name: str, resource_id: str, az_location: str):
device_name: `str`
The name of the Azure remote QPU/Simulator to be used
resource_id: `str`
resource_id
The resource_id of the Workplace
az_location: `str`
az_location
The location of the Azure Workplace. e.g. "westus"
"""

self.resource_id = resource_id
Expand Down
16 changes: 4 additions & 12 deletions src/openqaoa-qiskit/backends/qaoa_qiskit_qpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,11 @@ def __init__(
False,
None,
]:
if type(self.device).__name__ == "DeviceAzure":
raise Exception(
"Connection to Azure was made. Error connecting to the specified backend."
)
else:
raise Exception(
"Connection to IBMQ was made. Error connecting to the specified backend."
)
raise Exception("Connection to {} was made. Error connecting to the specified backend.".format(self.device.device_location.upper()))

else:
if type(self.device).__name__ == "DeviceAzure":
raise Exception("Error connecting to Azure.")
else:
raise Exception("Error connecting to IBMQ.")

raise Exception("Error connecting to {}.".format(self.device.device_location.upper()))

if self.device.n_qubits < self.n_qubits:
raise Exception(
Expand Down
Loading

0 comments on commit 9985058

Please sign in to comment.