diff --git a/.JuliaFormatter.toml b/.JuliaFormatter.toml index 81b75a0e..462392e9 100644 --- a/.JuliaFormatter.toml +++ b/.JuliaFormatter.toml @@ -1,7 +1,7 @@ -margin = 100 -indent = 2 -whitespace_typedefs = true -whitespace_ops_in_indices = true -remove_extra_newlines = true annotate_untyped_fields_with_any = false +indent = 2 +margin = 92 normalize_line_endings = "unix" +remove_extra_newlines = true +whitespace_ops_in_indices = true +whitespace_typedefs = true diff --git a/.all-contributorsrc b/.all-contributorsrc new file mode 100644 index 00000000..2b7af14b --- /dev/null +++ b/.all-contributorsrc @@ -0,0 +1,5 @@ +{ + "projectName": "RegularizedOptimization", + "projectOwner": "JuliaSmoothOptimizers", + "files": ["README.md", "docs/src/index.md"] +} diff --git a/.cirrus.yml b/.cirrus.yml index ad5fb1d9..a5763184 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -1,25 +1,12 @@ +freebsd_instance: + image_family: freebsd-13-3 task: - matrix: - - name: FreeBSD - freebsd_instance: - image_family: freebsd-14-2 - env: - matrix: - - JULIA_VERSION: 1 - install_script: | - URL="https://raw.githubusercontent.com/ararslan/CirrusCI.jl/master/bin/install.sh" - set -x - if [ "$(uname -s)" = "Linux" ] && command -v apt; then - apt update - apt install -y curl - fi - if command -v curl; then - sh -c "$(curl ${URL})" - elif command -v wget; then - sh -c "$(wget ${URL} -q -O-)" - elif command -v fetch; then - sh -c "$(fetch ${URL} -o -)" - fi + name: FreeBSD + env: + matrix: + - JULIA_VERSION: 1 + install_script: + - sh -c "$(fetch https://raw.githubusercontent.com/ararslan/CirrusCI.jl/master/bin/install.sh -o -)" build_script: - cirrusjl build test_script: diff --git a/.copier-answers.yml b/.copier-answers.yml new file mode 100644 index 00000000..4b1074bc --- /dev/null +++ b/.copier-answers.yml @@ -0,0 +1,41 @@ +# Changes here will be overwritten by Copier +AddAllcontributors: true +AddCitationCFF: true +AddCodeOfConduct: true +AddCompatHelperCI: true +AddContributionDocs: true +AddCopierCI: false +AddDependabot: true +AddDocs: true +AddDocsCI: true +AddFormatterAndLinterConfigFiles: true +AddGitHubPRTemplate: true +AddGitHubTemplates: true +AddLintCI: true +AddLychee: true +AddMacToCI: true +AddPrecommit: true +AddTagBotCI: true +AddTestCI: true +AddWinToCI: true +Authors: Robert Baraldi and Dominique Orban +AutoIncludeTests: true +CheckExplicitImports: true +CodeOfConductContact: dominique.orban@gmail.com +ConfigIndentation: 2 +ExplicitImportsChecklist: exclude_all_qualified_accesses_are_public +JuliaIndentation: 2 +JuliaMinCIVersion: lts +JuliaMinVersion: lts +License: MPL-2.0 +LicenseCopyrightHolders: Robert Baraldi and Dominique Orban +MarkdownIndentation: 2 +PackageName: RegularizedOptimization +PackageOwner: JuliaSmoothOptimizers +PackageUUID: 196f2941-2d58-45ba-9f13-43a2532b2fa8 +RunJuliaNightlyOnCI: true +StrategyConfirmIncluded: true +StrategyLevel: 1 +StrategyReviewExcluded: true +UseCirrusCI: true +_src_path: C:\Users\mgoll\.julia\packages\BestieTemplate\jdG8v diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..cbb163ba --- /dev/null +++ b/.editorconfig @@ -0,0 +1,18 @@ +# https://editorconfig.org +root = true + +[*] +end_of_line = lf +insert_final_newline = true +charset = utf-8 +indent_style = space +trim_trailing_whitespace = true + +[*.jl] +indent_size = 2 + +[*.md] +indent_size = 2 + +[*.{yml,toml,json}] +indent_size = 2 diff --git a/.github/ISSUE_TEMPLATE/10-bug-report.yml b/.github/ISSUE_TEMPLATE/10-bug-report.yml new file mode 100644 index 00000000..1e4ae0ca --- /dev/null +++ b/.github/ISSUE_TEMPLATE/10-bug-report.yml @@ -0,0 +1,60 @@ +name: Bug Report +description: File a bug report related to running the package +title: "[Bug] " +labels: ["bug"] +body: + - type: markdown + attributes: + value: | + Thanks for taking the time to fill out this bug report! + + Please, before submitting, make sure that: + + - There is not an [existing issue](https://github.com/JuliaSmoothOptimizers/RegularizedOptimization.jl/issues) with the same question + - You have read the [contributing guide](https://JuliaSmoothOptimizers.github.io/RegularizedOptimization.jl/dev/90-contributing/) + - You are following the [code of conduct](https://github.com/JuliaSmoothOptimizers/RegularizedOptimization.jl/blob/main/CODE_OF_CONDUCT.md) + The form below should help you in filling out this issue. + - type: textarea + id: description + attributes: + label: Description + description: Describe the bug + validations: + required: true + - type: input + id: pkg-version + attributes: + label: Package Version + description: What version of the package are you running? + validations: + required: true + - type: input + id: version + attributes: + label: Julia Version + description: What version of Julia are you running? + validations: + required: true + - type: textarea + id: reproduction + attributes: + label: Reproduction steps + description: What steps led to the bug happening? Please provide a minimal reproducible example. + validations: + required: true + - type: textarea + id: logs + attributes: + label: Relevant log output + description: Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks. + render: shell + - type: dropdown + id: os + attributes: + label: "Operating System" + description: What is the impacted environment? + multiple: true + options: + - Windows + - Linux + - Mac diff --git a/.github/ISSUE_TEMPLATE/20-feature-request.yml b/.github/ISSUE_TEMPLATE/20-feature-request.yml new file mode 100644 index 00000000..c7e49736 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/20-feature-request.yml @@ -0,0 +1,41 @@ +name: "Feature Request" +description: Suggest a new feature for the package +body: + - type: markdown + attributes: + value: | + Thanks for taking the time to fill out this feature request! + + Please, before submitting, make sure that: + + - There is not an [existing issue](https://github.com/JuliaSmoothOptimizers/RegularizedOptimization.jl/issues) with the same question + - You have read the [contributing guide](https://JuliaSmoothOptimizers.github.io/RegularizedOptimization.jl/dev/90-contributing/) + - You are following the [code of conduct](https://github.com/JuliaSmoothOptimizers/RegularizedOptimization.jl/blob/main/CODE_OF_CONDUCT.md) + The form below should help you in filling out this issue. + - type: textarea + id: description + attributes: + label: Description + description: Describe the requested feature + validations: + required: true + - type: textarea + id: validation + attributes: + label: Validation and testing + description: How could we verify that the new feature works? What kind of tests can be done? + - type: textarea + id: motivation + attributes: + label: Motivation + description: Explain why this feature is relevant + - type: textarea + id: target + attributes: + label: Target audience + description: Tell more about the users of this feature, or where it could be useful + - type: textarea + id: can-help + attributes: + label: Can you help? + description: Can you help developing this feature? diff --git a/.github/ISSUE_TEMPLATE/30-usage.yml b/.github/ISSUE_TEMPLATE/30-usage.yml new file mode 100644 index 00000000..8afbd951 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/30-usage.yml @@ -0,0 +1,23 @@ +name: "Usage question" +description: Questions related to the usage +labels: ["documentation"] +body: + - type: markdown + attributes: + value: | + Thanks for taking the time to fill out this question! + + Please, before submitting, make sure that: + + - You have checked the [documentation](https://JuliaSmoothOptimizers.github.io/RegularizedOptimization.jl) and haven't found enough information + - There is not an [existing issue](https://github.com/JuliaSmoothOptimizers/RegularizedOptimization.jl/issues) with the same question + - You have read the [contributing guide](https://JuliaSmoothOptimizers.github.io/RegularizedOptimization.jl/dev/90-contributing/) + - You are following the [code of conduct](https://github.com/JuliaSmoothOptimizers/RegularizedOptimization.jl/blob/main/CODE_OF_CONDUCT.md) + The form below should help you in filling out this issue. + - type: textarea + id: description + attributes: + label: Description + description: Write your question + validations: + required: true diff --git a/.github/ISSUE_TEMPLATE/99-general.yml b/.github/ISSUE_TEMPLATE/99-general.yml new file mode 100644 index 00000000..797096f8 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/99-general.yml @@ -0,0 +1,21 @@ +name: "General issue" +description: In case none of the others templates apply +body: + - type: markdown + attributes: + value: | + Thanks for taking the time to fill out this issue! + + Please, before submitting, make sure that: + + - There is not an [existing issue](https://github.com/JuliaSmoothOptimizers/RegularizedOptimization.jl/issues) with the same question + - You have read the [contributing guide](https://JuliaSmoothOptimizers.github.io/RegularizedOptimization.jl/dev/90-contributing/) + - You are following the [code of conduct](https://github.com/JuliaSmoothOptimizers/RegularizedOptimization.jl/blob/main/CODE_OF_CONDUCT.md) + The form below should help you in filling out this issue. + - type: textarea + id: description + attributes: + label: Description + description: Describe the issue + validations: + required: true diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 00000000..e3b24acb --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,5 @@ +blank_issues_enabled: false +contact_links: + - name: Discussions + url: https://github.com/JuliaSmoothOptimizers/RegularizedOptimization.jl/discussions + about: Create and follow discussions here diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 00000000..9df1d376 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,27 @@ + + +## Related issues + + + + +Closes # + + + + +## Checklist + + + +- [ ] I am following the [contributing guidelines](https://github.com/JuliaSmoothOptimizers/RegularizedOptimization.jl/blob/main/docs/src/90-contributing.md) +- [ ] Tests are passing +- [ ] Lint workflow is passing +- [ ] Docs were updated and workflow is passing diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..700707ce --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,7 @@ +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" # Location of package manifests + schedule: + interval: "weekly" diff --git a/.github/workflows/CompatHelper.yml b/.github/workflows/CompatHelper.yml new file mode 100644 index 00000000..210e56f0 --- /dev/null +++ b/.github/workflows/CompatHelper.yml @@ -0,0 +1,51 @@ +# CompatHelper v3.5.0 +name: CompatHelper + +on: + schedule: + - cron: 0 0 * * * # Every day at 00:00 UTC + workflow_dispatch: + +permissions: + contents: write + pull-requests: write + +jobs: + CompatHelper: + runs-on: ubuntu-latest + steps: + - name: Check if Julia is already available in the PATH + id: julia_in_path + run: which julia + continue-on-error: true + - name: Install Julia, but only if it is not already available in the PATH + uses: julia-actions/setup-julia@v2 + with: + version: "1" + arch: ${{ runner.arch }} + if: steps.julia_in_path.outcome != 'success' + - name: Use Julia cache + uses: julia-actions/cache@v2 + - name: "Add the General registry via Git" + run: | + import Pkg + ENV["JULIA_PKG_SERVER"] = "" + Pkg.Registry.add("General") + shell: julia --color=yes {0} + - name: "Install CompatHelper" + run: | + import Pkg + name = "CompatHelper" + uuid = "aa819f21-2bde-4658-8897-bab36330d9b7" + version = "3" + Pkg.add(; name, uuid, version) + shell: julia --color=yes {0} + - name: "Run CompatHelper" + run: | + import CompatHelper + CompatHelper.main() + shell: julia --color=yes {0} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + COMPATHELPER_PRIV: ${{ secrets.DOCUMENTER_KEY }} + # COMPATHELPER_PRIV: ${{ secrets.COMPATHELPER_PRIV }} diff --git a/.github/workflows/Docs.yml b/.github/workflows/Docs.yml new file mode 100644 index 00000000..8b41f7fa --- /dev/null +++ b/.github/workflows/Docs.yml @@ -0,0 +1,57 @@ +name: Docs + +on: + push: + branches: + - main + paths: + - "docs/**" + - "src/**" + - "*.toml" + tags: ["*"] + pull_request: + branches: + - main + paths: + - "docs/**" + - "src/**" + - "*.toml" + types: [opened, synchronize, reopened] + +concurrency: + # Skip intermediate builds: always. + # Cancel intermediate builds: only if it is a pull request build. + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }} + +jobs: + docs: + name: Documentation + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: julia-actions/setup-julia@v2 + with: + version: "1" + - name: Use Julia cache + uses: julia-actions/cache@v2 + - name: Instantiate environment with development version of the package + run: | + julia --project=docs -e ' + using Pkg + Pkg.develop(PackageSpec(path=pwd())) + Pkg.instantiate()' + - name: Run doctest + run: | + julia --project=docs -e ' + using Documenter: DocMeta, doctest + using RegularizedOptimization + DocMeta.setdocmeta!(RegularizedOptimization, :DocTestSetup, :(using RegularizedOptimization); recursive=true) + doctest(RegularizedOptimization)' + - name: Generate and deploy documentation + run: julia --project=docs docs/make.jl + env: + JULIA_PKG_SERVER: "" + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} + GKSwstype: "100" # https://discourse.julialang.org/t/generation-of-documentation-fails-qt-qpa-xcb-could-not-connect-to-display/60988 diff --git a/.github/workflows/Lint.yml b/.github/workflows/Lint.yml new file mode 100644 index 00000000..dab91cf1 --- /dev/null +++ b/.github/workflows/Lint.yml @@ -0,0 +1,63 @@ +name: Lint + +on: + push: + branches: + - main + tags: ["*"] + pull_request: + +concurrency: + # Skip intermediate builds: always. + # Cancel intermediate builds: only if it is a pull request build. + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }} + +jobs: + + lint: + name: Linting + runs-on: ubuntu-latest + steps: + - name: Clone + uses: actions/checkout@v4 + - name: Setup Julia + uses: julia-actions/setup-julia@v2 + with: + version: "1" + - name: Use Julia cache + uses: julia-actions/cache@v2 + - name: Build package (required for ExplicitImports) + uses: julia-actions/julia-buildpkg@v1 + - name: Install Julia packages + run: julia -e 'using Pkg; pkg"add ExplicitImports, JuliaFormatter"' + - name: Hack for setup-python cache # https://github.com/actions/setup-python/issues/807 + run: touch requirements.txt + - name: Setup Python + uses: actions/setup-python@v5 + with: + cache: "pip" + python-version: "3.11" + - name: Hack for setup-python cache # https://github.com/actions/setup-python/issues/807 + run: rm requirements.txt + - name: Cache pre-commit + uses: actions/cache@v4 + with: + path: ~/.cache/pre-commit + key: ${{ runner.os }}-pre-commit-${{ hashFiles('**/.pre-commit-config.yaml') }} + - name: Install pre-commit + run: pip install pre-commit + - name: Run pre-commit + run: SKIP=no-commit-to-branch pre-commit run -a + link-checker: + name: Link checker + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Link Checker + id: lychee + uses: lycheeverse/lychee-action@v2 + with: + fail: true + args: --config '.lychee.toml' . diff --git a/.github/workflows/PreCommitUpdate.yml b/.github/workflows/PreCommitUpdate.yml new file mode 100644 index 00000000..e5318c55 --- /dev/null +++ b/.github/workflows/PreCommitUpdate.yml @@ -0,0 +1,40 @@ +name: pre-commit Update + +on: + schedule: + - cron: "0 7 1/7 * *" # At 7:00 every 7 days + workflow_dispatch: + +jobs: + pre-commit-update: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Hack for setup-python cache # https://github.com/actions/setup-python/issues/807 + run: touch requirements.txt + - name: Setup Python + uses: actions/setup-python@v5 + with: + cache: pip + python-version: "3.11" + - name: Hack for setup-python cache # https://github.com/actions/setup-python/issues/807 + run: rm requirements.txt + - name: Install pre-commit + run: pip install pre-commit + - name: Run pre-commit's autoupdate + run: | + # ignore exit code + pre-commit autoupdate || true + - name: Create Pull Request + id: cpr + uses: peter-evans/create-pull-request@v7 + with: + commit-message: "chore: :robot: pre-commit update" + title: "[AUTO] pre-commit update" + branch: auto-pre-commit-update + delete-branch: true + labels: chore + - name: Check outputs + run: | + echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}" + echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}" diff --git a/.github/workflows/ReusableTest.yml b/.github/workflows/ReusableTest.yml new file mode 100644 index 00000000..12431f28 --- /dev/null +++ b/.github/workflows/ReusableTest.yml @@ -0,0 +1,52 @@ +name: Reusable test + +on: + workflow_call: + inputs: + version: + required: false + type: string + default: "1" + os: + required: false + type: string + default: ubuntu-latest + arch: + required: false + type: string + default: x64 + allow_failure: + required: false + type: boolean + default: false + run_codecov: + required: false + type: boolean + default: false + secrets: + codecov_token: + required: true + +jobs: + test: + name: Julia ${{ inputs.version }} - ${{ inputs.os }} - ${{ inputs.arch }} - ${{ github.event_name }} + runs-on: ${{ inputs.os }} + continue-on-error: ${{ inputs.allow_failure }} + + steps: + - uses: actions/checkout@v4 + - uses: julia-actions/setup-julia@v2 + with: + version: ${{ inputs.version }} + arch: ${{ inputs.arch }} + - name: Use Julia cache + uses: julia-actions/cache@v2 + - uses: julia-actions/julia-buildpkg@v1 + - uses: julia-actions/julia-runtest@v1 + - uses: julia-actions/julia-processcoverage@v1 + if: ${{ inputs.run_codecov }} + - uses: codecov/codecov-action@v4 + if: ${{ inputs.run_codecov }} + with: + file: lcov.info + token: ${{ secrets.codecov_token }} diff --git a/.github/workflows/TagBot.yml b/.github/workflows/TagBot.yml index 778c06fe..dab9b0b6 100644 --- a/.github/workflows/TagBot.yml +++ b/.github/workflows/TagBot.yml @@ -1,9 +1,29 @@ name: TagBot + on: issue_comment: types: - created workflow_dispatch: + inputs: + lookback: + type: number + default: 3 + +permissions: + actions: read + checks: read + contents: write + deployments: read + issues: read + discussions: read + packages: read + pages: read + pull-requests: read + repository-projects: read + security-events: read + statuses: read + jobs: TagBot: if: github.event_name == 'workflow_dispatch' || github.actor == 'JuliaTagBot' @@ -12,3 +32,6 @@ jobs: - uses: JuliaRegistries/TagBot@v1 with: token: ${{ secrets.GITHUB_TOKEN }} + # Edit the following line to reflect the actual name of the GitHub Secret containing your private key + ssh: ${{ secrets.DOCUMENTER_KEY }} + # ssh: ${{ secrets.NAME_OF_MY_SSH_PRIVATE_KEY_SECRET }} diff --git a/.github/workflows/Test.yml b/.github/workflows/Test.yml new file mode 100644 index 00000000..02496687 --- /dev/null +++ b/.github/workflows/Test.yml @@ -0,0 +1,48 @@ +name: Test + +on: + push: + branches: + - main + tags: ["*"] + workflow_dispatch: + +jobs: + test: + uses: ./.github/workflows/ReusableTest.yml + with: + os: ${{ matrix.os }} + version: ${{ matrix.version }} + arch: ${{ matrix.arch }} + allow_failure: ${{ matrix.allow_failure }} + run_codecov: ${{ matrix.version == '1' && matrix.os == 'ubuntu-latest' }} + secrets: + codecov_token: ${{ secrets.CODECOV_TOKEN }} + strategy: + fail-fast: false + matrix: + version: + - "lts" + - "1" + os: + - ubuntu-latest + - macOS-latest + + - windows-latest + + arch: + - x64 + allow_failure: [false] + include: + - version: "nightly" + os: ubuntu-latest + arch: x64 + allow_failure: true + - version: "nightly" + os: macOS-latest + arch: x64 + allow_failure: true + - version: "nightly" + os: windows-latest + arch: x64 + allow_failure: true diff --git a/.github/workflows/TestOnPRs.yml b/.github/workflows/TestOnPRs.yml new file mode 100644 index 00000000..19a1f5a8 --- /dev/null +++ b/.github/workflows/TestOnPRs.yml @@ -0,0 +1,29 @@ +name: Test on PRs + +on: + pull_request: + branches: + - main + paths: + - "src/**" + - "test/**" + - "*.toml" + types: [opened, synchronize, reopened] + +concurrency: + # Skip intermediate builds: always. + # Cancel intermediate builds: only if it is a pull request build. + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }} + +jobs: + test: + uses: ./.github/workflows/ReusableTest.yml + with: + os: ubuntu-latest + version: "1" + arch: x64 + allow_failure: false + run_codecov: true + secrets: + codecov_token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.github/workflows/demos.yml b/.github/workflows/demos.yml index 194323e5..9c505719 100644 --- a/.github/workflows/demos.yml +++ b/.github/workflows/demos.yml @@ -38,16 +38,7 @@ jobs: uses: teatimeguest/setup-texlive-action@v3 with: packages: >- - scheme-minimal - latex-bin - pgf - pgfplots - standalone - xkeyval - luatex85 - infwarerr - ltxcmds - epstopdf-pkg + scheme-minimal latex-bin pgf pgfplots standalone xkeyval luatex85 infwarerr ltxcmds epstopdf-pkg # - name: Setup tmate session # uses: mxschmitt/action-tmate@v3 - name: Develop package diff --git a/.github/workflows/format_pr.yml b/.github/workflows/format_pr.yml index 60382f15..b85ac7d3 100644 --- a/.github/workflows/format_pr.yml +++ b/.github/workflows/format_pr.yml @@ -29,4 +29,4 @@ jobs: - name: Check outputs run: | echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}" - echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}" \ No newline at end of file + echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}" diff --git a/.github/workflows/pr-comment.yml b/.github/workflows/pr-comment.yml index e0d72cb9..46a3869c 100644 --- a/.github/workflows/pr-comment.yml +++ b/.github/workflows/pr-comment.yml @@ -12,8 +12,8 @@ jobs: - name: add artifact links to pull request and related issues step uses: veitbjarsch/artifacts-url-comments@v1.1.0 env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - prefix: "Here are the" - format: "name" - addTo: "pull" + prefix: "Here are the" + format: "name" + addTo: "pull" diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..a7643b74 --- /dev/null +++ b/.gitignore @@ -0,0 +1,14 @@ +*.jl.*.cov +*.jl.cov +*.jl.mem +*.rej +.DS_Store +.benchmarkci +Manifest.toml +benchmark/*.json +coverage +docs/build/ +env +node_modules +test_script* +benchmark_JOSS diff --git a/.lychee.toml b/.lychee.toml new file mode 100644 index 00000000..117864f6 --- /dev/null +++ b/.lychee.toml @@ -0,0 +1,12 @@ +exclude = [ + "@ref", + "@cite", + "^https://github.com/.*/releases/tag/v.*$", + "^https://doi.org/FIXME$", + "^https://JuliaSmoothOptimizers.github.io/RegularizedOptimization.jl/stable$", + "zenodo.org/badge/DOI/FIXME$" +] + +exclude_path = [ + "docs/build" +] diff --git a/.markdownlint.json b/.markdownlint.json new file mode 100644 index 00000000..8bf958ad --- /dev/null +++ b/.markdownlint.json @@ -0,0 +1,13 @@ +{ + "MD007": { + "indent": 2, + "start_indented": false + }, + "MD013": { + "line_length": 1000, + "tables": false + }, + "MD033": false, + "MD041": false, + "default": true +} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..efdf8ebc --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,53 @@ +repos: + - repo: local + hooks: + # Prevent committing .rej files + - id: forbidden-files + name: forbidden files + entry: found Copier update rejection files; review them and remove them + language: fail + files: "\\.rej$" + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v5.0.0 + hooks: + - id: check-json + - id: check-toml + - id: check-yaml + - id: file-contents-sorter + files: .JuliaFormatter.toml + args: [--unique] + - id: mixed-line-ending + args: [--fix=lf] + - id: no-commit-to-branch + - id: pretty-format-json + args: [--autofix, --indent=2] + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-merge-conflict + args: [--assume-in-merge] + - repo: https://github.com/igorshubovych/markdownlint-cli + rev: v0.43.0 + hooks: + - id: markdownlint-fix + - repo: https://github.com/citation-file-format/cffconvert + rev: 054bda51dbe278b3e86f27c890e3f3ac877d616c + hooks: + - id: validate-cff + - repo: https://github.com/google/yamlfmt + rev: v0.16.0 + hooks: + - id: yamlfmt + - repo: https://github.com/adrienverge/yamllint + rev: v1.35.1 + hooks: + - id: yamllint + - repo: https://github.com/ericphanson/ExplicitImports.jl + rev: v1.10.1 + hooks: + - id: explicit-imports + name: ExplicitImports checks + args: [--print, --checklist, exclude_all_qualified_accesses_are_public] + - repo: https://github.com/domluna/JuliaFormatter.jl + rev: v2.0.0 + hooks: + - id: julia-formatter diff --git a/.yamlfmt.yml b/.yamlfmt.yml new file mode 100644 index 00000000..6f5fab32 --- /dev/null +++ b/.yamlfmt.yml @@ -0,0 +1,7 @@ +# https://github.com/google/yamlfmt/blob/main/docs/config-file.md +formatter: + type: basic + retain_line_breaks_single: true + indent: 2 +line_ending: lf # matching other hooks settings +exclude: ['.copier-answers.yml'] diff --git a/.yamllint.yml b/.yamllint.yml new file mode 100644 index 00000000..31bcb021 --- /dev/null +++ b/.yamllint.yml @@ -0,0 +1,2 @@ +rules: + indentation: {spaces: 2} diff --git a/CITATION.cff b/CITATION.cff new file mode 100644 index 00000000..5d298407 --- /dev/null +++ b/CITATION.cff @@ -0,0 +1,17 @@ +cff-version: 1.2.0 +title: RegularizedOptimization.jl +message: >- + If you use this software, please cite it using the + metadata from this file. +type: software +authors: + - given-names: Dominique + email: dominique.orban@gmail.com + family-names: Orban + - given-names: Robert + family-names: Baraldi + email: rbaraldi@uw.edu +identifiers: + - type: doi + value: 10.5281/zenodo.6940313 +license: MPL-2.0 diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 00000000..bcf8f1d7 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,133 @@ + +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, caste, color, religion, or sexual +identity and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our +community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the overall + community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or advances of + any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email address, + without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official email address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement: +`dominique.orban@gmail.com`. +All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series of +actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or permanent +ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within the +community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.1, available at +[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1]. + +Community Impact Guidelines were inspired by +[Mozilla's code of conduct enforcement ladder][Mozilla CoC]. + +For answers to common questions about this code of conduct, see the FAQ at +[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at +[https://www.contributor-covenant.org/translations][translations]. + +[homepage]: https://www.contributor-covenant.org +[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html +[Mozilla CoC]: https://github.com/mozilla/diversity +[FAQ]: https://www.contributor-covenant.org/faq +[translations]: https://www.contributor-covenant.org/translations diff --git a/CondaPkg.toml b/CondaPkg.toml new file mode 100644 index 00000000..432fb20b --- /dev/null +++ b/CondaPkg.toml @@ -0,0 +1,2 @@ +[deps] +copier = "" diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..a612ad98 --- /dev/null +++ b/LICENSE @@ -0,0 +1,373 @@ +Mozilla Public License Version 2.0 +================================== + +1. Definitions +-------------- + +1.1. "Contributor" + means each individual or legal entity that creates, contributes to + the creation of, or owns Covered Software. + +1.2. "Contributor Version" + means the combination of the Contributions of others (if any) used + by a Contributor and that particular Contributor's Contribution. + +1.3. "Contribution" + means Covered Software of a particular Contributor. + +1.4. "Covered Software" + means Source Code Form to which the initial Contributor has attached + the notice in Exhibit A, the Executable Form of such Source Code + Form, and Modifications of such Source Code Form, in each case + including portions thereof. + +1.5. "Incompatible With Secondary Licenses" + means + + (a) that the initial Contributor has attached the notice described + in Exhibit B to the Covered Software; or + + (b) that the Covered Software was made available under the terms of + version 1.1 or earlier of the License, but not also under the + terms of a Secondary License. + +1.6. "Executable Form" + means any form of the work other than Source Code Form. + +1.7. "Larger Work" + means a work that combines Covered Software with other material, in + a separate file or files, that is not Covered Software. + +1.8. "License" + means this document. + +1.9. "Licensable" + means having the right to grant, to the maximum extent possible, + whether at the time of the initial grant or subsequently, any and + all of the rights conveyed by this License. + +1.10. "Modifications" + means any of the following: + + (a) any file in Source Code Form that results from an addition to, + deletion from, or modification of the contents of Covered + Software; or + + (b) any new file in Source Code Form that contains any Covered + Software. + +1.11. "Patent Claims" of a Contributor + means any patent claim(s), including without limitation, method, + process, and apparatus claims, in any patent Licensable by such + Contributor that would be infringed, but for the grant of the + License, by the making, using, selling, offering for sale, having + made, import, or transfer of either its Contributions or its + Contributor Version. + +1.12. "Secondary License" + means either the GNU General Public License, Version 2.0, the GNU + Lesser General Public License, Version 2.1, the GNU Affero General + Public License, Version 3.0, or any later versions of those + licenses. + +1.13. "Source Code Form" + means the form of the work preferred for making modifications. + +1.14. "You" (or "Your") + means an individual or a legal entity exercising rights under this + License. For legal entities, "You" includes any entity that + controls, is controlled by, or is under common control with You. For + purposes of this definition, "control" means (a) the power, direct + or indirect, to cause the direction or management of such entity, + whether by contract or otherwise, or (b) ownership of more than + fifty percent (50%) of the outstanding shares or beneficial + ownership of such entity. + +2. License Grants and Conditions +-------------------------------- + +2.1. Grants + +Each Contributor hereby grants You a world-wide, royalty-free, +non-exclusive license: + +(a) under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or + as part of a Larger Work; and + +(b) under Patent Claims of such Contributor to make, use, sell, offer + for sale, have made, import, and otherwise transfer either its + Contributions or its Contributor Version. + +2.2. Effective Date + +The licenses granted in Section 2.1 with respect to any Contribution +become effective for each Contribution on the date the Contributor first +distributes such Contribution. + +2.3. Limitations on Grant Scope + +The licenses granted in this Section 2 are the only rights granted under +this License. No additional rights or licenses will be implied from the +distribution or licensing of Covered Software under this License. +Notwithstanding Section 2.1(b) above, no patent license is granted by a +Contributor: + +(a) for any code that a Contributor has removed from Covered Software; + or + +(b) for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + +(c) under Patent Claims infringed by Covered Software in the absence of + its Contributions. + +This License does not grant any rights in the trademarks, service marks, +or logos of any Contributor (except as may be necessary to comply with +the notice requirements in Section 3.4). + +2.4. Subsequent Licenses + +No Contributor makes additional grants as a result of Your choice to +distribute the Covered Software under a subsequent version of this +License (see Section 10.2) or under the terms of a Secondary License (if +permitted under the terms of Section 3.3). + +2.5. Representation + +Each Contributor represents that the Contributor believes its +Contributions are its original creation(s) or it has sufficient rights +to grant the rights to its Contributions conveyed by this License. + +2.6. Fair Use + +This License is not intended to limit any rights You have under +applicable copyright doctrines of fair use, fair dealing, or other +equivalents. + +2.7. Conditions + +Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted +in Section 2.1. + +3. Responsibilities +------------------- + +3.1. Distribution of Source Form + +All distribution of Covered Software in Source Code Form, including any +Modifications that You create or to which You contribute, must be under +the terms of this License. You must inform recipients that the Source +Code Form of the Covered Software is governed by the terms of this +License, and how they can obtain a copy of this License. You may not +attempt to alter or restrict the recipients' rights in the Source Code +Form. + +3.2. Distribution of Executable Form + +If You distribute Covered Software in Executable Form then: + +(a) such Covered Software must also be made available in Source Code + Form, as described in Section 3.1, and You must inform recipients of + the Executable Form how they can obtain a copy of such Source Code + Form by reasonable means in a timely manner, at a charge no more + than the cost of distribution to the recipient; and + +(b) You may distribute such Executable Form under the terms of this + License, or sublicense it under different terms, provided that the + license for the Executable Form does not attempt to limit or alter + the recipients' rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + +You may create and distribute a Larger Work under terms of Your choice, +provided that You also comply with the requirements of this License for +the Covered Software. If the Larger Work is a combination of Covered +Software with a work governed by one or more Secondary Licenses, and the +Covered Software is not Incompatible With Secondary Licenses, this +License permits You to additionally distribute such Covered Software +under the terms of such Secondary License(s), so that the recipient of +the Larger Work may, at their option, further distribute the Covered +Software under the terms of either this License or such Secondary +License(s). + +3.4. Notices + +You may not remove or alter the substance of any license notices +(including copyright notices, patent notices, disclaimers of warranty, +or limitations of liability) contained within the Source Code Form of +the Covered Software, except that You may alter any license notices to +the extent required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + +You may choose to offer, and to charge a fee for, warranty, support, +indemnity or liability obligations to one or more recipients of Covered +Software. However, You may do so only on Your own behalf, and not on +behalf of any Contributor. You must make it absolutely clear that any +such warranty, support, indemnity, or liability obligation is offered by +You alone, and You hereby agree to indemnify every Contributor for any +liability incurred by such Contributor as a result of warranty, support, +indemnity or liability terms You offer. You may include additional +disclaimers of warranty and limitations of liability specific to any +jurisdiction. + +4. Inability to Comply Due to Statute or Regulation +--------------------------------------------------- + +If it is impossible for You to comply with any of the terms of this +License with respect to some or all of the Covered Software due to +statute, judicial order, or regulation then You must: (a) comply with +the terms of this License to the maximum extent possible; and (b) +describe the limitations and the code they affect. Such description must +be placed in a text file included with all distributions of the Covered +Software under this License. Except to the extent prohibited by statute +or regulation, such description must be sufficiently detailed for a +recipient of ordinary skill to be able to understand it. + +5. Termination +-------------- + +5.1. The rights granted under this License will terminate automatically +if You fail to comply with any of its terms. However, if You become +compliant, then the rights granted under this License from a particular +Contributor are reinstated (a) provisionally, unless and until such +Contributor explicitly and finally terminates Your grants, and (b) on an +ongoing basis, if such Contributor fails to notify You of the +non-compliance by some reasonable means prior to 60 days after You have +come back into compliance. Moreover, Your grants from a particular +Contributor are reinstated on an ongoing basis if such Contributor +notifies You of the non-compliance by some reasonable means, this is the +first time You have received notice of non-compliance with this License +from such Contributor, and You become compliant prior to 30 days after +Your receipt of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent +infringement claim (excluding declaratory judgment actions, +counter-claims, and cross-claims) alleging that a Contributor Version +directly or indirectly infringes any patent, then the rights granted to +You by any and all Contributors for the Covered Software under Section +2.1 of this License shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all +end user license agreements (excluding distributors and resellers) which +have been validly granted by You or Your distributors under this License +prior to termination shall survive termination. + +************************************************************************ +* * +* 6. Disclaimer of Warranty * +* ------------------------- * +* * +* Covered Software is provided under this License on an "as is" * +* basis, without warranty of any kind, either expressed, implied, or * +* statutory, including, without limitation, warranties that the * +* Covered Software is free of defects, merchantable, fit for a * +* particular purpose or non-infringing. The entire risk as to the * +* quality and performance of the Covered Software is with You. * +* Should any Covered Software prove defective in any respect, You * +* (not any Contributor) assume the cost of any necessary servicing, * +* repair, or correction. This disclaimer of warranty constitutes an * +* essential part of this License. No use of any Covered Software is * +* authorized under this License except under this disclaimer. * +* * +************************************************************************ + +************************************************************************ +* * +* 7. Limitation of Liability * +* -------------------------- * +* * +* Under no circumstances and under no legal theory, whether tort * +* (including negligence), contract, or otherwise, shall any * +* Contributor, or anyone who distributes Covered Software as * +* permitted above, be liable to You for any direct, indirect, * +* special, incidental, or consequential damages of any character * +* including, without limitation, damages for lost profits, loss of * +* goodwill, work stoppage, computer failure or malfunction, or any * +* and all other commercial damages or losses, even if such party * +* shall have been informed of the possibility of such damages. This * +* limitation of liability shall not apply to liability for death or * +* personal injury resulting from such party's negligence to the * +* extent applicable law prohibits such limitation. Some * +* jurisdictions do not allow the exclusion or limitation of * +* incidental or consequential damages, so this exclusion and * +* limitation may not apply to You. * +* * +************************************************************************ + +8. Litigation +------------- + +Any litigation relating to this License may be brought only in the +courts of a jurisdiction where the defendant maintains its principal +place of business and such litigation shall be governed by laws of that +jurisdiction, without reference to its conflict-of-law provisions. +Nothing in this Section shall prevent a party's ability to bring +cross-claims or counter-claims. + +9. Miscellaneous +---------------- + +This License represents the complete agreement concerning the subject +matter hereof. If any provision of this License is held to be +unenforceable, such provision shall be reformed only to the extent +necessary to make it enforceable. Any law or regulation which provides +that the language of a contract shall be construed against the drafter +shall not be used to construe this License against a Contributor. + +10. Versions of the License +--------------------------- + +10.1. New Versions + +Mozilla Foundation is the license steward. Except as provided in Section +10.3, no one other than the license steward has the right to modify or +publish new versions of this License. Each version will be given a +distinguishing version number. + +10.2. Effect of New Versions + +You may distribute the Covered Software under the terms of the version +of the License under which You originally received the Covered Software, +or under the terms of any subsequent version published by the license +steward. + +10.3. Modified Versions + +If you create software not governed by this License, and you want to +create a new license for such software, you may create and use a +modified version of this License if you rename the license and remove +any references to the name of the license steward (except to note that +such modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary +Licenses + +If You choose to distribute Source Code Form that is Incompatible With +Secondary Licenses under the terms of this version of the License, the +notice described in Exhibit B of this License must be attached. + +Exhibit A - Source Code Form License Notice +------------------------------------------- + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular +file, then You may include the notice in a location (such as a LICENSE +file in a relevant directory) where a recipient would be likely to look +for such a notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - "Incompatible With Secondary Licenses" Notice +--------------------------------------------------------- + + This Source Code Form is "Incompatible With Secondary Licenses", as + defined by the Mozilla Public License, v. 2.0. diff --git a/LICENSE.md b/LICENSE.md deleted file mode 100644 index dd4ac468..00000000 --- a/LICENSE.md +++ /dev/null @@ -1,379 +0,0 @@ -Copyright (c) 2021: Robert Baraldi and Dominique Orban - -RegularizedProblems.jl is licensed under the [MPL version 2.0](https://www.mozilla.org/MPL/2.0/). - -## License - - Mozilla Public License Version 2.0 - ================================== - - 1. Definitions - -------------- - - 1.1. "Contributor" - means each individual or legal entity that creates, contributes to - the creation of, or owns Covered Software. - - 1.2. "Contributor Version" - means the combination of the Contributions of others (if any) used - by a Contributor and that particular Contributor's Contribution. - - 1.3. "Contribution" - means Covered Software of a particular Contributor. - - 1.4. "Covered Software" - means Source Code Form to which the initial Contributor has attached - the notice in Exhibit A, the Executable Form of such Source Code - Form, and Modifications of such Source Code Form, in each case - including portions thereof. - - 1.5. "Incompatible With Secondary Licenses" - means - - (a) that the initial Contributor has attached the notice described - in Exhibit B to the Covered Software; or - - (b) that the Covered Software was made available under the terms of - version 1.1 or earlier of the License, but not also under the - terms of a Secondary License. - - 1.6. "Executable Form" - means any form of the work other than Source Code Form. - - 1.7. "Larger Work" - means a work that combines Covered Software with other material, in - a separate file or files, that is not Covered Software. - - 1.8. "License" - means this document. - - 1.9. "Licensable" - means having the right to grant, to the maximum extent possible, - whether at the time of the initial grant or subsequently, any and - all of the rights conveyed by this License. - - 1.10. "Modifications" - means any of the following: - - (a) any file in Source Code Form that results from an addition to, - deletion from, or modification of the contents of Covered - Software; or - - (b) any new file in Source Code Form that contains any Covered - Software. - - 1.11. "Patent Claims" of a Contributor - means any patent claim(s), including without limitation, method, - process, and apparatus claims, in any patent Licensable by such - Contributor that would be infringed, but for the grant of the - License, by the making, using, selling, offering for sale, having - made, import, or transfer of either its Contributions or its - Contributor Version. - - 1.12. "Secondary License" - means either the GNU General Public License, Version 2.0, the GNU - Lesser General Public License, Version 2.1, the GNU Affero General - Public License, Version 3.0, or any later versions of those - licenses. - - 1.13. "Source Code Form" - means the form of the work preferred for making modifications. - - 1.14. "You" (or "Your") - means an individual or a legal entity exercising rights under this - License. For legal entities, "You" includes any entity that - controls, is controlled by, or is under common control with You. For - purposes of this definition, "control" means (a) the power, direct - or indirect, to cause the direction or management of such entity, - whether by contract or otherwise, or (b) ownership of more than - fifty percent (50%) of the outstanding shares or beneficial - ownership of such entity. - - 2. License Grants and Conditions - -------------------------------- - - 2.1. Grants - - Each Contributor hereby grants You a world-wide, royalty-free, - non-exclusive license: - - (a) under intellectual property rights (other than patent or trademark) - Licensable by such Contributor to use, reproduce, make available, - modify, display, perform, distribute, and otherwise exploit its - Contributions, either on an unmodified basis, with Modifications, or - as part of a Larger Work; and - - (b) under Patent Claims of such Contributor to make, use, sell, offer - for sale, have made, import, and otherwise transfer either its - Contributions or its Contributor Version. - - 2.2. Effective Date - - The licenses granted in Section 2.1 with respect to any Contribution - become effective for each Contribution on the date the Contributor first - distributes such Contribution. - - 2.3. Limitations on Grant Scope - - The licenses granted in this Section 2 are the only rights granted under - this License. No additional rights or licenses will be implied from the - distribution or licensing of Covered Software under this License. - Notwithstanding Section 2.1(b) above, no patent license is granted by a - Contributor: - - (a) for any code that a Contributor has removed from Covered Software; - or - - (b) for infringements caused by: (i) Your and any other third party's - modifications of Covered Software, or (ii) the combination of its - Contributions with other software (except as part of its Contributor - Version); or - - (c) under Patent Claims infringed by Covered Software in the absence of - its Contributions. - - This License does not grant any rights in the trademarks, service marks, - or logos of any Contributor (except as may be necessary to comply with - the notice requirements in Section 3.4). - - 2.4. Subsequent Licenses - - No Contributor makes additional grants as a result of Your choice to - distribute the Covered Software under a subsequent version of this - License (see Section 10.2) or under the terms of a Secondary License (if - permitted under the terms of Section 3.3). - - 2.5. Representation - - Each Contributor represents that the Contributor believes its - Contributions are its original creation(s) or it has sufficient rights - to grant the rights to its Contributions conveyed by this License. - - 2.6. Fair Use - - This License is not intended to limit any rights You have under - applicable copyright doctrines of fair use, fair dealing, or other - equivalents. - - 2.7. Conditions - - Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted - in Section 2.1. - - 3. Responsibilities - ------------------- - - 3.1. Distribution of Source Form - - All distribution of Covered Software in Source Code Form, including any - Modifications that You create or to which You contribute, must be under - the terms of this License. You must inform recipients that the Source - Code Form of the Covered Software is governed by the terms of this - License, and how they can obtain a copy of this License. You may not - attempt to alter or restrict the recipients' rights in the Source Code - Form. - - 3.2. Distribution of Executable Form - - If You distribute Covered Software in Executable Form then: - - (a) such Covered Software must also be made available in Source Code - Form, as described in Section 3.1, and You must inform recipients of - the Executable Form how they can obtain a copy of such Source Code - Form by reasonable means in a timely manner, at a charge no more - than the cost of distribution to the recipient; and - - (b) You may distribute such Executable Form under the terms of this - License, or sublicense it under different terms, provided that the - license for the Executable Form does not attempt to limit or alter - the recipients' rights in the Source Code Form under this License. - - 3.3. Distribution of a Larger Work - - You may create and distribute a Larger Work under terms of Your choice, - provided that You also comply with the requirements of this License for - the Covered Software. If the Larger Work is a combination of Covered - Software with a work governed by one or more Secondary Licenses, and the - Covered Software is not Incompatible With Secondary Licenses, this - License permits You to additionally distribute such Covered Software - under the terms of such Secondary License(s), so that the recipient of - the Larger Work may, at their option, further distribute the Covered - Software under the terms of either this License or such Secondary - License(s). - - 3.4. Notices - - You may not remove or alter the substance of any license notices - (including copyright notices, patent notices, disclaimers of warranty, - or limitations of liability) contained within the Source Code Form of - the Covered Software, except that You may alter any license notices to - the extent required to remedy known factual inaccuracies. - - 3.5. Application of Additional Terms - - You may choose to offer, and to charge a fee for, warranty, support, - indemnity or liability obligations to one or more recipients of Covered - Software. However, You may do so only on Your own behalf, and not on - behalf of any Contributor. You must make it absolutely clear that any - such warranty, support, indemnity, or liability obligation is offered by - You alone, and You hereby agree to indemnify every Contributor for any - liability incurred by such Contributor as a result of warranty, support, - indemnity or liability terms You offer. You may include additional - disclaimers of warranty and limitations of liability specific to any - jurisdiction. - - 4. Inability to Comply Due to Statute or Regulation - --------------------------------------------------- - - If it is impossible for You to comply with any of the terms of this - License with respect to some or all of the Covered Software due to - statute, judicial order, or regulation then You must: (a) comply with - the terms of this License to the maximum extent possible; and (b) - describe the limitations and the code they affect. Such description must - be placed in a text file included with all distributions of the Covered - Software under this License. Except to the extent prohibited by statute - or regulation, such description must be sufficiently detailed for a - recipient of ordinary skill to be able to understand it. - - 5. Termination - -------------- - - 5.1. The rights granted under this License will terminate automatically - if You fail to comply with any of its terms. However, if You become - compliant, then the rights granted under this License from a particular - Contributor are reinstated (a) provisionally, unless and until such - Contributor explicitly and finally terminates Your grants, and (b) on an - ongoing basis, if such Contributor fails to notify You of the - non-compliance by some reasonable means prior to 60 days after You have - come back into compliance. Moreover, Your grants from a particular - Contributor are reinstated on an ongoing basis if such Contributor - notifies You of the non-compliance by some reasonable means, this is the - first time You have received notice of non-compliance with this License - from such Contributor, and You become compliant prior to 30 days after - Your receipt of the notice. - - 5.2. If You initiate litigation against any entity by asserting a patent - infringement claim (excluding declaratory judgment actions, - counter-claims, and cross-claims) alleging that a Contributor Version - directly or indirectly infringes any patent, then the rights granted to - You by any and all Contributors for the Covered Software under Section - 2.1 of this License shall terminate. - - 5.3. In the event of termination under Sections 5.1 or 5.2 above, all - end user license agreements (excluding distributors and resellers) which - have been validly granted by You or Your distributors under this License - prior to termination shall survive termination. - - ************************************************************************ - * * - * 6. Disclaimer of Warranty * - * ------------------------- * - * * - * Covered Software is provided under this License on an "as is" * - * basis, without warranty of any kind, either expressed, implied, or * - * statutory, including, without limitation, warranties that the * - * Covered Software is free of defects, merchantable, fit for a * - * particular purpose or non-infringing. The entire risk as to the * - * quality and performance of the Covered Software is with You. * - * Should any Covered Software prove defective in any respect, You * - * (not any Contributor) assume the cost of any necessary servicing, * - * repair, or correction. This disclaimer of warranty constitutes an * - * essential part of this License. No use of any Covered Software is * - * authorized under this License except under this disclaimer. * - * * - ************************************************************************ - - ************************************************************************ - * * - * 7. Limitation of Liability * - * -------------------------- * - * * - * Under no circumstances and under no legal theory, whether tort * - * (including negligence), contract, or otherwise, shall any * - * Contributor, or anyone who distributes Covered Software as * - * permitted above, be liable to You for any direct, indirect, * - * special, incidental, or consequential damages of any character * - * including, without limitation, damages for lost profits, loss of * - * goodwill, work stoppage, computer failure or malfunction, or any * - * and all other commercial damages or losses, even if such party * - * shall have been informed of the possibility of such damages. This * - * limitation of liability shall not apply to liability for death or * - * personal injury resulting from such party's negligence to the * - * extent applicable law prohibits such limitation. Some * - * jurisdictions do not allow the exclusion or limitation of * - * incidental or consequential damages, so this exclusion and * - * limitation may not apply to You. * - * * - ************************************************************************ - - 8. Litigation - ------------- - - Any litigation relating to this License may be brought only in the - courts of a jurisdiction where the defendant maintains its principal - place of business and such litigation shall be governed by laws of that - jurisdiction, without reference to its conflict-of-law provisions. - Nothing in this Section shall prevent a party's ability to bring - cross-claims or counter-claims. - - 9. Miscellaneous - ---------------- - - This License represents the complete agreement concerning the subject - matter hereof. If any provision of this License is held to be - unenforceable, such provision shall be reformed only to the extent - necessary to make it enforceable. Any law or regulation which provides - that the language of a contract shall be construed against the drafter - shall not be used to construe this License against a Contributor. - - 10. Versions of the License - --------------------------- - - 10.1. New Versions - - Mozilla Foundation is the license steward. Except as provided in Section - 10.3, no one other than the license steward has the right to modify or - publish new versions of this License. Each version will be given a - distinguishing version number. - - 10.2. Effect of New Versions - - You may distribute the Covered Software under the terms of the version - of the License under which You originally received the Covered Software, - or under the terms of any subsequent version published by the license - steward. - - 10.3. Modified Versions - - If you create software not governed by this License, and you want to - create a new license for such software, you may create and use a - modified version of this License if you rename the license and remove - any references to the name of the license steward (except to note that - such modified license differs from this License). - - 10.4. Distributing Source Code Form that is Incompatible With Secondary - Licenses - - If You choose to distribute Source Code Form that is Incompatible With - Secondary Licenses under the terms of this version of the License, the - notice described in Exhibit B of this License must be attached. - - Exhibit A - Source Code Form License Notice - ------------------------------------------- - - This Source Code Form is subject to the terms of the Mozilla Public - License, v. 2.0. If a copy of the MPL was not distributed with this - file, You can obtain one at http://mozilla.org/MPL/2.0/. - - If it is not possible or desirable to put the notice in a particular - file, then You may include the notice in a location (such as a LICENSE - file in a relevant directory) where a recipient would be likely to look - for such a notice. - - You may add additional accurate notices of copyright ownership. - - Exhibit B - "Incompatible With Secondary Licenses" Notice - --------------------------------------------------------- - - This Source Code Form is "Incompatible With Secondary Licenses", as - defined by the Mozilla Public License, v. 2.0. diff --git a/Project.toml b/Project.toml index e6e5aff0..27e98249 100644 --- a/Project.toml +++ b/Project.toml @@ -21,6 +21,7 @@ SolverCore = "ff4d7338-4cf1-434d-91df-b86cb86fb843" [compat] ADNLPModels = "0.8.13" Arpack = "0.5" +JET = "0.9.20" LinearOperators = "2.10.0" ManualNLPModels = "0.2.0" NLPModels = "0.19, 0.20, 0.21" @@ -35,6 +36,7 @@ julia = "^1.6.0" [extras] ADNLPModels = "54578032-b7ea-4c30-94aa-7cbd1cce6c9a" +JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b" OptimizationProblems = "5049e819-d29b-5fba-b941-0eee7e64c1c6" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" RegularizedProblems = "ea076b23-609f-44d2-bb12-a4ae45328278" @@ -42,4 +44,4 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" TestSetExtensions = "98d24dd4-01ad-11ea-1b02-c9a08f80db04" [targets] -test = ["ADNLPModels", "OptimizationProblems", "Random", "RegularizedProblems", "Test", "TestSetExtensions"] +test = ["ADNLPModels", "JET", "OptimizationProblems", "Random", "RegularizedProblems", "Test", "TestSetExtensions"] diff --git a/README.md b/README.md index 73e8cbc5..906ea539 100644 --- a/README.md +++ b/README.md @@ -1,58 +1,34 @@ # RegularizedOptimization -[![CI](https://github.com/JuliaSmoothOptimizers/RegularizedOptimization.jl/actions/workflows/ci.yml/badge.svg)](https://github.com/JuliaSmoothOptimizers/RegularizedOptimization.jl/actions/workflows/ci.yml) -[![](https://img.shields.io/badge/docs-latest-3f51b5.svg)](https://JuliaSmoothOptimizers.github.io/RegularizedOptimization.jl/dev) -[![codecov](https://codecov.io/gh/JuliaSmoothOptimizers/RegularizedOptimization.jl/branch/master/graph/badge.svg?token=lTbRmyBspS)](https://codecov.io/gh/JuliaSmoothOptimizers/RegularizedOptimization.jl) -[![DOI](https://zenodo.org/badge/160387219.svg)](https://zenodo.org/badge/latestdoi/160387219) +[![Stable Documentation](https://img.shields.io/badge/docs-stable-blue.svg)](https://JuliaSmoothOptimizers.github.io/RegularizedOptimization.jl/stable) +[![Development documentation](https://img.shields.io/badge/docs-dev-blue.svg)](https://JuliaSmoothOptimizers.github.io/RegularizedOptimization.jl/dev) +[![Test workflow status](https://github.com/JuliaSmoothOptimizers/RegularizedOptimization.jl/actions/workflows/Test.yml/badge.svg?branch=wip-bestie)](https://github.com/JuliaSmoothOptimizers/RegularizedOptimization.jl/actions/workflows/Test.yml?query=branch%3Awip-bestie) +[![Coverage](https://codecov.io/gh/JuliaSmoothOptimizers/RegularizedOptimization.jl/branch/wip-bestie/graph/badge.svg)](https://codecov.io/gh/JuliaSmoothOptimizers/RegularizedOptimization.jl) +[![Lint workflow Status](https://github.com/JuliaSmoothOptimizers/RegularizedOptimization.jl/actions/workflows/Lint.yml/badge.svg?branch=wip-bestie)](https://github.com/JuliaSmoothOptimizers/RegularizedOptimization.jl/actions/workflows/Lint.yml?query=branch%3Awip-bestie) +[![Docs workflow Status](https://github.com/JuliaSmoothOptimizers/RegularizedOptimization.jl/actions/workflows/Docs.yml/badge.svg?branch=wip-bestie)](https://github.com/JuliaSmoothOptimizers/RegularizedOptimization.jl/actions/workflows/Docs.yml?query=branch%3Awip-bestie) +[![Build Status](https://api.cirrus-ci.com/github/JuliaSmoothOptimizers/RegularizedOptimization.jl.svg)](https://cirrus-ci.com/github/JuliaSmoothOptimizers/RegularizedOptimization.jl) +[![DOI](https://zenodo.org/badge/DOI/FIXME)](https://doi.org/FIXME) +[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](CODE_OF_CONDUCT.md) +[![All Contributors](https://img.shields.io/github/all-contributors/JuliaSmoothOptimizers/RegularizedOptimization.jl?labelColor=5e1ec7&color=c0ffee&style=flat-square)](#contributors) +[![BestieTemplate](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/JuliaBesties/BestieTemplate.jl/wip-bestie/docs/src/assets/badge.json)](https://github.com/JuliaBesties/BestieTemplate.jl) -## How to cite +## How to Cite -If you use RegularizedOptimization.jl in your work, please cite using the format given in [CITATION.bib](CITATION.bib). +If you use RegularizedOptimization.jl in your work, please cite using the reference given in [CITATION.cff](https://github.com/JuliaSmoothOptimizers/RegularizedOptimization.jl/blob/wip-bestie/CITATION.cff). -## Synopsis +## Contributing -This package contains solvers to solve regularized optimization problems of the form +If you want to make contributions of any kind, please first that a look into our [contributing guide directly on GitHub](docs/src/90-contributing.md) or the [contributing page on the website](https://JuliaSmoothOptimizers.github.io/RegularizedOptimization.jl/dev/90-contributing/) -

