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

Issue 41 cimulator buid #47

Open
wants to merge 73 commits into
base: bump-build-version
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
c5aab9c
add tests for simulators build and timing
alex124585 Mar 5, 2024
0a6b0b3
black format
alex124585 Mar 5, 2024
182fdea
fix numpy
alex124585 Mar 5, 2024
ceff2dc
Code refactor
alex124585 Mar 5, 2024
a61a7d5
fix pyhton test
alex124585 Mar 5, 2024
dfc96c8
Update test_simulators_builds.py
alex124585 Mar 22, 2024
09757b3
Update setup.py
alex124585 Mar 27, 2024
9170337
Update qokit-python-only.yml
alex124585 Mar 27, 2024
762d6a0
Update qokit-package.yml
alex124585 Mar 27, 2024
26c8ee3
ran black
Mar 27, 2024
1c2c483
Update setup.py
alex124585 Mar 27, 2024
ebce252
Update setup.py
alex124585 Mar 28, 2024
88e346e
ran black
Mar 28, 2024
473a90a
Merge branch 'issue_41_cimulator_buid' of https://github.com/jpmorgan…
Mar 28, 2024
2526bc3
Update setup.py
alex124585 Mar 29, 2024
4f931ca
Update test_simulators_builds.py
alex124585 Mar 29, 2024
1262f89
remove dup logic for QOKIT_PYTHON_ONLY
Apr 26, 2024
13b2616
black fix
Apr 26, 2024
2ce3526
Check for pypi failure
Apr 30, 2024
eb842dc
Check for pypi failure
Apr 30, 2024
0d1b067
Check for pypi failure
Apr 30, 2024
7f174d1
Check for pypi failure
Apr 30, 2024
53b86e5
added pypi test for all environment
May 9, 2024
35bb1aa
added pypi test for all environment
May 9, 2024
aafca21
Update test_simulators_builds.py
alex124585 May 10, 2024
b254d52
Update test_simulators_builds.py
alex124585 May 10, 2024
031709d
Update pypi-test-publish.yml
alex124585 May 10, 2024
c3b337b
add code for graceful test handling
May 10, 2024
fb7e4ef
Merge branch 'issue_41_cimulator_buid' of https://github.com/jpmorgan…
May 10, 2024
24dbfdf
Merge branch 'main' into issue_41_cimulator_buid
alex124585 May 10, 2024
3fc210e
Update qokit-python-only.yml
alex124585 May 10, 2024
1bf6ac0
Merge branch 'main' into issue_41_cimulator_buid
rsln-s May 14, 2024
6d48cf3
Update qokit-python-only.yml
alex124585 May 14, 2024
66df968
Update qokit-python-only.yml
alex124585 May 14, 2024
84680bf
Merge branch 'bump-build-version' into issue_41_cimulator_buid
rsln-s Aug 1, 2024
b7406cb
cleanup
rsln-s Aug 1, 2024
ed4d664
fix flag
rsln-s Aug 1, 2024
a1177d0
cleanup
rsln-s Aug 1, 2024
d92aa65
change how environment variable is handled
rsln-s Aug 1, 2024
f8d31b9
black
rsln-s Aug 1, 2024
83da77c
rename
rsln-s Aug 1, 2024
18d0757
no need to skip the tests
rsln-s Aug 1, 2024
d81c7cf
catch windows-specific exception
rsln-s Aug 1, 2024
e0ebef8
now build tests are run correctly
rsln-s Aug 1, 2024
617763b
timeout is hard to get right in GH actions, removing
rsln-s Aug 1, 2024
2ff4228
add another flag
rsln-s Aug 1, 2024
c01ccd2
revert change
rsln-s Aug 1, 2024
c33d328
removing unused flag
rsln-s Aug 1, 2024
ad6f002
change the order of installs
rsln-s Aug 1, 2024
16f4890
Revert "change the order of installs"
rsln-s Aug 1, 2024
295a89c
try adding explicit dependency on types-pkg-resources==0.1.3
rsln-s Aug 2, 2024
8740ced
debug: try building in GH actions manualy
rsln-s Aug 2, 2024
66d3c0b
Revert "debug: try building in GH actions manualy"
rsln-s Aug 2, 2024
385f305
drop windows (losing battle), install gcc on mac
rsln-s Aug 2, 2024
ac8dff8
fix GCC install
rsln-s Aug 2, 2024
aa73b13
debug: try building in GH actions manualy
rsln-s Aug 2, 2024
1d9204c
Update setup.py
alex124585 Sep 12, 2024
952f05b
Update qokit-python-only-unix.yml
alex124585 Sep 12, 2024
f369822
Update qokit-python-only-unix.yml
alex124585 Sep 12, 2024
9189ab2
Update qokit-package.yml
alex124585 Sep 12, 2024
3d3f230
Update qokit-package.yml
alex124585 Sep 12, 2024
97b741a
Update qokit-python-only-unix.yml
alex124585 Sep 12, 2024
3616e58
Update qokit-package.yml
alex124585 Sep 12, 2024
17c0854
Update test_simulator_build.py
alex124585 Sep 12, 2024
6d488e2
Update test_simulator_build.py
alex124585 Sep 12, 2024
ff64638
black run
Sep 12, 2024
6d93092
Update qokit-package.yml
alex124585 Sep 12, 2024
fd42d6d
Update qokit-python-only-unix.yml
alex124585 Sep 12, 2024
7194c2c
Update test_simulator_build.py
alex124585 Sep 12, 2024
2c6d1fd
black format
Sep 12, 2024
6170795
Update test_simulator_build.py
alex124585 Sep 12, 2024
694a6d3
black format
Sep 12, 2024
d624e21
Update test_simulator_build.py
alex124585 Sep 12, 2024
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
22 changes: 14 additions & 8 deletions .github/workflows/qokit-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,39 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
os: [ubuntu-latest, macos-latest]
python-version: ["3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pipreqs black addheader pytest-cov pip-licenses
python -m pip install --upgrade pip
pip install pipreqs black addheader pytest-cov pip-licenses
- name: Install GCC (macOS only)
if: runner.os == 'macOS'
run: |
brew install gcc
export PATH=$PATH:/opt/homebrew/
- name: black check
run: |
black --check .
- name: pip install
run: |
pip install .
# make -C qokit/fur/c/csim/src/
- name: Run tests
run: |
pytest --cov=qokit --cov-fail-under=75 -rs tests
pytest --cov=qokit --cov-fail-under=75 -rs tests
- name: License check
run: |
pip-licenses --format=markdown --order=license
pip-licenses --format=markdown --order=license

- name: SPDX check
run: |
addheader -t header.txt .
grep -L -f header.txt */*.py
addheader -t header.txt .
grep -L -f header.txt */*.py
2 changes: 1 addition & 1 deletion .github/workflows/qokit-python-only-unix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
black --check .
- name: pip install
run: |
export QOKIT_PYTHON_ONLY=True
export QOKIT_PYTHON_ONLY=true
pip install .
- name: Run tests and coverage
run: |
Expand Down
46 changes: 0 additions & 46 deletions .github/workflows/qokit-python-only-win.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Some optional parts of the package require additional dependencies.

Please note that the GPU dependency is specified for CUDA 12x. For other versions of CUDA, please follow cupy installation instructions.

If compilation fails, try installing just the Python version using `QOKIT_PYTHON_ONLY=1 pip install -e .`.
If compilation fails, try installing just the Python version using `QOKIT_PYTHON_ONLY=true pip install -e .`.

Installation can be verified by running tests using `pytest`.

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ classifiers=[
version = "0.2.0"
requires-python = ">=3.9.0"
dependencies = [
'types-pkg-resources==0.1.3',
'networkx>=3.0.0',
'importlib-resources>=5.2.2',
'numba>=0.56.4,<1',
Expand Down
2 changes: 1 addition & 1 deletion qokit/fur/c/csim/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

try:
lib = ctypes.cdll.LoadLibrary(str(libpath))
except OSError as e:
except (OSError, FileNotFoundError) as e:
raise ImportError("You must compile the C simulator before running the code. Please follow the instructions in README.md") from e


Expand Down
34 changes: 11 additions & 23 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,28 @@
import sys


environment_variable_name = "QOKIT_NO_C_ENV"
QOKIT_PYTHON_ONLY = False
QOKIT_NO_C_ENV = False # used for tests only

environment_variable_value = os.environ.get(environment_variable_name, None)

if environment_variable_value is not None:
QOKIT_NO_C_ENV = True

path = "./qokit/fur/c/csim/src/"

sources = [os.path.join(path, "diagonal.c"), os.path.join(path, "fur.c"), os.path.join(path, "qaoa_fur.c")]
PYTHON_ONLY = os.environ.get("QOKIT_PYTHON_ONLY") == "true"

sources = [os.path.join(path, "diagonal.c"), os.path.join(path, "fur.c"), os.path.join(path, "qaoa_fur.c")]
extensions = []
if not QOKIT_PYTHON_ONLY:
if not PYTHON_ONLY:
extensions.append(
Extension("simulator", sources=sources, include_dirs=[os.path.join(path, "")], extra_compile_args=["/d2FH4-"] if sys.platform == "win32" else [])
)


class SimulatorBuild(build_ext):
def run(self):
try:
if not QOKIT_PYTHON_ONLY:
if QOKIT_NO_C_ENV:
raise Exception("No C/C++ enviroment setup")
subprocess.call(["make", "-C", path])
super().run
except Exception as e:
print("No C/C++ enviroment setup to compile the C simulator. Installing Python Simulator")
def cbuild():
if not PYTHON_ONLY:
subprocess.call(["make", "-C", path])


with open("README.md", "r") as f:
long_description = f.read()
class SimulatorBuild(build_ext):
def run(self):
cbuild()
super().run


cbuild()
setup(ext_modules=extensions, cmdclass={"build_ext": SimulatorBuild} if sys.platform == "win32" else {}),
25 changes: 25 additions & 0 deletions tests/test_simulator_build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
###############################################################################
# // SPDX-License-Identifier: Apache-2.0
# // Copyright : JP Morgan Chase & Co
###############################################################################
import pytest
import os
import numpy as np
from qokit import get_qaoa_labs_objective
from qokit.fur import get_available_simulator_names

# Set up QOKIT_PYTHON_ONLY in your local enviroment for Python only
PYTHON_ONLY = os.environ.get("QOKIT_PYTHON_ONLY")


@pytest.mark.skipif(not PYTHON_ONLY, reason="Fast c/c++ simulator should be installed")
def test_simulator_lack_of_c_build():
assert "c" not in get_available_simulator_names("x")
assert "c" not in get_available_simulator_names("xyring")
assert "c" not in get_available_simulator_names("xycomplete")


def test_simulator_python_build():
assert "python" in get_available_simulator_names("x")
assert "python" in get_available_simulator_names("xyring")
assert "python" in get_available_simulator_names("xycomplete")
Loading