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 22 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
3 changes: 2 additions & 1 deletion .github/workflows/pypi-test-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ jobs:
runs-on: ${{matrix.os}}
strategy:
matrix:
os: [ubuntu-22.04, macos-11, windows-2022]
#os: [ubuntu-22.04, macos-11, windows-2022]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: add back macOS and (possibly) windows

os: [ubuntu-22.04]
python: ["cp311"]

steps:
Expand Down
14 changes: 0 additions & 14 deletions .github/workflows/qokit-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,6 @@ jobs:

steps:
- uses: actions/checkout@v3
###### Alex: to be used in future version once permissions issue is resolved
# - name: black
# uses: lgeiger/black-action@master
# with:
# args: .
# - name: Apply black formatting if reviewdog found formatting errors
# if: "${{ failure() }}"
# run: |
# black .
# - name: Commit black formatting results
# if: "${{ failure() }}"
# uses: stefanzweifel/git-auto-commit-action@v4
# with:
# commit_message: ":art: Format Python code with psf/black push"
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
Expand Down
17 changes: 2 additions & 15 deletions .github/workflows/qokit-python-only.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,6 @@ jobs:

steps:
- uses: actions/checkout@v3
###### Alex: to be used in future version once permissions issue is resolved
# - name: black
# uses: lgeiger/black-action@master
# with:
# args: .
# - name: Apply black formatting if reviewdog found formatting errors
# if: "${{ failure() }}"
# run: |
# black .
# - name: Commit black formatting results
# if: "${{ failure() }}"
# uses: stefanzweifel/git-auto-commit-action@v4
# with:
# commit_message: ":art: Format Python code with psf/black push"
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
Expand All @@ -47,7 +33,8 @@ jobs:
black --check .
- name: pip install
run: |
QOKIT_PYTHON_ONLY=1 pip install .
export QOKIT_PYTHON_ONLY=True
pip install .
- name: Run tests and coverage
run: |
pytest --cov=qokit -rs tests --cov-fail-under=70
Expand Down
34 changes: 8 additions & 26 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,22 @@
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")

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 python_only is None:
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")


with open("README.md", "r") as f:
long_description = f.read()
def cbuild():
if python_only is None:
subprocess.call(["make", "-C", path])


setup(ext_modules=extensions, cmdclass={"build_ext": SimulatorBuild} if sys.platform == "win32" else {}),
cbuild()
setup(ext_modules=extensions)
35 changes: 35 additions & 0 deletions tests/test_simulators_builds.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
###############################################################################
# // 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

# when fail tests only runs in Github actions. Change to true to run locally
IN_GITHUB_ACTIONS = os.getenv("GITHUB_ACTIONS") == "fales"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo! "fales" -> "fails"



@pytest.mark.skipif(IN_GITHUB_ACTIONS, reason="Test runs only in Github Actions.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: add graceful handling of this in python pipeline

def test_simulator_c_bild():
assert "c" in get_available_simulator_names("x")
assert "c" in get_available_simulator_names("xyring")
assert "c" in get_available_simulator_names("xycomplete")


@pytest.mark.skipif(IN_GITHUB_ACTIONS, reason="Test runs only in Github Actions.")
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")


@pytest.mark.skipif(IN_GITHUB_ACTIONS, reason="Test runs only in Github Actions.")
@pytest.mark.timeout(15)
def test_simulator_timing_test():
theta = np.random.uniform(0, 1, 280)
f = get_qaoa_labs_objective(20, 140)
f(theta)
pass
Loading