-minₓ f(x) + h(x) -

+--- -where f: ℝⁿ → ℝ has Lipschitz-continuous gradient and h: ℝⁿ → ℝ is lower semi-continuous and proper. -The smooth term f describes the objective to minimize while the role of the regularizer h is to select -a solution with desirable properties: minimum norm, sparsity below a certain level, maximum sparsity, etc. -Both f and h can be nonconvex. +### Contributors -## Installation + + + -To install the package, hit `]` from the Julia command line to enter the package manager and type -```julia -pkg> add https://github.com/JuliaSmoothOptimizers/RegularizedOptimization.jl -``` + + -## What is Implemented? - -Please refer to the documentation. - -## Related Software - -* [RegularizedProblems.jl](https://github.com/JuliaSmoothOptimizers/RegularizedProblems.jl) -* [ShiftedProximalOperators.jl](https://github.com/JuliaSmoothOptimizers/ShiftedProximalOperators.jl) - -## References - -1. A. Y. Aravkin, R. Baraldi and D. Orban, *A Proximal Quasi-Newton Trust-Region Method for Nonsmooth Regularized Optimization*, SIAM Journal on Optimization, 32(2), pp.900–929, 2022. Technical report: https://arxiv.org/abs/2103.15993 -2. R. Baraldi, R. Kumar, and A. Aravkin (2019), [*Basis Pursuit De-noise with Non-smooth Constraints*](https://doi.org/10.1109/TSP.2019.2946029), IEEE Transactions on Signal Processing, vol. 67, no. 22, pp. 5811-5823. - -```bibtex -@article{aravkin-baraldi-orban-2022, - author = {Aravkin, Aleksandr Y. and Baraldi, Robert and Orban, Dominique}, - title = {A Proximal Quasi-{N}ewton Trust-Region Method for Nonsmooth Regularized Optimization}, - journal = {SIAM Journal on Optimization}, - volume = {32}, - number = {2}, - pages = {900--929}, - year = {2022}, - doi = {10.1137/21M1409536}, - abstract = { We develop a trust-region method for minimizing the sum of a smooth term (f) and a nonsmooth term (h), both of which can be nonconvex. Each iteration of our method minimizes a possibly nonconvex model of (f + h) in a trust region. The model coincides with (f + h) in value and subdifferential at the center. We establish global convergence to a first-order stationary point when (f) satisfies a smoothness condition that holds, in particular, when it has a Lipschitz-continuous gradient, and (h) is proper and lower semicontinuous. The model of (h) is required to be proper, lower semi-continuous and prox-bounded. Under these weak assumptions, we establish a worst-case (O(1/\epsilon^2)) iteration complexity bound that matches the best known complexity bound of standard trust-region methods for smooth optimization. We detail a special instance, named TR-PG, in which we use a limited-memory quasi-Newton model of (f) and compute a step with the proximal gradient method, resulting in a practical proximal quasi-Newton method. We establish similar convergence properties and complexity bound for a quadratic regularization variant, named R2, and provide an interpretation as a proximal gradient method with adaptive step size for nonconvex problems. R2 may also be used to compute steps inside the trust-region method, resulting in an implementation named TR-R2. We describe our Julia implementations and report numerical results on inverse problems from sparse optimization and signal processing. Both TR-PG and TR-R2 exhibit promising performance and compare favorably with two linesearch proximal quasi-Newton methods based on convex models. } -} -``` + diff --git a/benchmarks/tables/bpdn-constr-table.jl b/benchmarks/tables/bpdn-constr-table.jl index 3c4207a2..0ead555e 100644 --- a/benchmarks/tables/bpdn-constr-table.jl +++ b/benchmarks/tables/bpdn-constr-table.jl @@ -17,8 +17,14 @@ verbose = 0 # 10 ϵri = 1.0e-6 maxIter = 500 maxIter_inner = 100 -options = - ROSolverOptions(ν = ν, ϵa = ϵ, ϵr = ϵ, verbose = verbose, maxIter = maxIter, spectral = true) +options = ROSolverOptions( + ν = ν, + ϵa = ϵ, + ϵr = ϵ, + verbose = verbose, + maxIter = maxIter, + spectral = true, +) options_nrTR = ROSolverOptions( ν = ν, ϵa = ϵ, @@ -28,7 +34,8 @@ options_nrTR = ROSolverOptions( spectral = true, reduce_TR = false, ) -options2 = ROSolverOptions(spectral = false, psb = true, ϵa = ϵi, ϵr = ϵri, maxIter = maxIter_inner) +options2 = + ROSolverOptions(spectral = false, psb = true, ϵa = ϵi, ϵr = ϵri, maxIter = maxIter_inner) options2_nrTR = ROSolverOptions( spectral = false, psb = true, @@ -48,8 +55,13 @@ options3_nrTR = ROSolverOptions( reduce_TR = false, ) options4 = ROSolverOptions(spectral = true, ϵa = ϵi, ϵr = ϵri, maxIter = maxIter_inner) -options4_nrTR = - ROSolverOptions(spectral = true, ϵa = ϵi, ϵr = ϵri, maxIter = maxIter_inner, reduce_TR = false) +options4_nrTR = ROSolverOptions( + spectral = true, + ϵa = ϵi, + ϵr = ϵri, + maxIter = maxIter_inner, + reduce_TR = false, +) options5 = ROSolverOptions( ν = ν, ϵa = ϵ, @@ -90,8 +102,22 @@ options6_nrTR = ROSolverOptions( ) solvers = [:R2, :TRDH, :TRDH, :TRDH, :TRDH, :TRDH, :TRDH, :TR, :TR, :TR, :TR, :TR, :TR, :TR] -subsolvers = - [:None, :None, :None, :None, :None, :None, :None, :R2, :TRDH, :TRDH, :TRDH, :TRDH, :TRDH, :TRDH] +subsolvers = [ + :None, + :None, + :None, + :None, + :None, + :None, + :None, + :R2, + :TRDH, + :TRDH, + :TRDH, + :TRDH, + :TRDH, + :TRDH, +] solver_options = [ options, options, diff --git a/benchmarks/tables/bpdn-table.jl b/benchmarks/tables/bpdn-table.jl index dfa5768c..27f9a50c 100644 --- a/benchmarks/tables/bpdn-table.jl +++ b/benchmarks/tables/bpdn-table.jl @@ -18,8 +18,14 @@ verbose = 0 # 10 ϵri = 1.0e-6 maxIter = 500 maxIter_inner = 100 -options = - ROSolverOptions(ν = ν, ϵa = ϵ, ϵr = ϵ, verbose = verbose, maxIter = maxIter, spectral = true) +options = ROSolverOptions( + ν = ν, + ϵa = ϵ, + ϵr = ϵ, + verbose = verbose, + maxIter = maxIter, + spectral = true, +) options_nrTR = ROSolverOptions( ν = ν, ϵa = ϵ, @@ -29,7 +35,8 @@ options_nrTR = ROSolverOptions( spectral = true, reduce_TR = false, ) -options2 = ROSolverOptions(spectral = false, psb = true, ϵa = ϵi, ϵr = ϵri, maxIter = maxIter_inner) +options2 = + ROSolverOptions(spectral = false, psb = true, ϵa = ϵi, ϵr = ϵri, maxIter = maxIter_inner) options2_nrTR = ROSolverOptions( spectral = false, psb = true, @@ -49,8 +56,13 @@ options3_nrTR = ROSolverOptions( reduce_TR = false, ) options4 = ROSolverOptions(spectral = true, ϵa = ϵi, ϵr = ϵri, maxIter = maxIter_inner) -options4_nrTR = - ROSolverOptions(spectral = true, ϵa = ϵi, ϵr = ϵri, maxIter = maxIter_inner, reduce_TR = false) +options4_nrTR = ROSolverOptions( + spectral = true, + ϵa = ϵi, + ϵr = ϵri, + maxIter = maxIter_inner, + reduce_TR = false, +) options5 = ROSolverOptions( ν = ν, ϵa = ϵ, @@ -91,8 +103,22 @@ options6_nrTR = ROSolverOptions( ) solvers = [:R2, :TRDH, :TRDH, :TRDH, :TRDH, :TRDH, :TRDH, :TR, :TR, :TR, :TR, :TR, :TR, :TR] -subsolvers = - [:None, :None, :None, :None, :None, :None, :None, :R2, :TRDH, :TRDH, :TRDH, :TRDH, :TRDH, :TRDH] +subsolvers = [ + :None, + :None, + :None, + :None, + :None, + :None, + :None, + :R2, + :TRDH, + :TRDH, + :TRDH, + :TRDH, + :TRDH, + :TRDH, +] solver_options = [ options, options, diff --git a/benchmarks/tables/fh-table.jl b/benchmarks/tables/fh-table.jl index 4584e2e0..fcd844e1 100644 --- a/benchmarks/tables/fh-table.jl +++ b/benchmarks/tables/fh-table.jl @@ -23,8 +23,14 @@ maxIter_inner = 200 # max iter for subsolver ϵ = 1.0e-4 ϵi = 1.0e-3 ϵri = 1.0e-6 -options = - ROSolverOptions(ν = ν, ϵa = ϵ, ϵr = ϵ, verbose = verbose, maxIter = maxIter, spectral = true) +options = ROSolverOptions( + ν = ν, + ϵa = ϵ, + ϵr = ϵ, + verbose = verbose, + maxIter = maxIter, + spectral = true, +) options_nrTR = ROSolverOptions( ν = ν, ϵa = ϵ, @@ -34,7 +40,8 @@ options_nrTR = ROSolverOptions( spectral = true, reduce_TR = false, ) -options2 = ROSolverOptions(spectral = false, psb = true, ϵa = ϵi, ϵr = ϵri, maxIter = maxIter_inner) +options2 = + ROSolverOptions(spectral = false, psb = true, ϵa = ϵi, ϵr = ϵri, maxIter = maxIter_inner) options2_nrTR = ROSolverOptions( spectral = false, psb = true, @@ -54,8 +61,13 @@ options3_nrTR = ROSolverOptions( reduce_TR = false, ) options4 = ROSolverOptions(spectral = true, ϵa = ϵi, ϵr = ϵri, maxIter = maxIter_inner) -options4_nrTR = - ROSolverOptions(spectral = true, ϵa = ϵi, ϵr = ϵri, maxIter = maxIter_inner, reduce_TR = false) +options4_nrTR = ROSolverOptions( + spectral = true, + ϵa = ϵi, + ϵr = ϵri, + maxIter = maxIter_inner, + reduce_TR = false, +) options5 = ROSolverOptions( ν = ν, ϵa = ϵ, @@ -96,8 +108,22 @@ options6_nrTR = ROSolverOptions( ) solvers = [:R2, :TRDH, :TRDH, :TRDH, :TRDH, :TRDH, :TRDH, :TR, :TR, :TR, :TR, :TR, :TR, :TR] -subsolvers = - [:None, :None, :None, :None, :None, :None, :None, :R2, :TRDH, :TRDH, :TRDH, :TRDH, :TRDH, :TRDH] +subsolvers = [ + :None, + :None, + :None, + :None, + :None, + :None, + :None, + :R2, + :TRDH, + :TRDH, + :TRDH, + :TRDH, + :TRDH, + :TRDH, +] solver_options = [ options, options, diff --git a/benchmarks/tables/nnmf-table.jl b/benchmarks/tables/nnmf-table.jl index 20cabfc6..4c683221 100644 --- a/benchmarks/tables/nnmf-table.jl +++ b/benchmarks/tables/nnmf-table.jl @@ -14,8 +14,14 @@ h = NormL0(λ) maxIter = 500 maxIter_inner = 100 verbose = 0 #10 -options = - ROSolverOptions(ν = ν, ϵa = ϵ, ϵr = ϵ, verbose = verbose, maxIter = maxIter, spectral = true) +options = ROSolverOptions( + ν = ν, + ϵa = ϵ, + ϵr = ϵ, + verbose = verbose, + maxIter = maxIter, + spectral = true, +) options_nrTR = ROSolverOptions( ν = ν, ϵa = ϵ, @@ -25,7 +31,8 @@ options_nrTR = ROSolverOptions( spectral = true, reduce_TR = false, ) -options2 = ROSolverOptions(spectral = false, psb = true, ϵa = ϵi, ϵr = ϵri, maxIter = maxIter_inner) +options2 = + ROSolverOptions(spectral = false, psb = true, ϵa = ϵi, ϵr = ϵri, maxIter = maxIter_inner) options2_nrTR = ROSolverOptions( spectral = false, psb = true, @@ -45,8 +52,13 @@ options3_nrTR = ROSolverOptions( reduce_TR = false, ) options4 = ROSolverOptions(spectral = true, ϵa = ϵi, ϵr = ϵri, maxIter = maxIter_inner) -options4_nrTR = - ROSolverOptions(spectral = true, ϵa = ϵi, ϵr = ϵri, maxIter = maxIter_inner, reduce_TR = false) +options4_nrTR = ROSolverOptions( + spectral = true, + ϵa = ϵi, + ϵr = ϵri, + maxIter = maxIter_inner, + reduce_TR = false, +) options5 = ROSolverOptions( ν = ν, ϵa = ϵ, @@ -87,8 +99,22 @@ options6_nrTR = ROSolverOptions( ) solvers = [:R2, :TRDH, :TRDH, :TRDH, :TRDH, :TRDH, :TRDH, :TR, :TR, :TR, :TR, :TR, :TR, :TR] -subsolvers = - [:None, :None, :None, :None, :None, :None, :None, :R2, :TRDH, :TRDH, :TRDH, :TRDH, :TRDH, :TRDH] +subsolvers = [ + :None, + :None, + :None, + :None, + :None, + :None, + :None, + :R2, + :TRDH, + :TRDH, + :TRDH, + :TRDH, + :TRDH, + :TRDH, +] solver_options = [ options, options, diff --git a/benchmarks/tables/regulopt-tables.jl b/benchmarks/tables/regulopt-tables.jl index ffaddff1..bd0dbaff 100644 --- a/benchmarks/tables/regulopt-tables.jl +++ b/benchmarks/tables/regulopt-tables.jl @@ -26,7 +26,8 @@ function options_str( out_str = !options.spectral ? (options.psb ? "-PSB" : "-Andrei") : "-Spec" out_str = (options.reduce_TR) ? out_str : string(out_str, "-noredTR") elseif solver == :TR && subsolver == :TRDH - out_str = !subsolver_options.spectral ? (subsolver_options.psb ? "-PSB" : "-Andrei") : "-Spec" + out_str = + !subsolver_options.spectral ? (subsolver_options.psb ? "-PSB" : "-Andrei") : "-Spec" out_str = (subsolver_options.reduce_TR) ? out_str : string(out_str, "-noredTR") else out_str = "" @@ -175,14 +176,19 @@ function benchmark_table( h_format = h isa NormL0 ? "%i" : "%7.1e" if length(sol) == 0 - print_formats = ft_printf(["%s", "%7.2e", h_format, "%7.1e", "%i", "%i", "%i", "%7.1e"], 1:nh) + print_formats = + ft_printf(["%s", "%7.2e", h_format, "%7.1e", "%i", "%i", "%i", "%7.1e"], 1:nh) else if pb_name[1:3] == "SVM" - print_formats = - ft_printf(["%s", "%7.2e", h_format, "%7.1e", "%7s", "%i", "%i", "%i", "%7.1e"], 1:nh) + print_formats = ft_printf( + ["%s", "%7.2e", h_format, "%7.1e", "%7s", "%i", "%i", "%i", "%7.1e"], + 1:nh, + ) else - print_formats = - ft_printf(["%s", "%7.2e", h_format, "%7.1e", "%7.1e", "%i", "%i", "%i", "%7.1e"], 1:nh) + print_formats = ft_printf( + ["%s", "%7.2e", h_format, "%7.1e", "%7.1e", "%i", "%i", "%i", "%7.1e"], + 1:nh, + ) end end diff --git a/benchmarks/tables/svm-table.jl b/benchmarks/tables/svm-table.jl index ed937972..d9381c61 100644 --- a/benchmarks/tables/svm-table.jl +++ b/benchmarks/tables/svm-table.jl @@ -17,8 +17,14 @@ verbose = 0 #10 ϵri = 1.0e-6 maxIter = 1000 maxIter_inner = 100 -options = - ROSolverOptions(ν = ν, ϵa = ϵ, ϵr = ϵ, verbose = verbose, maxIter = maxIter, spectral = true) +options = ROSolverOptions( + ν = ν, + ϵa = ϵ, + ϵr = ϵ, + verbose = verbose, + maxIter = maxIter, + spectral = true, +) options_nrTR = ROSolverOptions( ν = ν, ϵa = ϵ, @@ -28,7 +34,8 @@ options_nrTR = ROSolverOptions( spectral = true, reduce_TR = false, ) -options2 = ROSolverOptions(spectral = false, psb = true, ϵa = ϵi, ϵr = ϵri, maxIter = maxIter_inner) +options2 = + ROSolverOptions(spectral = false, psb = true, ϵa = ϵi, ϵr = ϵri, maxIter = maxIter_inner) options2_nrTR = ROSolverOptions( spectral = false, psb = true, @@ -48,8 +55,13 @@ options3_nrTR = ROSolverOptions( reduce_TR = false, ) options4 = ROSolverOptions(spectral = true, ϵa = ϵi, ϵr = ϵri, maxIter = maxIter_inner) -options4_nrTR = - ROSolverOptions(spectral = true, ϵa = ϵi, ϵr = ϵri, maxIter = maxIter_inner, reduce_TR = false) +options4_nrTR = ROSolverOptions( + spectral = true, + ϵa = ϵi, + ϵr = ϵri, + maxIter = maxIter_inner, + reduce_TR = false, +) options5 = ROSolverOptions( ν = ν, ϵa = ϵ, @@ -90,8 +102,22 @@ options6_nrTR = ROSolverOptions( ) solvers = [:R2, :TRDH, :TRDH, :TRDH, :TRDH, :TRDH, :TRDH, :TR, :TR, :TR, :TR, :TR, :TR, :TR] -subsolvers = - [:None, :None, :None, :None, :None, :None, :None, :R2, :TRDH, :TRDH, :TRDH, :TRDH, :TRDH, :TRDH] +subsolvers = [ + :None, + :None, + :None, + :None, + :None, + :None, + :None, + :R2, + :TRDH, + :TRDH, + :TRDH, + :TRDH, + :TRDH, + :TRDH, +] solver_options = [ options, options, diff --git a/docs/_config.yml b/docs/_config.yml index 2f7efbea..fff4ab92 100644 --- a/docs/_config.yml +++ b/docs/_config.yml @@ -1 +1 @@ -theme: jekyll-theme-minimal \ No newline at end of file +theme: jekyll-theme-minimal diff --git a/docs/make.jl b/docs/make.jl index fd1dc2de..b7c95926 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -1,19 +1,28 @@ -using Documenter, RegularizedOptimization +using RegularizedOptimization +using Documenter -makedocs( +DocMeta.setdocmeta!( + RegularizedOptimization, + :DocTestSetup, + :(using RegularizedOptimization); + recursive = true, +) + +const page_rename = Dict("developer.md" => "Developer docs") # Without the numbers +const numbered_pages = [ + file for file in readdir(joinpath(@__DIR__, "src")) if + file != "index.md" && splitext(file)[2] == ".md" +] + +makedocs(; modules = [RegularizedOptimization], - doctest = true, - # linkcheck = true, - strict = true, - format = Documenter.HTML( - assets = ["assets/style.css"], - prettyurls = get(ENV, "CI", nothing) == "true", - ), + authors = "Robert Baraldi and Dominique Orban ", + repo = "https://github.com/JuliaSmoothOptimizers/RegularizedOptimization.jl/blob/{commit}{path}#{line}", sitename = "RegularizedOptimization.jl", - pages = Any["Home" => "index.md", "Tutorial" => "tutorial.md", "Reference" => "reference.md"], + format = Documenter.HTML(; + canonical = "https://JuliaSmoothOptimizers.github.io/RegularizedOptimization.jl", + ), + pages = ["index.md"; numbered_pages], ) -deploydocs( - repo = "github.com/JuliaSmoothOptimizers/RegularizedOptimization.jl.git", - push_preview = true, -) +deploydocs(; repo = "github.com/JuliaSmoothOptimizers/RegularizedOptimization.jl") diff --git a/docs/src/90-contributing.md b/docs/src/90-contributing.md new file mode 100644 index 00000000..f24ddbb4 --- /dev/null +++ b/docs/src/90-contributing.md @@ -0,0 +1,25 @@ +# [Contributing guidelines](@id contributing) + +First of all, thanks for the interest! + +We welcome all kinds of contribution, including, but not limited to code, documentation, examples, configuration, issue creating, etc. + +Be polite and respectful, and follow the code of conduct. + +## Bug reports and discussions + +If you think you found a bug, feel free to open an [issue](https://github.com/JuliaSmoothOptimizers/RegularizedOptimization.jl/issues). +Focused suggestions and requests can also be opened as issues. +Before opening a pull request, start an issue or a discussion on the topic, please. + +## Working on an issue + +If you found an issue that interests you, comment on that issue what your plans are. +If the solution to the issue is clear, you can immediately create a pull request (see below). +Otherwise, say what your proposed solution is and wait for a discussion around it. + +!!! tip + Feel free to ping us after a few days if there are no responses. + +If your solution involves code (or something that requires running the package locally), check the [developer documentation](91-developer.md). +Otherwise, you can use the GitHub interface directly to create your pull request. diff --git a/docs/src/91-developer.md b/docs/src/91-developer.md new file mode 100644 index 00000000..7bf27edb --- /dev/null +++ b/docs/src/91-developer.md @@ -0,0 +1,163 @@ +# [Developer documentation](@id dev_docs) + +!!! note "Contributing guidelines" + If you haven't, please read the [Contributing guidelines](90-contributing.md) first. + +If you want to make contributions to this package that involves code, then this guide is for you. + +## First time clone + +!!! tip "If you have writing rights" + If you have writing rights, you don't have to fork. Instead, simply clone and skip ahead. Whenever **upstream** is mentioned, use **origin** instead. + +If this is the first time you work with this repository, follow the instructions below to clone the repository. + +1. Fork this repo +2. Clone your repo (this will create a `git remote` called `origin`) +3. Add this repo as a remote: + + ```bash + git remote add upstream https://github.com/JuliaSmoothOptimizers/RegularizedOptimization.jl + ``` + +This will ensure that you have two remotes in your git: `origin` and `upstream`. +You will create branches and push to `origin`, and you will fetch and update your local `main` branch from `upstream`. + +## Linting and formatting + +Install a plugin on your editor to use [EditorConfig](https://editorconfig.org). +This will ensure that your editor is configured with important formatting settings. + +We use [https://pre-commit.com](https://pre-commit.com) to run the linters and formatters. +In particular, the Julia code is formatted using [JuliaFormatter.jl](https://github.com/domluna/JuliaFormatter.jl), so please install it globally first: + +```julia-repl +julia> # Press ] +pkg> activate +pkg> add JuliaFormatter +``` + +To install `pre-commit`, we recommend using [pipx](https://pipx.pypa.io) as follows: + +```bash +# Install pipx following the link +pipx install pre-commit +``` + +With `pre-commit` installed, activate it as a pre-commit hook: + +```bash +pre-commit install +``` + +To run the linting and formatting manually, enter the command below: + +```bash +pre-commit run -a +``` + +**Now, you can only commit if all the pre-commit tests pass**. + +## Testing + +As with most Julia packages, you can just open Julia in the repository folder, activate the environment, and run `test`: + +```julia-repl +julia> # press ] +pkg> activate . +pkg> test +``` + +## Working on a new issue + +We try to keep a linear history in this repo, so it is important to keep your branches up-to-date. + +1. Fetch from the remote and fast-forward your local main + + ```bash + git fetch upstream + git switch main + git merge --ff-only upstream/main + ``` + +2. Branch from `main` to address the issue (see below for naming) + + ```bash + git switch -c 42-add-answer-universe + ``` + +3. Push the new local branch to your personal remote repository + + ```bash + git push -u origin 42-add-answer-universe + ``` + +4. Create a pull request to merge your remote branch into the org main. + +### Branch naming + +- If there is an associated issue, add the issue number. +- If there is no associated issue, **and the changes are small**, add a prefix such as "typo", "hotfix", "small-refactor", according to the type of update. +- If the changes are not small and there is no associated issue, then create the issue first, so we can properly discuss the changes. +- Use dash separated imperative wording related to the issue (e.g., `14-add-tests`, `15-fix-model`, `16-remove-obsolete-files`). + +### Commit message + +- Use imperative or present tense, for instance: *Add feature* or *Fix bug*. +- Have informative titles. +- When necessary, add a body with details. +- If there are breaking changes, add the information to the commit message. + +### Before creating a pull request + +!!! tip "Atomic git commits" + Try to create "atomic git commits" (recommended reading: [The Utopic Git History](https://blog.esciencecenter.nl/the-utopic-git-history-d44b81c09593)). + +- Make sure the tests pass. +- Make sure the pre-commit tests pass. +- Fetch any `main` updates from upstream and rebase your branch, if necessary: + + ```bash + git fetch upstream + git rebase upstream/main BRANCH_NAME + ``` + +- Then you can open a pull request and work with the reviewer to address any issues. + +## Building and viewing the documentation locally + +Following the latest suggestions, we recommend using `LiveServer` to build the documentation. +Here is how you do it: + +1. Run `julia --project=docs` to open Julia in the environment of the docs. +1. If this is the first time building the docs + 1. Press `]` to enter `pkg` mode + 1. Run `pkg> dev .` to use the development version of your package + 1. Press backspace to leave `pkg` mode +1. Run `julia> using LiveServer` +1. Run `julia> servedocs()` + +## Making a new release + +To create a new release, you can follow these simple steps: + +- Create a branch `release-x.y.z` +- Update `version` in `Project.toml` +- Update the `CHANGELOG.md`: + - Rename the section "Unreleased" to "[x.y.z] - yyyy-mm-dd" (i.e., version under brackets, dash, and date in ISO format) + - Add a new section on top of it named "Unreleased" + - Add a new link in the bottom for version "x.y.z" + - Change the "[unreleased]" link to use the latest version - end of line, `vx.y.z ... HEAD`. +- Create a commit "Release vx.y.z", push, create a PR, wait for it to pass, merge the PR. +- Go back to main screen and click on the latest commit (link: ) +- At the bottom, write `@JuliaRegistrator register` + +After that, you only need to wait and verify: + +- Wait for the bot to comment (should take < 1m) with a link to a PR to the registry +- Follow the link and wait for a comment on the auto-merge +- The comment should said all is well and auto-merge should occur shortly +- After the merge happens, TagBot will trigger and create a new GitHub tag. Check on +- After the release is create, a "docs" GitHub action will start for the tag. +- After it passes, a deploy action will run. +- After that runs, the [stable docs](https://JuliaSmoothOptimizers.github.io/RegularizedOptimization.jl/stable) should be updated. Check them and look for the version number. diff --git a/docs/src/95-reference.md b/docs/src/95-reference.md new file mode 100644 index 00000000..7a284418 --- /dev/null +++ b/docs/src/95-reference.md @@ -0,0 +1,17 @@ +# [Reference](@id reference) + +## Contents + +```@contents +Pages = ["95-reference.md"] +``` + +## Index + +```@index +Pages = ["95-reference.md"] +``` + +```@autodocs +Modules = [RegularizedOptimization] +``` diff --git a/docs/src/assets/badge.json b/docs/src/assets/badge.json new file mode 100644 index 00000000..78e9b79a --- /dev/null +++ b/docs/src/assets/badge.json @@ -0,0 +1,7 @@ +{ + "color": "#cb3c33", + "label": "using", + "labelColor": "white", + "logoSvg": "\n\n\n\n \n \n\n", + "message": "BestieTemplate" +} \ No newline at end of file diff --git a/docs/src/assets/style.css b/docs/src/assets/style.css index 7f1fab0d..f2cf50df 100644 --- a/docs/src/assets/style.css +++ b/docs/src/assets/style.css @@ -2,7 +2,7 @@ html.theme--documenter-dark #documenter .docs-sidebar { border-right: 4px solid #640000; background-color: #8c1515; - color: #fff; + color: #fff; } .mi, .mo, .mn { @@ -24,4 +24,4 @@ a:hover { nav.toc .logo { max-width: 256px; max-height: 256px; -} \ No newline at end of file +} diff --git a/docs/src/index.md b/docs/src/index.md index 4b393b13..b02be5ae 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -1 +1,20 @@ -# RegularizedOptimization.jl +```@meta +CurrentModule = RegularizedOptimization +``` + +# RegularizedOptimization + +Documentation for [RegularizedOptimization](https://github.com/JuliaSmoothOptimizers/RegularizedOptimization.jl). + +## Contributors + +```@raw html + + + + + + + + +``` diff --git a/examples/demo-fh.jl b/examples/demo-fh.jl index 702846a6..13078577 100644 --- a/examples/demo-fh.jl +++ b/examples/demo-fh.jl @@ -1,6 +1,7 @@ using LinearAlgebra using DifferentialEquations, ProximalOperators -using ADNLPModels, NLPModels, NLPModelsModifiers, RegularizedOptimization, RegularizedProblems +using ADNLPModels, + NLPModels, NLPModelsModifiers, RegularizedOptimization, RegularizedProblems include("plot-utils-fh.jl") diff --git a/examples/demo-nnmf-constr.jl b/examples/demo-nnmf-constr.jl index a8932939..12bda35b 100644 --- a/examples/demo-nnmf-constr.jl +++ b/examples/demo-nnmf-constr.jl @@ -9,7 +9,8 @@ include("plot-utils-nnmf.jl") Random.seed!(1234) function demo_solver(f, h, χ, selected, Avec, m, n, k, suffix = "l0-linf") - options = ROSolverOptions(ν = 1.0e-3, β = 1e16, ϵa = 1e-6, ϵr = 1e-6, verbose = 10, maxIter = 500) + options = + ROSolverOptions(ν = 1.0e-3, β = 1e16, ϵa = 1e-6, ϵr = 1e-6, verbose = 10, maxIter = 500) @info " using TR to solve with" h χ TR_out = TR(LSR1Model(f), h, χ, options, selected = selected) plot_nnmf(TR_out, Avec, m, n, k, "tr-r2-$suffix") diff --git a/examples/plot-utils-nnmf.jl b/examples/plot-utils-nnmf.jl index ed36381e..4e9cd936 100644 --- a/examples/plot-utils-nnmf.jl +++ b/examples/plot-utils-nnmf.jl @@ -19,11 +19,17 @@ function plot_nnmf(outstruct, Avec, m, n, k, name = "tr-qr") ) push!( a, - Axis(Plots.Image(WH, (1, m), (1, n), colormap = ColorMaps.Named("Jet")), xlabel = "WH matrix"), + Axis( + Plots.Image(WH, (1, m), (1, n), colormap = ColorMaps.Named("Jet")), + xlabel = "WH matrix", + ), ) push!( a, - Axis(Plots.Image(H, (1, k), (1, n), colormap = ColorMaps.Named("Jet")), xlabel = "H matrix"), + Axis( + Plots.Image(H, (1, k), (1, n), colormap = ColorMaps.Named("Jet")), + xlabel = "H matrix", + ), ) push!( a, diff --git a/src/AL_alg.jl b/src/AL_alg.jl index 6d3f3fb6..f87e17b0 100644 --- a/src/AL_alg.jl +++ b/src/AL_alg.jl @@ -42,7 +42,9 @@ function AL( ) where {V} nlp = reg_nlp.model if nlp.meta.ncon == 0 || equality_constrained(nlp) - error("AL(::Val{:ineq}, ...) should only be called for problems with inequalities. Use AL(...)") + error( + "AL(::Val{:ineq}, ...) should only be called for problems with inequalities. Use AL(...)", + ) end snlp = nlp isa AbstractNLSModel ? SlackNLSModel(nlp) : SlackModel(nlp) reg_snlp = RegularizedNLPModel(snlp, reg_nlp.h, reg_nlp.selected) @@ -74,7 +76,7 @@ At each iteration, an iterate x is computed as an approximate solution of the su minimize L(x;y,μ) + h(x) subject to lvar ≤ x ≤ uvar -where y is an estimate of the Lagrange multiplier vector for the constraints lcon ≤ c(x) ≤ ucon, +where y is an estimate of the Lagrange multiplier vector for the constraints lcon ≤ c(x) ≤ ucon, μ is the penalty parameter and L(⋅;y,μ) is the augmented Lagrangian function defined by L(x;y,μ) := f(x) - yᵀc(x) + ½ μ ‖c(x)‖². @@ -90,7 +92,7 @@ For advanced usage, first define a solver "ALSolver" to preallocate the memory u # Arguments -- `reg_nlp::AbstractRegularizedNLPModel`: a regularized optimization problem, see `RegularizedProblems.jl`, +- `reg_nlp::AbstractRegularizedNLPModel`: a regularized optimization problem, see `RegularizedProblems.jl`, consisting of `model` representing a smooth optimization problem, see `NLPModels.jl`, and a regularizer `h` such as those defined in `ProximalOperators.jl`. @@ -172,7 +174,11 @@ function ALSolver(reg_nlp::AbstractRegularizedNLPModel{T, V}; kwargs...) where { ) end -@doc (@doc ALSolver) function AL(::Val{:equ}, reg_nlp::AbstractRegularizedNLPModel; kwargs...) +@doc (@doc ALSolver) function AL( + ::Val{:equ}, + reg_nlp::AbstractRegularizedNLPModel; + kwargs..., +) nlp = reg_nlp.model if !(nlp.meta.minimize) error("AL only works for minimization problems") @@ -363,7 +369,9 @@ function SolverCore.solve!( done = stats.status != :unknown if verbose > 0 && (mod(stats.iter, verbose) == 0 || done) - @info log_row(Any[iter, subiters, objx, cviol, mu, norm(solver.y), subtol, subout.status]) + @info log_row( + Any[iter, subiters, objx, cviol, mu, norm(solver.y), subtol, subout.status], + ) end if !done diff --git a/src/LMTR_alg.jl b/src/LMTR_alg.jl index 621bedb4..2615b569 100644 --- a/src/LMTR_alg.jl +++ b/src/LMTR_alg.jl @@ -104,7 +104,8 @@ function LMTR( xkn = similar(xk) s = zero(xk) ψ = - treats_bounds ? shifted(h, xk, max.(-Δk, l_bound - xk), min.(Δk, u_bound - xk), selected) : + treats_bounds ? + shifted(h, xk, max.(-Δk, l_bound - xk), min.(Δk, u_bound - xk), selected) : shifted(h, xk, Δk, χ) Fobj_hist = zeros(maxIter) @@ -177,7 +178,8 @@ function LMTR( # s1 minimizes φ1(d) + ‖d‖² / 2 / ν + ψ(d) ⟺ s1 ∈ prox{νψ}(-ν∇φ1(0)) prox!(s, ψ, mν∇fk, ν) ξ1 = fk + hk - mk1(s) + max(1, abs(fk + hk)) * 10 * eps() - ξ1 > 0 || error("LMTR: first prox-gradient step should produce a decrease but ξ1 = $(ξ1)") + ξ1 > 0 || + error("LMTR: first prox-gradient step should produce a decrease but ξ1 = $(ξ1)") if ξ1 ≥ 0 && k == 1 ϵ_increment = ϵr * sqrt(ξ1) diff --git a/src/LM_alg.jl b/src/LM_alg.jl index 9f179a5e..997b1204 100644 --- a/src/LM_alg.jl +++ b/src/LM_alg.jl @@ -29,7 +29,10 @@ mutable struct LMSolver{ substats::GenericExecutionStats{T, V, V, T} end -function LMSolver(reg_nls::AbstractRegularizedNLPModel{T, V}; subsolver = R2Solver) where {T, V} +function LMSolver( + reg_nls::AbstractRegularizedNLPModel{T, V}; + subsolver = R2Solver, +) where {T, V} x0 = reg_nls.model.meta.x0 l_bound = reg_nls.model.meta.lvar u_bound = reg_nls.model.meta.uvar @@ -110,7 +113,7 @@ For advanced usage, first define a solver "LMSolver" to preallocate the memory u stats = RegularizedExecutionStats(reg_nls) solve!(solver, reg_nls, stats) - + # Arguments * `reg_nls::AbstractRegularizedNLPModel{T, V}`: the problem to solve, see `RegularizedProblems.jl`, `NLPModels.jl`. @@ -202,7 +205,7 @@ function SolverCore.solve!( xk = solver.xk .= x - # Make sure ψ has the correct shift + # Make sure ψ has the correct shift shift!(solver.ψ, xk) Fk = solver.Fk diff --git a/src/R2DH.jl b/src/R2DH.jl index 1edb81eb..d232d8a6 100644 --- a/src/R2DH.jl +++ b/src/R2DH.jl @@ -107,11 +107,11 @@ or stats = RegularizedExecutionStats(reg_nlp) solver = R2DHSolver(reg_nlp) solve!(solver, reg_nlp, stats) - + # Arguments * `reg_nlp::AbstractRegularizedNLPModel{T, V}`: the problem to solve, see `RegularizedProblems.jl`, `NLPModels.jl`. -# Keyword arguments +# Keyword arguments - `x::V = nlp.meta.x0`: the initial guess; - `atol::T = √eps(T)`: absolute tolerance; - `rtol::T = √eps(T)`: relative tolerance; @@ -125,7 +125,7 @@ or - `η1::T = √√eps(T)`: very successful iteration threshold; - `η2::T = T(0.9)`: successful iteration threshold; - `γ::T = T(3)`: regularization parameter multiplier, σ := σ/γ when the iteration is very successful and σ := σγ when the iteration is unsuccessful. -- `θ::T = 1/(1 + eps(T)^(1 / 5))`: is the model decrease fraction with respect to the decrease of the Cauchy model. +- `θ::T = 1/(1 + eps(T)^(1 / 5))`: is the model decrease fraction with respect to the decrease of the Cauchy model. - `m_monotone::Int = 6`: monotoneness parameter. By default, R2DH is non-monotone but the monotone variant can be used with `m_monotone = 1` The algorithm stops either when `√(ξₖ/νₖ) < atol + rtol*√(ξ₀/ν₀) ` or `ξₖ < 0` and `√(-ξₖ/νₖ) < neg_tol` where ξₖ := f(xₖ) + h(xₖ) - φ(sₖ; xₖ) - ψ(sₖ; xₖ), and √(ξₖ/νₖ) is a stationarity measure. @@ -188,7 +188,13 @@ function R2DH( x0::AbstractVector{R}; selected::AbstractVector{<:Integer} = 1:length(x0), kwargs..., -) where {F <: Function, G <: Function, H, R <: Real, DQN <: AbstractDiagonalQuasiNewtonOperator} +) where { + F <: Function, + G <: Function, + H, + R <: Real, + DQN <: AbstractDiagonalQuasiNewtonOperator, +} nlp = FirstOrderModel(f, ∇f!, x0) reg_nlp = RegularizedNLPModel(nlp, h, selected) stats = R2DH( @@ -252,7 +258,7 @@ function SolverCore.solve!( xk = solver.xk .= x - # Make sure ψ has the correct shift + # Make sure ψ has the correct shift shift!(solver.ψ, xk) ∇fk = solver.∇fk diff --git a/src/R2N.jl b/src/R2N.jl index 1fd94b14..efcfe09f 100644 --- a/src/R2N.jl +++ b/src/R2N.jl @@ -114,11 +114,11 @@ For advanced usage, first define a solver "R2NSolver" to preallocate the memory stats = RegularizedExecutionStats(reg_nlp) solve!(solver, reg_nlp, stats) - + # Arguments * `reg_nlp::AbstractRegularizedNLPModel{T, V}`: the problem to solve, see `RegularizedProblems.jl`, `NLPModels.jl`. -# Keyword arguments +# Keyword arguments - `x::V = nlp.meta.x0`: the initial guess; - `atol::T = √eps(T)`: absolute tolerance; - `rtol::T = √eps(T)`: relative tolerance; @@ -237,7 +237,7 @@ function SolverCore.solve!( xk = solver.xk .= x - # Make sure ψ has the correct shift + # Make sure ψ has the correct shift shift!(solver.ψ, xk) ∇fk = solver.∇fk diff --git a/src/R2NModel.jl b/src/R2NModel.jl index a4b2f990..61133d95 100644 --- a/src/R2NModel.jl +++ b/src/R2NModel.jl @@ -14,8 +14,11 @@ this model represents the smooth R2N subproblem: where `B` is either an approximation of the Hessian of `f` or the Hessian itself and `∇f` represents the gradient of `f` at `x0`. `σ > 0` is a regularization parameter and `v` is a vector of the same size as `x0` used for intermediary computations. """ -mutable struct R2NModel{T <: Real, V <: AbstractVector{T}, G <: AbstractLinearOperator{T}} <: - AbstractNLPModel{T, V} +mutable struct R2NModel{ + T <: Real, + V <: AbstractVector{T}, + G <: AbstractLinearOperator{T}, +} <: AbstractNLPModel{T, V} B::G ∇f::V v::V diff --git a/src/R2_alg.jl b/src/R2_alg.jl index 0cea37e8..438c3456 100644 --- a/src/R2_alg.jl +++ b/src/R2_alg.jl @@ -65,7 +65,10 @@ function R2Solver( ) end -function R2Solver(reg_nlp::AbstractRegularizedNLPModel{T, V}; max_iter::Int = 10000) where {T, V} +function R2Solver( + reg_nlp::AbstractRegularizedNLPModel{T, V}; + max_iter::Int = 10000, +) where {T, V} x0 = reg_nlp.model.meta.x0 l_bound = reg_nlp.model.meta.lvar u_bound = reg_nlp.model.meta.uvar @@ -139,7 +142,7 @@ For advanced usage, first define a solver "R2Solver" to preallocate the memory u # Arguments * `reg_nlp::AbstractRegularizedNLPModel{T, V}`: the problem to solve, see `RegularizedProblems.jl`, `NLPModels.jl`. -# Keyword arguments +# Keyword arguments - `x::V = nlp.meta.x0`: the initial guess; - `atol::T = √eps(T)`: absolute tolerance; - `rtol::T = √eps(T)`: relative tolerance; @@ -347,7 +350,7 @@ function SolverCore.solve!( xk = solver.xk .= x - # Make sure ψ has the correct shift + # Make sure ψ has the correct shift shift!(solver.ψ, xk) ∇fk = solver.∇fk diff --git a/src/RegularizedOptimization.jl b/src/RegularizedOptimization.jl index 57f9d13e..55aa060e 100644 --- a/src/RegularizedOptimization.jl +++ b/src/RegularizedOptimization.jl @@ -1,19 +1,70 @@ module RegularizedOptimization -# base dependencies -using LinearAlgebra, Logging, Printf - -# external dependencies -using Arpack, ProximalOperators - -# dependencies from us -using LinearOperators, - ManualNLPModels, +using Arpack: Arpack, eigs, svds +using LinearAlgebra: LinearAlgebra, /, dot, mul!, norm, opnorm +using LinearOperators: + LinearOperators, + AbstractDiagonalQuasiNewtonOperator, + AbstractLinearOperator, + SpectralGradient +using Logging: Logging, @debug, @info, @warn, with_logger +using ManualNLPModels: ManualNLPModels, NLPModel +using NLPModels: NLPModels, - NLPModelsModifiers, - RegularizedProblems, + @lencheck, + AbstractNLPModel, + AbstractNLSModel, + Counters, + NLPModelMeta, + bound_constrained, + equality_constrained, + grad!, + has_bounds, + hess_op, + hess_op!, + increment!, + jac_op_residual, + jprod_residual!, + jtprod_residual!, + neval_obj, + obj, + objcons!, + reset!, + residual, + residual!, + unconstrained +using NLPModelsModifiers: + NLPModelsModifiers, AbstractDiagonalQNModel, QuasiNewtonModel, SlackModel, SlackNLSModel +using Printf: Printf, @sprintf +using ProximalOperators: ProximalOperators, NormLinf +using RegularizedProblems: + RegularizedProblems, AbstractRegularizedNLPModel, FirstOrderModel, RegularizedNLPModel +using ShiftedProximalOperators: ShiftedProximalOperators, - SolverCore + ShiftedProximableFunction, + iprox!, + prox!, + set_bounds!, + set_radius!, + shift!, + shifted +using SolverCore: + SolverCore, + AbstractOptimizationSolver, + GenericExecutionStats, + log_header, + log_row, + set_constraint_multipliers!, + set_dual_residual!, + set_iter!, + set_objective!, + set_primal_residual!, + set_residuals!, + set_solution!, + set_solver_specific!, + set_status!, + set_time!, + solve! using Percival: AugLagModel, update_y!, update_μ! const callback_docstring = " diff --git a/src/TRDH_alg.jl b/src/TRDH_alg.jl index f91319f5..c52d7700 100644 --- a/src/TRDH_alg.jl +++ b/src/TRDH_alg.jl @@ -251,7 +251,7 @@ function SolverCore.solve!( xk = solver.xk .= x - # Make sure ψ has the correct shift + # Make sure ψ has the correct shift shift!(solver.ψ, xk) ∇fk = solver.∇fk @@ -373,7 +373,15 @@ function SolverCore.solve!( # update radius if has_bnds - update_bounds!(l_bound_m_x, u_bound_m_x, is_subsolver, l_bound, u_bound, xk, Δ_effective) + update_bounds!( + l_bound_m_x, + u_bound_m_x, + is_subsolver, + l_bound, + u_bound, + xk, + Δ_effective, + ) set_bounds!(ψ, l_bound_m_x, u_bound_m_x) else set_radius!(ψ, Δ_effective) @@ -460,7 +468,15 @@ function SolverCore.solve!( if ρk < η1 || ρk == Inf Δk = Δk / 2 if has_bnds - update_bounds!(l_bound_m_x, u_bound_m_x, is_subsolver, l_bound, u_bound, xk, Δ_effective) + update_bounds!( + l_bound_m_x, + u_bound_m_x, + is_subsolver, + l_bound, + u_bound, + xk, + Δ_effective, + ) set_bounds!(ψ, l_bound_m_x, u_bound_m_x) else set_radius!(ψ, Δk) diff --git a/src/TR_alg.jl b/src/TR_alg.jl index d55dca16..39fb38d8 100644 --- a/src/TR_alg.jl +++ b/src/TR_alg.jl @@ -62,7 +62,7 @@ function TRSolver( Bk = isa(reg_nlp.model, QuasiNewtonModel) ? hess_op(reg_nlp.model, xk) : hess_op!(reg_nlp.model, xk, similar(xk)) - sub_nlp = R2NModel(Bk, ∇fk, zero(T), x0) #FIXME + sub_nlp = R2NModel(Bk, ∇fk, zero(T), x0) #FIXME subpb = RegularizedNLPModel(sub_nlp, ψ) substats = RegularizedExecutionStats(subpb) subsolver = subsolver(subpb) @@ -211,7 +211,7 @@ function SolverCore.solve!( xk = solver.xk .= x - # Make sure ψ has the correct shift + # Make sure ψ has the correct shift shift!(solver.ψ, xk) ∇fk = solver.∇fk @@ -371,7 +371,7 @@ function SolverCore.solve!( ) end end - + prox_evals += solver.substats.iter s .= solver.substats.solution @@ -490,7 +490,19 @@ function SolverCore.solve!( end if verbose > 0 && stats.status == :first_order @info log_row( - Any[stats.iter, solver.substats.iter, fk, hk, sqrt_ξ1_νInv, ρk, Δk, χ(xk), χ(s), λmax, ""], + Any[ + stats.iter, + solver.substats.iter, + fk, + hk, + sqrt_ξ1_νInv, + ρk, + Δk, + χ(xk), + χ(s), + λmax, + "", + ], colsep = 1, ) @info "TR: terminating with √(ξ1/ν) = $(sqrt_ξ1_νInv)" diff --git a/src/utils.jl b/src/utils.jl index acc35592..da2a8040 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -58,7 +58,8 @@ function opnorm_svd(J; max_attempts::Int = 3) attempt += 1 try # Estimate largest singular value - s, nconv, niter, nmult, resid = svds(J; nsv = nsv, ncv = ncv, ritzvec = false, check = 1) + s, nconv, niter, nmult, resid = + svds(J; nsv = nsv, ncv = ncv, ritzvec = false, check = 1) # Check if singular value has converged have_svd = nconv >= 1 @@ -102,10 +103,10 @@ LinearAlgebra.diag(op::SpectralGradient{T}) where {T} = zeros(T, op.nrow) .* op. """ GenericExecutionStats(reg_nlp :: AbstractRegularizedNLPModel{T, V}) -Construct a GenericExecutionStats object from an AbstractRegularizedNLPModel. +Construct a GenericExecutionStats object from an AbstractRegularizedNLPModel. More specifically, construct a GenericExecutionStats on the NLPModel of reg_nlp and add three solver_specific entries namely :smooth_obj, :nonsmooth_obj and :xi. This is useful for reducing the number of allocations when calling solve!(..., reg_nlp, stats) and should be used by default. -Warning: This should *not* be used when adding other solver_specific entries that do not have the current scalar type. +Warning: This should *not* be used when adding other solver_specific entries that do not have the current scalar type. """ function RegularizedExecutionStats(reg_nlp::AbstractRegularizedNLPModel{T, V}) where {T, V} stats = GenericExecutionStats(reg_nlp.model, solver_specific = Dict{Symbol, T}()) diff --git a/test/Project.toml b/test/Project.toml new file mode 100644 index 00000000..edb4d150 --- /dev/null +++ b/test/Project.toml @@ -0,0 +1,13 @@ +[deps] +ADNLPModels = "54578032-b7ea-4c30-94aa-7cbd1cce6c9a" +JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b" +LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" +NLPModels = "a4795742-8479-5a88-8948-cc11e1c8c1a6" +NLPModelsModifiers = "e01155f1-5c6f-4375-a9d8-616dd036575f" +OptimizationProblems = "5049e819-d29b-5fba-b941-0eee7e64c1c6" +ProximalOperators = "a725b495-10eb-56fe-b38b-717eba820537" +Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" +RegularizedProblems = "ea076b23-609f-44d2-bb12-a4ae45328278" +SolverCore = "ff4d7338-4cf1-434d-91df-b86cb86fb843" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" +TestSetExtensions = "98d24dd4-01ad-11ea-1b02-c9a08f80db04" diff --git a/test/bpdn/test-bpdn.jl b/test/bpdn/test-bpdn.jl new file mode 100644 index 00000000..d6bede25 --- /dev/null +++ b/test/bpdn/test-bpdn.jl @@ -0,0 +1,117 @@ +compound = 1 +nz = 10 * compound +bpdn, bpdn_nls, sol = bpdn_model(compound) +bpdn_bounded, bpdn_nls_bounded, sol_bounded = bpdn_model(compound, bounds = true) +λ = norm(grad(bpdn, zeros(bpdn.meta.nvar)), Inf) / 10 +x0 = 10*randn(bpdn.meta.nvar) + +hessian_modifiers = [LSR1Model, LBFGSModel, SpectralGradientModel, DiagonalPSBModel] # TODO: should add exact hessians once we implement hess_op for bpdn +regularizers = [NormL0(λ), NormL1(λ), NormL2(λ), IndBallL0(10 * compound)] +bounded_regularizers = [NormL0(λ), NormL1(λ)] + +@testset "BPDN" verbose=true begin + @testset "NLP" begin + @testset "R2" begin + # Test on unbounded problem + constructor_parameters_set = [NamedTuple(), NamedTuple(), NamedTuple(), NamedTuple(), NamedTuple()] + solve_parameters_set = [(ν = 1.0, atol = 1e-6, rtol = 1e-6, x = x0, verbose = 10), + (ν = 1.0, atol = 1e-6, rtol = 1e-6, x = x0, verbose = 10, max_iter = 1,), + (ν = 1.0, atol = 1e-6, rtol = 1e-6, x = x0, verbose = 10, max_time = -1.0,), + (ν = 1.0, atol = 1e-6, rtol = 1e-6, x = x0, verbose = 10, max_eval = 2,), + (ν = 1.0, atol = 1e-6, rtol = 1e-6, x = x0, verbose = 10, callback = basic_callback,)] + expected_output = [:first_order, :max_iter, :max_time, :max_eval, :user] + for h in regularizers + reg_nlp = RegularizedNLPModel(bpdn, h) + @testset "R2-unbounded-$(typeof(h))" begin + for (solver_kwargs, constructor_kwargs, expected_output) in zip(solve_parameters_set, constructor_parameters_set, expected_output) + test_solver_basic(reg_nlp, :R2; expected_output = expected_output, constructor_kwargs = constructor_kwargs, solver_kwargs = solver_kwargs) + end + end + end + + # Test on bounded problem + for h in bounded_regularizers + reg_nlp = RegularizedNLPModel(bpdn_bounded, h) + @testset "R2-bounded-$(typeof(h))" begin + for (solver_kwargs, constructor_kwargs, expected_output) in zip(solve_parameters_set, constructor_parameters_set, expected_output) + test_solver_basic(reg_nlp, :R2; expected_output = expected_output, constructor_kwargs = constructor_kwargs, solver_kwargs = solver_kwargs) + end + end + end + end + + @testset "R2N" begin + # Test on unbounded problem + constructor_parameters_set = [NamedTuple(), (subsolver = R2DHSolver,)] + solve_parameters_set = [(σk = 1.0, atol = 1e-6, rtol = 1e-6, x = x0, verbose = 10), + (σk = 1.0, atol = 1e-6, rtol = 1e-6, x = x0, verbose = 10, max_iter = 1,), + (σk = 1.0, atol = 1e-6, rtol = 1e-6, x = x0, verbose = 10, max_time = -1.0,), + (σk = 1.0, atol = 1e-6, rtol = 1e-6, x = x0, verbose = 10, max_eval = 2,), + (σk = 1.0, atol = 1e-6, rtol = 1e-6, x = x0, verbose = 10, callback = basic_callback,)] + expected_output = [:first_order, :max_iter, :max_time, :max_eval, :user] + for modifier in hessian_modifiers + for h in regularizers + reg_nlp = RegularizedNLPModel(modifier(bpdn), h) + @testset "R2N-unbounded-$modifier-$(typeof(h))" begin + for constructor_kwargs in constructor_parameters_set + for (solver_kwargs, expected_output) in zip(solve_parameters_set, expected_output) + test_solver_basic(reg_nlp, :R2N; expected_output = expected_output, constructor_kwargs = constructor_kwargs, solver_kwargs = solver_kwargs) + end + end + end + end + end + + # Test on bounded problem + for modifier in hessian_modifiers + for h in bounded_regularizers + reg_nlp = RegularizedNLPModel(bpdn_bounded, h) + @testset "R2N-bounded-$modifier-$(typeof(h))" begin + for constructor_kwargs in constructor_parameters_set + for (solver_kwargs, expected_output) in zip(solve_parameters_set, expected_output) + test_solver_basic(reg_nlp, :R2N; expected_output = expected_output, constructor_kwargs = constructor_kwargs, solver_kwargs = solver_kwargs) + end + end + end + end + end + end + + @testset "TR" begin + # Test on unbounded problem + constructor_parameters_set = [NamedTuple(), (subsolver = TRDHSolver,)] + solve_parameters_set = [(Δk = 1.0, atol = 1e-6, rtol = 1e-6, x = x0, verbose = 10), + (Δk = 1.0, atol = 1e-6, rtol = 1e-6, x = x0, verbose = 10, max_iter = 1,), + (Δk = 1.0, atol = 1e-6, rtol = 1e-6, x = x0, verbose = 10, max_time = -1.0,), + (Δk = 1.0, atol = 1e-6, rtol = 1e-6, x = x0, verbose = 10, max_eval = 2,), + (Δk = 1.0, atol = 1e-6, rtol = 1e-6, x = x0, verbose = 10, callback = basic_callback,)] + expected_output = [:first_order, :max_iter, :max_time, :max_eval, :user] + for modifier in hessian_modifiers + for h in regularizers + reg_nlp = RegularizedNLPModel(modifier(bpdn), h) + @testset "TR-unbounded-$modifier-$(typeof(h))" begin + for constructor_kwargs in constructor_parameters_set + for (solver_kwargs, expected_output) in zip(solve_parameters_set, expected_output) + test_solver_basic(reg_nlp, :TR; expected_output = expected_output, constructor_kwargs = constructor_kwargs, solver_kwargs = solver_kwargs) + end + end + end + end + end + + # Test on bounded problem + for modifier in hessian_modifiers + for h in bounded_regularizers + reg_nlp = RegularizedNLPModel(bpdn_bounded, h) + @testset "R2N-bounded-$modifier-$(typeof(h))" begin + for constructor_kwargs in constructor_parameters_set + for (solver_kwargs, expected_output) in zip(solve_parameters_set, expected_output) + test_solver_basic(reg_nlp, :TR; expected_output = expected_output, constructor_kwargs = constructor_kwargs, solver_kwargs = solver_kwargs) + end + end + end + end + end + end + end +end \ No newline at end of file diff --git a/test/callbacks.jl b/test/callbacks.jl new file mode 100644 index 00000000..c7dd7dd9 --- /dev/null +++ b/test/callbacks.jl @@ -0,0 +1,5 @@ +basic_callback = (solver, reg_nlp, stats) -> begin + stats.status = :user +end + +##TODO : add more callbacks here to allow for more intricate tests \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index 62dfbaed..05f097af 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,5 +1,4 @@ -using LinearAlgebra: length -using LinearAlgebra, Random, Test +using JET, LinearAlgebra, Random, Test using ProximalOperators using ADNLPModels, OptimizationProblems, @@ -10,139 +9,12 @@ using ADNLPModels, RegularizedOptimization, SolverCore -const global compound = 1 -const global nz = 10 * compound -const global options = ROSolverOptions(ν = 1.0, β = 1e16, ϵa = 1e-6, ϵr = 1e-6, verbose = 10) -const global bpdn, bpdn_nls, sol = bpdn_model(compound) -const global bpdn2, bpdn_nls2, sol2 = bpdn_model(compound, bounds = true) -const global λ = norm(grad(bpdn, zeros(bpdn.meta.nvar)), Inf) / 10 +Random.seed!(0) +include("utils.jl") +include("callbacks.jl") -include("test_AL.jl") +include("test-AL.jl") -for (mod, mod_name) ∈ ((x -> x, "exact"), (LSR1Model, "lsr1"), (LBFGSModel, "lbfgs")) - for (h, h_name) ∈ ((NormL0(λ), "l0"), (NormL1(λ), "l1"), (IndBallL0(10 * compound), "B0")) - for solver_sym ∈ (:R2, :TR) - solver_sym == :TR && mod_name == "exact" && continue - solver_sym == :TR && h_name == "B0" && continue # FIXME - solver_name = string(solver_sym) - solver = eval(solver_sym) - @testset "bpdn-$(mod_name)-$(solver_name)-$(h_name)" begin - x0 = zeros(bpdn.meta.nvar) - p = randperm(bpdn.meta.nvar)[1:nz] - x0[p[1:nz]] = sign.(randn(nz)) # initial guess with nz nonzeros (necessary for h = B0) - args = solver_sym == :R2 ? () : (NormLinf(1.0),) - out = solver(mod(bpdn), h, args..., options, x0 = x0) - @test typeof(out.solution) == typeof(bpdn.meta.x0) - @test length(out.solution) == bpdn.meta.nvar - @test typeof(out.dual_feas) == eltype(out.solution) - @test out.status == :first_order - end - end - end -end - -for (mod, mod_name) ∈ ((SpectralGradientModel, "spg"),) - # ((DiagonalPSBModel, "psb"),(DiagonalAndreiModel, "andrei")) work but do not always terminate - for (h, h_name) ∈ ((NormL0(λ), "l0"), (NormL1(λ), "l1")) #, (IndBallL0(10 * compound), "B0")) - @testset "bpdn-$(mod_name)-TRDH-$(h_name)" begin - x0 = zeros(bpdn.meta.nvar) - p = randperm(bpdn.meta.nvar)[1:nz] - # x0[p[1:nz]] = sign.(randn(nz)) # initial guess with nz nonzeros (necessary for h = B0) - χ = NormLinf(1.0) - out = TRDH(mod(bpdn), h, χ, options, x0 = x0) - @test typeof(out.solution) == typeof(bpdn.meta.x0) - @test length(out.solution) == bpdn.meta.nvar - @test typeof(out.dual_feas) == eltype(out.solution) - @test out.status == :first_order - end - end -end - -# TR with h = L1 and χ = L2 is a special case -for (mod, mod_name) ∈ ((LSR1Model, "lsr1"), (LBFGSModel, "lbfgs")) - for (h, h_name) ∈ ((NormL1(λ), "l1"),) - @testset "bpdn-$(mod_name)-TR-$(h_name)" begin - x0 = zeros(bpdn.meta.nvar) - p = randperm(bpdn.meta.nvar)[1:nz] - x0[p[1:nz]] = sign.(randn(nz)) # initial guess with nz nonzeros (necessary for h = B0) - TR_out = TR(mod(bpdn), h, NormL2(1.0), options, x0 = x0) - @test typeof(TR_out.solution) == typeof(bpdn.meta.x0) - @test length(TR_out.solution) == bpdn.meta.nvar - @test typeof(TR_out.dual_feas) == eltype(TR_out.solution) - @test TR_out.status == :first_order - end - end -end - -for (h, h_name) ∈ ((NormL0(λ), "l0"), (NormL1(λ), "l1"), (IndBallL0(10 * compound), "B0")) - for solver_sym ∈ (:LM, :LMTR) - solver_name = string(solver_sym) - solver = eval(solver_sym) - solver_sym == :LMTR && h_name == "B0" && continue # FIXME - @testset "bpdn-ls-$(solver_name)-$(h_name)" begin - x0 = zeros(bpdn_nls.meta.nvar) - p = randperm(bpdn_nls.meta.nvar)[1:nz] - x0[p[1:nz]] = sign.(randn(nz)) # initial guess with nz nonzeros (necessary for h = B0) - args = solver_sym == :LM ? () : (NormLinf(1.0),) - out = solver(bpdn_nls, h, args..., options, x0 = x0) - @test typeof(out.solution) == typeof(bpdn.meta.x0) - @test length(out.solution) == bpdn.meta.nvar - @test typeof(out.dual_feas) == eltype(out.solution) - @test out.status == :first_order - end - end -end - -# LMTR with h = L1 and χ = L2 is a special case -for (h, h_name) ∈ ((NormL1(λ), "l1"),) - @testset "bpdn-ls-LMTR-$(h_name)" begin - x0 = zeros(bpdn_nls.meta.nvar) - p = randperm(bpdn_nls.meta.nvar)[1:nz] - x0[p[1:nz]] = sign.(randn(nz)) # initial guess with nz nonzeros (necessary for h = B0) - LMTR_out = LMTR(bpdn_nls, h, NormL2(1.0), options, x0 = x0) - @test typeof(LMTR_out.solution) == typeof(bpdn_nls.meta.x0) - @test length(LMTR_out.solution) == bpdn_nls.meta.nvar - @test typeof(LMTR_out.solver_specific[:Fhist]) == typeof(LMTR_out.solution) - @test typeof(LMTR_out.solver_specific[:Hhist]) == typeof(LMTR_out.solution) - @test typeof(LMTR_out.solver_specific[:SubsolverCounter]) == Array{Int, 1} - @test typeof(LMTR_out.dual_feas) == eltype(LMTR_out.solution) - @test length(LMTR_out.solver_specific[:Fhist]) == length(LMTR_out.solver_specific[:Hhist]) - @test length(LMTR_out.solver_specific[:Fhist]) == - length(LMTR_out.solver_specific[:SubsolverCounter]) - @test length(LMTR_out.solver_specific[:Fhist]) == length(LMTR_out.solver_specific[:NLSGradHist]) - @test LMTR_out.solver_specific[:NLSGradHist][end] == - bpdn_nls.counters.neval_jprod_residual + bpdn_nls.counters.neval_jtprod_residual - 1 - @test obj(bpdn_nls, LMTR_out.solution) == LMTR_out.solver_specific[:Fhist][end] - @test h(LMTR_out.solution) == LMTR_out.solver_specific[:Hhist][end] - @test LMTR_out.status == :first_order - end -end - -R2N_R2DH(args...; kwargs...) = R2N(args...; subsolver = R2DHSolver, kwargs...) -for (mod, mod_name) ∈ ( - (SpectralGradientModel, "spg"), - (DiagonalPSBModel, "psb"), - (LSR1Model, "lsr1"), - (LBFGSModel, "lbfgs"), -) - for (h, h_name) ∈ ((NormL0(λ), "l0"), (NormL1(λ), "l1")) - for solver_sym ∈ (:R2DH, :R2N, :R2N_R2DH) - solver_sym ∈ (:R2N, :R2N_R2DH) && mod_name ∈ ("spg", "psb") && continue - solver_sym == :R2DH && mod_name != "spg" && continue - solver_sym == :R2N_R2DH && h_name == "l1" && continue # this test seems to fail because s seems to be equal to zeros within the subsolver - solver_name = string(solver_sym) - solver = eval(solver_sym) - @testset "bpdn-$(mod_name)-$(solver_name)-$(h_name)" begin - x0 = zeros(bpdn.meta.nvar) - out = solver(mod(bpdn), h, options, x0 = x0) - @test typeof(out.solution) == typeof(bpdn.meta.x0) - @test length(out.solution) == bpdn.meta.nvar - @test typeof(out.dual_feas) == eltype(out.solution) - @test out.status == :first_order - end - end - end -end - -include("test_bounds.jl") -include("test_allocs.jl") +include("bpdn/test-bpdn.jl") +include("bpdn/test-bpdn-bounds.jl") +include("bpdn/test-bpdn-allocs.jl") diff --git a/test/test_AL.jl b/test/test-AL.jl similarity index 64% rename from test/test_AL.jl rename to test/test-AL.jl index afe3ba41..acedcf6c 100644 --- a/test/test_AL.jl +++ b/test/test-AL.jl @@ -11,7 +11,12 @@ problem_list = [:hs8] @test stats.dual_feas <= 1e-2 @test length(stats.solution) == nlp.meta.nvar @test typeof(stats.solution) == typeof(nlp.meta.x0) + + # Test allocations + reg_nlp = RegularizedNLPModel(hs8(backend = :generic), h) + solver = ALSolver(reg_nlp) + stats = RegularizedExecutionStats(reg_nlp) + #@test @wrappedallocs(solve!(solver, reg_nlp, stats, atol = 1e-3)) == 0 #FIXME end - finalize(nlp) end end diff --git a/test/test_allocs.jl b/test/test_allocs.jl deleted file mode 100644 index 10e477ea..00000000 --- a/test/test_allocs.jl +++ /dev/null @@ -1,93 +0,0 @@ -""" - @wrappedallocs(expr) - -Given an expression, this macro wraps that expression inside a new function -which will evaluate that expression and measure the amount of memory allocated -by the expression. Wrapping the expression in a new function allows for more -accurate memory allocation detection when using global variables (e.g. when -at the REPL). - -This code is based on that of https://github.com/JuliaAlgebra/TypedPolynomials.jl/blob/master/test/runtests.jl - -For example, `@wrappedallocs(x + y)` produces: - -```julia -function g(x1, x2) - @allocated x1 + x2 -end -g(x, y) -``` - -You can use this macro in a unit test to verify that a function does not -allocate: - -``` -@test @wrappedallocs(x + y) == 0 -``` -""" -macro wrappedallocs(expr) - kwargs = [a for a in expr.args if isa(a, Expr)] - args = [a for a in expr.args if isa(a, Symbol)] - - argnames = [gensym() for a in args] - kwargs_dict = Dict{Symbol, Any}(a.args[1] => a.args[2] for a in kwargs if a.head == :kw) - quote - function g($(argnames...); kwargs_dict...) - @allocated $(Expr(expr.head, argnames..., kwargs...)) - end - $(Expr(:call, :g, [esc(a) for a in args]...)) - end -end - -# Test non allocating solve! -@testset "NLP allocs" begin - for (h, h_name) ∈ ((NormL0(λ), "l0"),) - for (solver, solver_name) ∈ ( - (:R2Solver, "R2"), - (:R2DHSolver, "R2DH"), - (:R2NSolver, "R2N"), - (:TRDHSolver, "TRDH"), - (:TRSolver, "TR"), - ) - @testset "$(solver_name)" begin - (solver_name == "R2N" || solver_name == "TR") && continue #FIXME - reg_nlp = RegularizedNLPModel(LBFGSModel(bpdn), h) - solver = eval(solver)(reg_nlp) - stats = RegularizedExecutionStats(reg_nlp) - solver_name == "R2" && - @test @wrappedallocs(solve!(solver, reg_nlp, stats, ν = 1.0, atol = 1e-6, rtol = 1e-6)) == - 0 - solver_name == "R2DH" && @test @wrappedallocs( - solve!(solver, reg_nlp, stats, σk = 1.0, atol = 1e-6, rtol = 1e-6) - ) == 0 - solver_name == "TRDH" && - @test @wrappedallocs(solve!(solver, reg_nlp, stats, atol = 1e-6, rtol = 1e-6)) == 0 - @test stats.status == :first_order - end - end - @testset "Augmented Lagrangian" begin - continue # FIXME : fails due to type instabilities in ADNLPModels... - reg_nlp = RegularizedNLPModel(hs8(backend = :generic), h) - solver = ALSolver(reg_nlp) - stats = RegularizedExecutionStats(reg_nlp) - @test @wrappedallocs(solve!(solver, reg_nlp, stats, atol = 1e-3)) == 0 - @test stats.status == :first_order - end - end -end - -@testset "NLS allocs" begin - for (h, h_name) ∈ ((NormL0(λ), "l0"),) - for (solver, solver_name) ∈ ((:LMSolver, "LM"),) - @testset "$(solver_name)" begin - solver_name == "LM" && continue #FIXME - reg_nlp = RegularizedNLPModel(bpdn_nls, h) - solver = eval(solver)(reg_nlp) - stats = RegularizedExecutionStats(reg_nlp) - @test @wrappedallocs(solve!(solver, reg_nlp, stats, σk = 1.0, atol = 1e-6, rtol = 1e-6)) == - 0 - @test stats.status == :first_order - end - end - end -end diff --git a/test/test_bounds.jl b/test/test_bounds.jl deleted file mode 100644 index 110546a2..00000000 --- a/test/test_bounds.jl +++ /dev/null @@ -1,101 +0,0 @@ -const subsolver_options = deepcopy(options) -TR_TRDH(args...; kwargs...) = TR(args...; subsolver = TRDHSolver, kwargs...) - -for (mod, mod_name) ∈ ((x -> x, "exact"), (LSR1Model, "lsr1"), (LBFGSModel, "lbfgs")) - for (h, h_name) ∈ ((NormL0(λ), "l0"), (NormL1(λ), "l1")) - for solver_sym ∈ (:TR, :R2, :TR_TRDH) - solver_sym ∈ (:TR, :TR_TRDH) && mod_name == "exact" && continue - solver_name = string(solver_sym) - solver = eval(solver_sym) - @testset "bpdn-with-bounds-$(mod_name)-$(solver_name)-$(h_name)" begin - x0 = zeros(bpdn2.meta.nvar) - p = randperm(bpdn2.meta.nvar)[1:nz] - args = solver_sym == :R2 ? () : (NormLinf(1.0),) - @test has_bounds(mod(bpdn2)) - out = solver(mod(bpdn2), h, args..., options; x0 = x0) - @test typeof(out.solution) == typeof(bpdn2.meta.x0) - @test length(out.solution) == bpdn2.meta.nvar - @test typeof(out.dual_feas) == eltype(out.solution) - @test out.status == :first_order - end - end - end -end - -for (mod, mod_name) ∈ ((SpectralGradientModel, "spg"),) - # ((DiagonalPSBModel, "psb"),(DiagonalAndreiModel, "andrei")) work but do not always terminate - for (h, h_name) ∈ ((NormL0(λ), "l0"), (NormL1(λ), "l1")) - @testset "bpdn-with-bounds-$(mod_name)-TRDH-$(h_name)" begin - x0 = zeros(bpdn2.meta.nvar) - p = randperm(bpdn2.meta.nvar)[1:nz] - χ = NormLinf(1.0) - out = TRDH(mod(bpdn2), h, χ, options; x0 = x0) - @test typeof(out.solution) == typeof(bpdn2.meta.x0) - @test length(out.solution) == bpdn2.meta.nvar - @test typeof(out.dual_feas) == eltype(out.solution) - @test out.status == :first_order - end - end -end - -for (h, h_name) ∈ ((NormL0(λ), "l0"), (NormL1(λ), "l1")) - for solver_sym ∈ (:LMTR, :LM) - solver_name = string(solver_sym) - solver = eval(solver_sym) - @testset "bpdn-with-bounds-ls-$(solver_name)-$(h_name)" begin - x0 = zeros(bpdn_nls2.meta.nvar) - args = solver_sym == :LM ? () : (NormLinf(1.0),) - @test has_bounds(bpdn_nls2) - out = solver(bpdn_nls2, h, args..., options, x0 = x0) - @test typeof(out.solution) == typeof(bpdn.meta.x0) - @test length(out.solution) == bpdn.meta.nvar - @test typeof(out.dual_feas) == eltype(out.solution) - @test out.status == :first_order - end - end -end - -# LMTR with TRDH as subsolver -for (h, h_name) ∈ ((NormL0(λ), "l0"), (NormL1(λ), "l1")) - @testset "bpdn-with-bounds-ls-LMTR-$(h_name)-TRDH" begin - x0 = zeros(bpdn_nls2.meta.nvar) - @test has_bounds(bpdn_nls2) - LMTR_out = LMTR( - bpdn_nls2, - h, - NormLinf(1.0), - options, - x0 = x0, - subsolver = TRDH, - subsolver_options = subsolver_options, - ) - @test typeof(LMTR_out.solution) == typeof(bpdn_nls2.meta.x0) - @test length(LMTR_out.solution) == bpdn_nls2.meta.nvar - @test typeof(LMTR_out.solver_specific[:Fhist]) == typeof(LMTR_out.solution) - @test typeof(LMTR_out.solver_specific[:Hhist]) == typeof(LMTR_out.solution) - @test typeof(LMTR_out.solver_specific[:SubsolverCounter]) == Array{Int, 1} - @test typeof(LMTR_out.dual_feas) == eltype(LMTR_out.solution) - @test length(LMTR_out.solver_specific[:Fhist]) == length(LMTR_out.solver_specific[:Hhist]) - @test length(LMTR_out.solver_specific[:Fhist]) == - length(LMTR_out.solver_specific[:SubsolverCounter]) - @test length(LMTR_out.solver_specific[:Fhist]) == length(LMTR_out.solver_specific[:NLSGradHist]) - @test LMTR_out.solver_specific[:NLSGradHist][end] == - bpdn_nls2.counters.neval_jprod_residual + bpdn_nls2.counters.neval_jtprod_residual - 1 - @test obj(bpdn_nls2, LMTR_out.solution) == LMTR_out.solver_specific[:Fhist][end] - @test h(LMTR_out.solution) == LMTR_out.solver_specific[:Hhist][end] - @test LMTR_out.status == :first_order - end -end - -# LM with R2DH as subsolver -for (h, h_name) ∈ ((NormL0(λ), "l0"),) - @testset "bpdn-with-bounds-ls-LM-$(h_name)-R2DH" begin - x0 = zeros(bpdn_nls2.meta.nvar) - @test has_bounds(bpdn_nls2) - LM_out = LM(bpdn_nls2, h, options, x0 = x0, subsolver = R2DHSolver)#, subsolver_options = subsolver_options) - @test typeof(LM_out.solution) == typeof(bpdn.meta.x0) - @test length(LM_out.solution) == bpdn.meta.nvar - @test typeof(LM_out.dual_feas) == eltype(LM_out.solution) - @test LM_out.status == :first_order - end -end diff --git a/test/utils.jl b/test/utils.jl new file mode 100644 index 00000000..5617f4e4 --- /dev/null +++ b/test/utils.jl @@ -0,0 +1,90 @@ +""" + @wrappedallocs(expr) + +Given an expression, this macro wraps that expression inside a new function +which will evaluate that expression and measure the amount of memory allocated +by the expression. Wrapping the expression in a new function allows for more +accurate memory allocation detection when using global variables (e.g. when +at the REPL). + +This code is based on that of https://github.com/JuliaAlgebra/TypedPolynomials.jl/blob/master/test/runtests.jl + +For example, `@wrappedallocs(x + y)` produces: + +```julia +function g(x1, x2) + @allocated x1 + x2 +end +g(x, y) +``` + +You can use this macro in a unit test to verify that a function does not +allocate: + +``` +@test @wrappedallocs(x + y) == 0 +``` +""" +macro wrappedallocs(expr) + kwargs = [a for a in expr.args if isa(a, Expr)] + args = [a for a in expr.args if isa(a, Symbol)] + + argnames = [gensym() for a in args] + kwargs_dict = Dict{Symbol, Any}(a.args[1] => a.args[2] for a in kwargs if a.head == :kw) + quote + function g($(argnames...); kwargs_dict...) + @allocated $(Expr(expr.head, argnames..., kwargs...)) + end + $(Expr(:call, :g, [esc(a) for a in args]...)) + end +end + +function test_solver_basic(reg_nlp::AbstractRegularizedNLPModel, solver_sym::Symbol; expected_output = :first_order, constructor_kwargs = NamedTuple(), solver_kwargs = NamedTuple()) + + # Test calling with a regularized NLP + solver = eval(solver_sym) + reset!(reg_nlp.model) + out1 = solver(reg_nlp; merge(constructor_kwargs, solver_kwargs)...) + @test typeof(out1.solution) == typeof(reg_nlp.model.meta.x0) + @test length(out1.solution) == reg_nlp.model.meta.nvar + @test typeof(out1.dual_feas) == eltype(out1.solution) + @test out1.status == expected_output + + if expected_output == :max_eval + @test neval_obj(reg_nlp.model) == solver_kwargs[:max_eval] + 1 + end + + if expected_output == :max_iter + @test out1.iter == solver_kwargs[:max_iter] + 1 + end + + # Test calling with solve! + solver_constructor = eval(Symbol(string(solver_sym), "Solver")) + workspace = solver_constructor(reg_nlp; constructor_kwargs...) + out2 = RegularizedExecutionStats(reg_nlp) + + solve!(workspace, reg_nlp, out2; solver_kwargs...) + @test typeof(out2.solution) == typeof(reg_nlp.model.meta.x0) + @test length(out2.solution) == reg_nlp.model.meta.nvar + @test typeof(out2.dual_feas) == eltype(out2.solution) + @test out2.status == expected_output + + # Test that both methods gave the same solution + if expected_output == :first_order # Else there are issues with uninitialized values + @test out2.solution == out1.solution + @test out2.iter == out1.iter + @test out2.dual_feas == out1.dual_feas + @test out2.solver_specific[:smooth_obj] == out1.solver_specific[:smooth_obj] + @test out2.solver_specific[:nonsmooth_obj] == out1.solver_specific[:nonsmooth_obj] + end + + # In case the problem has bounds, check feasibility + if has_bounds(reg_nlp.model) && expected_output == :first_order + l_bound, u_bound = reg_nlp.model.meta.lvar, reg_nlp.model.meta.uvar + @test all(out2.solution .>= l_bound) + @test all(out2.solution .<= u_bound) + end + + # Test Type stability + @test_opt target_modules=(RegularizedOptimization,) function_filter=(@nospecialize(f)->(f!=LinearAlgebra.opnorm)) solve!(workspace, reg_nlp, out2; solver_kwargs...) +end \ No newline at end of file