Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docker tests #187

Merged
merged 75 commits into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from 67 commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
f1c7861
aaa
shahidee44 Feb 20, 2023
4aa29cd
Add docker tests
Q-lds Feb 21, 2023
12e38cb
Add qvm and quilc as dockers in the tests
Q-lds Feb 21, 2023
c7bcb5d
Update rigetti dockers
Q-lds Feb 21, 2023
3f0a7ae
Update docker run commands
Q-lds Feb 21, 2023
32b8fe4
remove -it from docker run
Q-lds Feb 21, 2023
1cbfdc9
Update tests
Q-lds Feb 21, 2023
84cb719
Update
Q-lds Feb 21, 2023
cfc5fb2
Updates
Q-lds Feb 21, 2023
4c504b2
Update
Q-lds Feb 21, 2023
bd98d19
add -id flag
Q-lds Feb 21, 2023
b3c9b2f
update aws tests
Q-lds Feb 21, 2023
1803cd3
Update tests
Q-lds Feb 21, 2023
768f1eb
Update check_connection requirement in QAOABaseBackendCloud
Q-lds Feb 21, 2023
9172543
Add MagicMock to AWS tests
Q-lds Feb 21, 2023
c4aa597
Fix MagicMock issue
Q-lds Feb 21, 2023
3420b40
Update magicMock conditions
Q-lds Feb 21, 2023
a5c119a
Mock available_qpus
Q-lds Feb 21, 2023
a4f2df1
Update aws docker tests
Q-lds Feb 22, 2023
e01b11c
fix aws tests
Q-lds Feb 22, 2023
0665df9
Update aws docker tests
Q-lds Feb 22, 2023
b9d8e79
Add aws cli
Q-lds Feb 22, 2023
8f9e3e9
Update awscli
Q-lds Feb 22, 2023
7932a63
Update awscli
Q-lds Feb 22, 2023
656761f
Update test_dev.yml
Q-lds Feb 22, 2023
d148bc1
Update cli aws
Q-lds Feb 22, 2023
d645d2c
update cli
Q-lds Feb 22, 2023
308cef6
add braket_api pytest flag
Q-lds Feb 22, 2023
096a612
Update braket_api marker
Q-lds Feb 22, 2023
1107294
Update docker instructions
Q-lds Feb 22, 2023
b305671
Update docker
Q-lds Feb 22, 2023
c548da1
update tests
Q-lds Feb 22, 2023
3d5be2e
Merge branch 'dev' into dev_azure_tests
shahidee44 Feb 22, 2023
201b1f3
update ibmq and az tests
Q-lds Feb 23, 2023
7ff0d08
Merge branch 'dev' into docker_aws
Q-lds Feb 23, 2023
f9c2312
Update tests
Q-lds Feb 23, 2023
d9dd66a
Update test_dev.yml
Q-lds Feb 23, 2023
8415d9e
Update az
Q-lds Feb 23, 2023
f95e0f1
Update test_dev.yml
Q-lds Feb 23, 2023
3a5e5c8
Update az
Q-lds Feb 23, 2023
0d798e2
Update ibm yml
Q-lds Feb 23, 2023
aae34c0
Add import os to tests
Q-lds Feb 23, 2023
36e4e25
Test
Q-lds Feb 23, 2023
98a9116
Update
Q-lds Feb 23, 2023
3fbe0f9
Update az
Q-lds Feb 23, 2023
5febbac
Update az
Q-lds Feb 23, 2023
f3b8103
update az
Q-lds Feb 23, 2023
2cea6b7
update az
Q-lds Feb 23, 2023
95e4e90
update az
Q-lds Feb 23, 2023
8d6e3ff
update az
Q-lds Feb 23, 2023
f71b8a1
update az
Q-lds Feb 23, 2023
11021b9
update az
Q-lds Feb 23, 2023
0180c17
add az cli
Q-lds Feb 23, 2023
a9aa434
Merge branch 'dev' into dev_azure_tests
shahidee44 Feb 23, 2023
2406a70
update tests
Q-lds Feb 23, 2023
41afda5
Change dockerfile
Q-lds Feb 23, 2023
23effd8
Merge branch 'dev' into docker_aws
Q-lds Feb 23, 2023
d52c366
Update unittests, notebooks and error messages
shahidee44 Feb 23, 2023
d5f7255
Merge branch 'dev' into dev_azure_tests
shahidee44 Feb 23, 2023
ea20d8c
Missing docstring quotation marks
shahidee44 Feb 24, 2023
ddc2712
Updated docstrings
shahidee44 Feb 28, 2023
bf8d30d
Merge pull request #190 from entropicalabs/dev_azure_tests
Q-lds Mar 1, 2023
aeb0206
Update tests
Q-lds Mar 9, 2023
cdb1702
update test workflow to run selectively
vishal-ph Mar 10, 2023
461c31f
updated label conditional
vishal-ph Mar 10, 2023
efbe30b
syntax fix attempt
vishal-ph Mar 10, 2023
7b6e865
trigger for running test onlabel removal
vishal-ph Mar 10, 2023
fc6ec88
toggle based on draft status
vishal-ph Mar 13, 2023
1979b26
Update docker-compose.yml
Q-lds Mar 13, 2023
0deb49c
Update Dockerfile
Q-lds Mar 13, 2023
2b8b22f
Update flags and test_dev.yml
shahidee44 Mar 14, 2023
1077857
Merge branch 'dev' into docker_aws
vishal-ph Mar 21, 2023
f179d50
Update test_workflows.py
vishal-ph Mar 21, 2023
fad417f
run test on PR draft conditional is false
vishal-ph Mar 21, 2023
985ad99
Merge branch 'docker_aws' of github.com:entropicalabs/openqaoa into d…
vishal-ph Mar 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 31 additions & 19 deletions .github/workflows/test_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ name: test_dev
# Controls when the workflow will run
on:
pull_request:
types: [review_requested, ready_for_review]
branches:
- dev
unlabel: [halted_testing]
# Manual trigger
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
if: ${{ github.event.label.name != 'halted_testing' }}
strategy:
fail-fast: false
matrix:
Expand All @@ -30,7 +33,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 +45,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 api)' --cov --cov-report=xml:coverage.xml

- name: Upload coverage reports to Codecov with GitHub Action
uses: codecov/codecov-action@v3
Expand All @@ -70,6 +81,7 @@ jobs:
files: ./coverage.xml

docs:
if: ${{ github.event.label.name != 'halted_testing' }}
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
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM 292282985366.dkr.ecr.us-east-1.amazonaws.com/amazon-braket-pytorch-jobs:1.9.1-gpu-py38-cu111-ubuntu20.04
Q-lds marked this conversation as resolved.
Show resolved Hide resolved

RUN mkdir -p /openqaoa

ADD ./ /openqaoa/

RUN pip3 install /openqaoa/.
27 changes: 27 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: '3'

networks:
local_bridge:
external: true

Q-lds marked this conversation as resolved.
Show resolved Hide resolved
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
1 change: 1 addition & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ 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"')
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"')
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()))
Q-lds marked this conversation as resolved.
Show resolved Hide resolved

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