diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000000..17cfc2415d --- /dev/null +++ b/.clang-format @@ -0,0 +1,191 @@ +--- +Language: Cpp +# BasedOnStyle: LLVM +AccessModifierOffset: -2 +AlignAfterOpenBracket: Align +AlignArrayOfStructures: None +AlignConsecutiveMacros: None +AlignConsecutiveAssignments: None +AlignConsecutiveBitFields: None +AlignConsecutiveDeclarations: None +AlignEscapedNewlines: Right +AlignOperands: Align +AlignTrailingComments: true +AllowAllArgumentsOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortEnumsOnASingleLine: true +AllowShortBlocksOnASingleLine: Never +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AllowShortLambdasOnASingleLine: All +AllowShortIfStatementsOnASingleLine: Never +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: MultiLine +AttributeMacros: + - __capability +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: None +BreakBeforeConceptDeclarations: true +BreakBeforeBraces: Attach +BreakBeforeInheritanceComma: false +BreakInheritanceList: BeforeColon +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeColon +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 125 +CommentPragmas: '^ IWYU pragma:' +QualifierAlignment: Leave +CompactNamespaces: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DeriveLineEnding: true +DerivePointerAlignment: false +DisableFormat: false +EmptyLineAfterAccessModifier: Never +EmptyLineBeforeAccessModifier: LogicalBlock +ExperimentalAutoDetectBinPacking: false +PackConstructorInitializers: BinPack +BasedOnStyle: '' +ConstructorInitializerAllOnOneLineOrOnePerLine: false +AllowAllConstructorInitializersOnNextLine: true +FixNamespaceComments: true +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IfMacros: + - KJ_IF_MAYBE +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + SortPriority: 0 + CaseSensitive: false + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + SortPriority: 0 + CaseSensitive: false + - Regex: '.*' + Priority: 1 + SortPriority: 0 + CaseSensitive: false +IncludeIsMainRegex: '(Test)?$' +IncludeIsMainSourceRegex: '' +IndentAccessModifiers: false +IndentCaseLabels: false +IndentCaseBlocks: false +IndentGotoLabels: true +IndentPPDirectives: None +IndentExternBlock: AfterExternBlock +IndentRequires: false +IndentWidth: 4 +IndentWrappedFunctionNames: false +InsertTrailingCommas: None +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: true +LambdaBodyIndentation: Signature +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 2 +ObjCBreakBeforeNestedBlockParam: true +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakOpenParenthesis: 0 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PenaltyIndentedWhitespace: 0 +PointerAlignment: Right +PPIndentWidth: -1 +ReferenceAlignment: Pointer +ReflowComments: true +RemoveBracesLLVM: false +SeparateDefinitionBlocks: Leave +ShortNamespaceLines: 1 +SortIncludes: CaseSensitive +SortJavaStaticImport: Before +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeParensOptions: + AfterControlStatements: true + AfterForeachMacros: true + AfterFunctionDefinitionName: false + AfterFunctionDeclarationName: false + AfterIfMacros: true + AfterOverloadedOperator: false + BeforeNonEmptyParentheses: false +SpaceAroundPointerQualifiers: Default +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyBlock: false +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: Never +SpacesInConditionalStatement: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInLineCommentPrefix: + Minimum: 1 + Maximum: -1 +SpacesInParentheses: false +SpacesInSquareBrackets: false +SpaceBeforeSquareBrackets: false +BitFieldColonSpacing: Both +Standard: Latest +StatementAttributeLikeMacros: + - Q_EMIT +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 8 +UseCRLF: false +UseTab: Never +WhitespaceSensitiveMacros: + - STRINGIZE + - PP_STRINGIZE + - BOOST_PP_STRINGIZE + - NS_SWIFT_NAME + - CF_SWIFT_NAME +... diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 83bd329dae..88d445c66a 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,9 +1,9 @@ A# Description -> :memo: Please include a summary of the change. -> -> * Please also include relevant motivation and context. -> * List any dependencies that are required for this change. +> :memo: Please include a summary of the change. +> +> * Please also include relevant motivation and context. +> * List any dependencies that are required for this change. ## Type of change @@ -22,9 +22,9 @@ Note: Please delete options that are not relevant. ## Tests > :memo: Please describe the tests that you ran to verify your changes. -> -> * Provide instructions so we can reproduce. -> * Please also list any relevant details for your test configuration. +> +> * Provide instructions so we can reproduce. +> * Please also list any relevant details for your test configuration. **Test Configuration**: @@ -34,4 +34,5 @@ Note: Please delete options that are not relevant. - [ ] I have commented my code, particularly in hard-to-understand areas. - [ ] I have made corresponding changes to the documentation. - [ ] My changes generate no new warnings. -- [ ] I have added tests that prove my fix is effective or that my feature works.B \ No newline at end of file +- [ ] I have installed and run `pre-commit` on the files I edited or added. +- [ ] I have added tests that prove my fix is effective or that my feature works. diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 0000000000..d1c414e245 --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -0,0 +1,31 @@ +name: Run pre-commit + +on: + pull_request: + branches: [ main ] + push: + branches: [ main ] + +jobs: + pre-commit: + name: Format + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [3.7] + + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + submodules: recursive + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Pre-commit + uses: pre-commit/action@v3.0.0 + with: + extra_args: --hook-stage manual diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000000..8d509c3145 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,61 @@ +exclude: ^hls4ml\/templates\/(vivado|quartus)\/(ap_types|ac_types)\/ + +repos: +- repo: https://github.com/psf/black + rev: 22.10.0 + hooks: + - id: black + language_version: python3 + args: ['--line-length=125', + '--skip-string-normalization'] + +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.3.0 + hooks: + - id: check-added-large-files + - id: check-case-conflict + - id: check-merge-conflict + - id: check-symlinks + - id: check-yaml + - id: debug-statements + - id: end-of-file-fixer + - id: mixed-line-ending + - id: requirements-txt-fixer + - id: trailing-whitespace + +- repo: https://github.com/PyCQA/isort + rev: 5.10.1 + hooks: + - id: isort + +- repo: https://github.com/asottile/pyupgrade + rev: v3.1.0 + hooks: + - id: pyupgrade + args: ["--py36-plus"] + +- repo: https://github.com/asottile/setup-cfg-fmt + rev: v2.1.0 + hooks: + - id: setup-cfg-fmt + +- repo: https://github.com/pycqa/flake8 + rev: 5.0.4 + hooks: + - id: flake8 + exclude: docs/conf.py + additional_dependencies: [flake8-bugbear, flake8-print] + args: ['--max-line-length=125', # github viewer width + '--extend-ignore=E203'] # E203 is not PEP8 compliant + +- repo: https://github.com/mgedmin/check-manifest + rev: "0.48" + hooks: + - id: check-manifest + stages: [manual] + +- repo: https://github.com/jmduarte/p-clang-format + rev: "v1.0.3" + hooks: + - id: p-clang-format + types_or: [c++, c, cuda] diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 769ce7c165..c68142eb34 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,29 +1,30 @@ # How to Contribute -We'd love to accept your patches and contributions to this project. +We'd love to accept your patches and contributions to this project. There are just a few small guidelines you need to follow. ## Discussion -Share your proposal via [Github Issues](https://github.com/fastmachinelearning/hls4ml/issues). -If you are looking for some issues to get started with, we have a list of [good first issues](https://github.com/fastmachinelearning/hls4ml/labels/good%20first%20issue) in the issue tracker. +Share your proposal via [GitHub Issues](https://github.com/fastmachinelearning/hls4ml/issues). +If you are looking for some issues to get started with, we have a list of [good first issues](https://github.com/fastmachinelearning/hls4ml/labels/good%20first%20issue) in the issue tracker. We also welcome submissions to improve the documentation. ## Pull Request -All submissions, including submissions by project members, require review. -We use GitHub pull requests for this purpose. +All submissions, including submissions by project members, require review. +We use GitHub pull requests for this purpose. Consult [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more information on using pull requests. 1. In the pull request description, clearly document all changes made and the expected behavior. 1. If you are introducing new functionality, add at least one unit test under the `test` folder and make sure it passes before you submit the pull request. 1. Similarly, if you are fixing a bug, add at least one unit test under the `test` folder such that the master branch fails the test and your branch passes the test. +1. Install and run `pre-commit` on the files that you have edited. We are adiabatically turning on linting for the full repository (see [#678](https://github.com/fastmachinelearning/hls4ml/pull/678)). 1. Submit the pull request to the [main](https://github.com/fastmachinelearning/hls4ml) branch. ## Code Reviews -We will review your contribution and, if any additional fixes or modifications are necessary, may provide feedback to guide you. -When accepted, your pull request will be merged to the repository. +We will review your contribution and, if any additional fixes or modifications are necessary, may provide feedback to guide you. +When accepted, your pull request will be merged to the repository. ## Code of Conduct diff --git a/MANIFEST.in b/MANIFEST.in index a3482f0847..e36cf22407 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,7 +1,6 @@ -include LICENSE -include README.md -graft example-prjs +include LICENSE README.md CONTRIBUTING.md CITATION.cff pyproject.toml setup.py setup.cfg .clang-format graft example-models graft test recursive-include hls4ml/templates * +global-exclude .git .gitmodules .gitlab-ci.yml include hls4ml/backends/vivado_accelerator/supported_boards.json diff --git a/setup.cfg b/setup.cfg index e8239e9e67..bc6dbf643d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,12 +1,12 @@ [metadata] -description-file = README.md name = hls4ml -author = hls4ml Team -license = Apache 2.0 description = Machine learning in FPGAs using HLS -url = https://fastmachinelearning.org/hls4ml long_description = file: README.md long_description_content_type = text/markdown +url = https://fastmachinelearning.org/hls4ml +author = hls4ml Team +license = Apache-2.0 +license_file = LICENSE classifiers = Development Status :: 3 - Alpha Intended Audience :: Developers @@ -14,25 +14,24 @@ classifiers = License :: OSI Approved :: Apache Software License Programming Language :: C++ Programming Language :: Python :: 3 - Programming Language :: Python :: 3.7 - Programming Language :: Python :: 3.8 - Programming Language :: Python :: 3.9 + Programming Language :: Python :: 3 :: Only Topic :: Software Development :: Libraries Topic :: Software Development :: Libraries :: Python Modules +description_file = README.md [options] -python_requires = >=3.7 packages = find: install_requires = - numpy - six - pyyaml + calmjs.parse h5py + numpy onnx>=1.4.0 - calmjs.parse - tabulate pydigitalwavetools==1.1 + pyyaml qkeras + six + tabulate +python_requires = >=3.7 include_package_data = True scripts = scripts/hls4ml @@ -41,7 +40,15 @@ pytest_randomly.random_seeder = hls4ml = hls4ml:reseed [options.extras_require] -profiling = +profiling = + matplotlib pandas seaborn - matplotlib + +[check-manifest] +ignore = + .github/** + docs/** + .pre-commit-config.yaml + Jenkinsfile + hls4ml/_version.py