Skip to content

Commit

Permalink
Refactor c++ code and add github actions (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
kotarotanahashi authored Sep 22, 2021
1 parent aeebf5c commit 54f60fd
Show file tree
Hide file tree
Showing 73 changed files with 2,191 additions and 8,058 deletions.
27 changes: 27 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: 2

updates:
- package-ecosystem: docker
directory: "/"
schedule:
interval: "daily"
allow:
# Allow both direct and indirect updates for all packages
- dependency-type: "all"
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: "daily"
allow:
# Allow both direct and indirect updates for all packages
- dependency-type: "all"

- package-ecosystem: pip
directory: "/"
insecure-external-code-execution: allow
versioning-strategy: auto
schedule:
interval: "daily"
allow:
# Allow both direct and indirect updates for all packages
- dependency-type: "all"
179 changes: 179 additions & 0 deletions .github/workflows/build_and_upolad.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
name: Build&Upload

on:
workflow_dispatch:
pull_request:
release:
types:
- released
push:
branches:
- feature/addGithubActions

env:
Python_Version: 3.9

jobs:
build_sdist:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
name: Install Python
with:
python-version: ${{env.Python_Version}}
- name: Build sdist
run: |
pip install -r requirements.txt
python setup.py sdist
- uses: actions/upload-artifact@v2
with:
name: artifact
path: dist/*.tar.gz
retention-days: 1

codecov:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
name: Install Python
with:
python-version: ${{env.Python_Version}}
- name: Install PyQUBO
run: |
python -m pip install .
- name: Generate Codecov Report
run: |
pip install -r requirements.txt
python -m coverage run -m unittest discover .
- name: Upload Codecov Report
run: |
codecov
doctest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
name: Install Python
with:
python-version: ${{env.Python_Version}}

- name: Install PyQUBO
run: |
python -m pip install .
- name: Install dependencies
run: |
pip install -r requirements.txt
pip install -r requirements_doctest.txt
sphinx-build -W -b html docs docs/_build/html
- name: Run Doctest
run: |
make doctest
build_wheels:
name: Build wheels on ${{ matrix.os }} ${{matrix.arch}}
runs-on: ${{ matrix.os }}
env:
CIBW_DEPENDENCY_VERSIONS: pinned
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
arch: [x86_64, AMD64, i686, arm64]
python: [36, 37, 38, 39]
exclude:
- os: ubuntu-latest
arch: AMD64
- os: ubuntu-latest
arch: arm64

- os: macos-latest
arch: AMD64
- os: macos-latest
arch: i686
- os: macos-latest
arch: arm64
python: 36
- os: macos-latest
arch: arm64
python: 37

- os: windows-latest
arch: x86_64
- os: windows-latest
arch: i686
- os: windows-latest
arch: arm64

include:
- os: ubuntu-latest
CIBW_PLATFORM: linux
CIBW_BUILD: "cp3*-manylinux*"
CIBW_BEFORE_ALL: ""
CIBW_BEFORE_BUILD: "pip install scikit-build"
CIBW_REPAIR_WHEEL_COMMAND: "auditwheel repair -w {dest_dir} {wheel}"

- os: macos-latest
CIBW_PLATFORM: macos
CIBW_BUILD: "cp3*-macosx*"
CIBW_BEFORE_ALL: ""
CIBW_BEFORE_BUILD: "pip install git+https://github.com/scikit-build/scikit-build.git@master"
CIBW_REPAIR_WHEEL_COMMAND: "delocate-listdeps {wheel} && delocate-wheel --require-archs {delocate_archs} -w {dest_dir} {wheel}"


- os: windows-latest
CIBW_PLATFORM: windows
CIBW_BUILD: "cp3*-win_amd64*"
CIBW_BEFORE_ALL: ""
CIBW_BEFORE_BUILD: "pip install delvewheel scikit-build"
CIBW_REPAIR_WHEEL_COMMAND: "delvewheel repair -w {dest_dir} {wheel}"

fail-fast: false

steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
name: Install Python
with:
python-version: ${{env.Python_Version}}

- name: Build wheels on ${{ matrix.CIBW_PLATFORM }} ${{matrix.arch}}
uses: pypa/cibuildwheel@v1.12.0
env:
CIBW_PLATFORM: ${{ matrix.CIBW_PLATFORM }}
CIBW_BUILD: cp${{matrix.python}}-*
CIBW_SKIP: "cp35-*"
CIBW_ENVIRONMENT:
CFLAGS="-flto -Ofast -pipe"
CXXFLAGS="-flto -Ofast -pipe"
CIBW_ARCHS: ${{matrix.arch}}
CIBW_BEFORE_TEST: "pip install -r requirements.txt"
CIBW_TEST_COMMAND: "python -m coverage run -m unittest discover {package}"
CIBW_DEPENDENCY_VERSIONS: ${{ env.CIBW_DEPENDENCY_VERSIONS }}
CIBW_BEFORE_BUILD: ${{matrix.CIBW_BEFORE_BUILD}}
CIBW_BEFORE_ALL: ${{matrix.CIBW_BEFORE_ALL}}
CIBW_REPAIR_WHEEL_COMMAND: ${{matrix.CIBW_REPAIR_WHEEL_COMMAND}}
CIBW_BUILD_VERBOSITY: 3

- uses: actions/upload-artifact@v2
with:
name: artifact
path: ./wheelhouse/*.whl
retention-days: 1

upload_pypi:
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
if: github.event_name == 'release'
steps:
- uses: actions/download-artifact@v2
with:
name: artifact
path: dist
- uses: pypa/gh-action-pypi-publish@release/v1
with:
user: ${{ secrets.PYPI_USERNAME }}
password: ${{ secrets.PYPI_PASSWORD }}
71 changes: 71 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [ master, main ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ master, main ]
schedule:
- cron: '31 12 * * 5'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'cpp', 'python' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
# Learn more:
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed

steps:
- name: Checkout repository
uses: actions/checkout@v2

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
46 changes: 26 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
cmake_minimum_required(VERSION 3.11)
cmake_minimum_required(VERSION 3.20)

project(cpp_pyqubo)

set(CMAKE_INTERPROCEDURAL_OPTIMIZATION True)

set(CXX_STANDARD_REQUIRED TRUE)
set(CMAKE_VERBOSE_MAKEFILE TRUE)

set(CMAKE_CXX_STANDARD 14)
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
set(CMAKE_C_FLAGS "-Ofast -pipe" )
set(CMAKE_CXX_FLAGS "-Ofast -pipe")
set(CMAKE_C_FLAGS_RELEASE "-Ofast -pipe")
set(CMAKE_CXX_FLAGS_RELEASE "-Ofast -pipe")

include(external/boost_assert.cmake)
include(external/boost_config.cmake)
include(external/boost_container.cmake)
include(external/boost_container_hash.cmake)
include(external/boost_core.cmake)
include(external/boost_detail.cmake)
include(external/boost_integer.cmake)
include(external/boost_intrusive.cmake)
include(external/boost_move.cmake)
include(external/boost_static_assert.cmake)
include(external/boost_type_traits.cmake)
include(external/cimod.cmake)
include(external/eigen.cmake)
include(external/pybind11.cmake)
include_directories(cpp_dimod)
add_subdirectory(src)



include(external/googletest.cmake)
add_subdirectory(tests)
include(external/robin_hood.cmake)

pybind11_add_module(cpp_pyqubo src/main.cpp)

target_compile_definitions(cpp_pyqubo PRIVATE VERSION_INFO=${PYQUBO_VERSION_INFO})
target_compile_features(cpp_pyqubo PRIVATE cxx_std_17)
target_compile_options(cpp_pyqubo PRIVATE
$<$<CXX_COMPILER_ID:GNU>: -Ofast -Wall -Wno-terminate>
$<$<CXX_COMPILER_ID:AppleClang>: -Ofast -Wno-exceptions>
$<$<CXX_COMPILER_ID:MSVC>: /O2 /wd4297>
)
target_include_directories(cpp_pyqubo PRIVATE ${Boost_INCLUDE_DIRS})
2 changes: 0 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,3 @@ recursive-include pyqubo *
recursive-include tests *
recursive-include src *
recursive-include external *
recursive-include include *
recursive-include cpp_dimod *
16 changes: 9 additions & 7 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ By calling ``model.to_qubo()``, we get the resulting QUBO.
>>> pprint(qubo)
{('s1', 's1'): -160.0,
('s1', 's2'): 64.0,
('s1', 's3'): 224.0,
('s1', 's4'): 32.0,
('s2', 's2'): -96.0,
('s3', 's1'): 224.0,
('s3', 's2'): 112.0,
('s2', 's3'): 112.0,
('s2', 's4'): 16.0,
('s3', 's3'): -196.0,
('s4', 's1'): 32.0,
('s4', 's2'): 16.0,
('s4', 's3'): 56.0,
('s3', 's4'): 56.0,
('s4', 's4'): -52.0}

.. _integration:
Expand Down Expand Up @@ -108,12 +108,12 @@ or

.. code-block:: shell
python setup.py install
python -m pip install .
Supported Python Versions
-------------------------

Python 3.5, 3.6, 3.7, 3.8 and 3.9 are supported.
Python 3.7, 3.8 and 3.9 are supported.

Supported Operating Systems
---------------------------
Expand All @@ -131,12 +131,14 @@ Run all tests.

.. code-block:: shell
export USE_TEST=1
python -m unittest discover test
Show coverage report.

.. code-block:: shell
export USE_TEST=1
coverage run -m unittest discover
coverage html
Expand Down
2 changes: 2 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fixes:
- "/home/runner/work/pyqubo/pyqubo/::"
6 changes: 0 additions & 6 deletions cpp_dimod/.CMakeLists.txt

This file was deleted.

Loading

0 comments on commit 54f60fd

Please sign in to comment.