diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..3c23d69 --- /dev/null +++ b/.clang-format @@ -0,0 +1,4 @@ +BasedOnStyle: LLVM +IncludeBlocks: Regroup +PointerAlignment: Left +Standard: c++17 diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..7be7a6f --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,70 @@ +FormatStyle: file + +Checks: | + bugprone-*, + -bugprone-easily-swappable-parameters, + -bugprone-unchecked-optional-access, + clang-analyzer-*, + -clang-analyzer-core.NullDereference, + clang-diagnostic-*, + cppcoreguidelines-*, + -cppcoreguidelines-non-private-member-variables-in-classes, + -cppcoreguidelines-special-member-functions, + -cppcoreguidelines-avoid-magic-numbers, + -cppcoreguidelines-macro-usage, + google-*, + -google-readability-todo, + -google-build-using-namespace, + misc-*, + -misc-no-recursion, + -misc-non-private-member-variables-in-classes, + modernize-*, + -modernize-use-trailing-return-type, + performance-*, + portability-*, + readability-*, + -readability-identifier-length, + -readability-magic-numbers, + -readability-function-cognitive-complexity + +CheckOptions: + - key: readability-identifier-naming.ClassCase + value: CamelCase + - key: readability-identifier-naming.ClassIgnoredRegexp + value: ".*ZX.*|.*SWAP.*|.*CEX.*|.*DD.*|.*EQ.*" + - key: readability-identifier-naming.ConstantParameterCase + value: camelBack + - key: readability-identifier-naming.EnumCase + value: CamelCase + - key: readability-identifier-naming.EnumConstantCase + value: CamelCase + - key: readability-identifier-naming.FunctionCase + value: camelBack + - key: readability-identifier-naming.FunctionIgnoredRegexp + value: ".*ZX.*|.*SWAP.*|.*CEX.*|.*DD.*|.*EQ.*" + - key: readability-identifier-naming.GlobalConstantCase + value: UPPER_CASE + - key: readability-identifier-naming.IgnoreMainLikeFunctions + value: "true" + - key: readability-identifier-naming.LocalConstantCase + value: camelBack + - key: readability-identifier-naming.LocalVariableCase + value: camelBack + - key: readability-identifier-naming.MemberCase + value: camelBack + - key: readability-identifier-naming.MemberIgnoredRegexp + value: ".*ZX.*|.*SWAP.*|.*CEX.*|.*DD.*|.*EQ.*" + - key: readability-identifier-naming.MethodCase + value: camelBack + - key: readability-identifier-naming.ParameterCase + value: camelBack + - key: readability-identifier-naming.ParameterIgnoredRegexp + value: ".*ZX.*|.*SWAP.*|.*CEX.*|.*DD.*|.*EQ.*" + - key: readability-identifier-naming.NamespaceCase + value: lower_case + - key: readability-identifier-naming.StaticConstantCase + value: UPPER_CASE + - key: readability-identifier-naming.StructCase + value: CamelCase + - key: readability-identifier-naming.VariableCase + value: camelBack diff --git a/.cmake-format.yaml b/.cmake-format.yaml new file mode 100644 index 0000000..80b8381 --- /dev/null +++ b/.cmake-format.yaml @@ -0,0 +1,7 @@ +format: + line_width: 100 + keyword_case: "upper" + autosort: true + +markup: + first_comment_is_literal: true diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..1c8510e --- /dev/null +++ b/.editorconfig @@ -0,0 +1,18 @@ +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.{py,pyi}] +indent_size = 4 + +[*.md] +trim_trailing_whitespace = false + +[{*.{cmake,cmake.in},CMakeLists.txt}] +max_line_length = 100 diff --git a/.git_archival.txt b/.git_archival.txt new file mode 100644 index 0000000..7c51009 --- /dev/null +++ b/.git_archival.txt @@ -0,0 +1,3 @@ +node: $Format:%H$ +node-date: $Format:%cI$ +describe-name: $Format:%(describe:tags=true,match=*[0-9]*)$ diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..00a7b00 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +.git_archival.txt export-subst diff --git a/.license-tools-config.json b/.license-tools-config.json new file mode 100644 index 0000000..ef69625 --- /dev/null +++ b/.license-tools-config.json @@ -0,0 +1,44 @@ +{ + "author": { + "name": "MQSS Project", + "years": [2024, 2026] + }, + "force_author": true, + "custom_license": "Licensed under the Apache License v2.0 with LLVM Exceptions (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\nhttps://llvm.org/LICENSE.txt\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\nLicense for the specific language governing permissions and limitations under the License.\n\nSPDX-License-Identifier: Apache-2.0 WITH LLVM-exception", + "force_license": true, + "title": false, + "include": ["**/*"], + "style_override_for_suffix": { + ".pyi": "DOCSTRING_STYLE", + ".in": "POUND_STYLE", + ".mlir": "SLASH_STYLE", + ".td": "SLASH_STYLE", + ".yaml": "POUND_STYLE", + ".toml": "POUND_STYLE", + ".proto": "SLASH_STYLE", + ".ts": "C_STYLE", + ".css": "C_STYLE", + ".ps1": "POUND_STYLE" + }, + "exclude": [ + "^\\.[^/]+", + "/\\.[^/]+", + ".*\\.qasm", + ".*\\.ll", + ".*\\.md", + ".*\\.bib", + ".*\\.cff", + ".*\\.json", + ".*\\.html", + ".*\\.tfc", + ".*\\.qc", + ".*\\.real", + ".*\\.tex", + "uv\\.lock", + "py\\.typed", + "Dockerfile", + "prefix_defs.txt", + "test_defs.cpp.in", + "LICENSE" + ] +} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e5e41f9..639f900 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,23 @@ +# To run all pre-commit checks, use: +# +# pre-commit run -a +# +# To install pre-commit hooks that run every time you commit: +# +# pre-commit install +# + +ci: + autoupdate_commit_msg: "⬆️🪝 update pre-commit hooks" + autoupdate_schedule: quarterly + autofix_commit_msg: "🎨 pre-commit fixes" + +exclude: \.svg$ + repos: # Standard hooks - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v5.0.0 + rev: v6.0.0 hooks: - id: check-added-large-files - id: check-case-conflict @@ -18,7 +34,7 @@ repos: # Handling unwanted unicode characters - repo: https://github.com/sirosen/texthooks - rev: 0.6.8 + rev: 0.7.1 hooks: - id: fix-ligatures - id: fix-smartquotes @@ -31,32 +47,54 @@ repos: - id: rst-directive-colons - id: rst-inline-touching-normal + # Check for license headers + - repo: https://github.com/emzeat/mz-lictools + rev: v2.9.0 + hooks: + - id: license-tools + # Check for spelling - repo: https://github.com/crate-ci/typos - rev: v1.29.4 + rev: v1.46.3 hooks: - id: typos + # Clang-format the C++ part of the code base automatically + - repo: https://github.com/pre-commit/mirrors-clang-format + rev: v22.1.5 + hooks: + - id: clang-format + types_or: [c++, c, cuda] + + # CMake format the CMakeLists.txt files + - repo: https://github.com/cheshirekow/cmake-format-precommit + rev: v0.6.13 + hooks: + - id: cmake-format + additional_dependencies: [pyyaml] + types: [file] + files: (\.cmake|CMakeLists.txt)(.in)?$ + # Format configuration files with prettier - repo: https://github.com/rbubley/mirrors-prettier - rev: v3.4.2 + rev: v3.8.3 hooks: - id: prettier types_or: [yaml, markdown, html, css, scss, javascript, json] - args: - - --print-width=100 - - --prose-wrap=always - - --tab-width=2 - exclude: ^docs/header\.html$ - - - repo: https://github.com/astral-sh/ruff-pre-commit - # Ruff version. - rev: v0.9.6 - hooks: - # Run the linter. - - id: ruff - types_or: [python, pyi] - args: [--fix] - # Run the formatter. - - id: ruff-format - types_or: [python, pyi] + exclude: docs/header\.html$ + + # Catch common capitalization mistakes + - repo: local + hooks: + - id: disallow-caps + name: Disallow improper capitalization + language: pygrep + entry: PyBind|Numpy|Cmake|CCache|Github|PyTest + exclude: .pre-commit-config.yaml + + # Check JSON schemata + - repo: https://github.com/python-jsonschema/check-jsonschema + rev: 0.37.2 + hooks: + - id: check-dependabot + - id: check-github-workflows diff --git a/CMakeLists.txt b/CMakeLists.txt index 360ed08..91aeb33 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,11 @@ -# ------------------------------------------------------------------------------ -# Copyright 2024 Munich Quantum Software Stack Project +# Copyright (c) 2024 - 2026 MQSS Project +# All rights reserved. # -# Licensed under the Apache License, Version 2.0 with LLVM Exceptions (the -# "License"); you may not use this file except in compliance with the License. +# Licensed under the Apache License v2.0 with LLVM Exceptions (the "License"); +# you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# https://github.com/Munich-Quantum-Software-Stack/QDMI-Devices/blob/develop/LICENSE +# https://llvm.org/LICENSE.txt # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT @@ -14,7 +14,6 @@ # the License. # # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# ------------------------------------------------------------------------------ # set required cmake version cmake_minimum_required(VERSION 3.19...3.30) @@ -25,8 +24,7 @@ project( DESCRIPTION "MQSS Client" LANGUAGES CXX) -# Generate compile_commands.json to make it easier to work with clang based -# tools +# Generate compile_commands.json to make it easier to work with clang based tools set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE BOOL "Export compile commands" FORCE) @@ -41,7 +39,6 @@ if(ENABLE_COVERAGE) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage -O0 -g") endif() - set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD_REQUIRED True) set(CMAKE_C_EXTENSIONS OFF) diff --git a/cmake/ExternalDependencies.cmake b/cmake/ExternalDependencies.cmake index 3c182f6..011d6ac 100644 --- a/cmake/ExternalDependencies.cmake +++ b/cmake/ExternalDependencies.cmake @@ -1,11 +1,27 @@ +# Copyright (c) 2024 - 2026 MQSS Project +# All rights reserved. +# +# Licensed under the Apache License v2.0 with LLVM Exceptions (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://llvm.org/LICENSE.txt +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. +# +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + include(FetchContent) set(FETCH_PACKAGES "") -#if(BUILD_DOCUMENTATION) +if(BUILD_DOCUMENTATION) set(CMAKE_POLICY_DEFAULT_CMP0116 NEW - CACHE STRING - "Set the default CMP0116 policy to NEW for documentation builds") + CACHE STRING "Set the default CMP0116 policy to NEW for documentation builds") set(DOXYGEN_VERSION 1.15.0 CACHE STRING "Doxygen version") @@ -31,7 +47,7 @@ set(FETCH_PACKAGES "") GIT_TAG ${DOXYGEN_AWESOME_REV} FIND_PACKAGE_ARGS ${DOXYGEN_AWESOME_VERSION}) list(APPEND FETCH_PACKAGES doxygen-awesome-css) -#endif() +endif() if(FETCH_PACKAGES) FetchContent_MakeAvailable(${FETCH_PACKAGES}) diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt index 4774165..dada0b2 100644 --- a/docs/CMakeLists.txt +++ b/docs/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2024 - 2026 QDMI Maintainers +# Copyright (c) 2024 - 2026 MQSS Project # All rights reserved. # # Licensed under the Apache License v2.0 with LLVM Exceptions (the "License"); @@ -15,26 +15,19 @@ # # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# Set the Doxygen configuration file. In the Doxyfile.in file, there are some -# placeholders that are replaced by CMake. That is also the reason for the -# extension `.in`. For details see below for the command `configure_file`. +# Set the Doxygen configuration file. In the Doxyfile.in file, there are some placeholders that are +# replaced by CMake. That is also the reason for the extension `.in`. For details see below for the +# command `configure_file`. set(DOXYGEN_CONFIG_FILE_IN ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in) - - -# This variable is only needed to setup the dependency tracking of CMake -# correctly and is not passed to Doxygen. Whenever such a file is modified, -# CMake detects that change and will rerun the Doxygen command instead of using -# the cached result when the target `qdmi-docs` is built. -file( - GLOB_RECURSE - DOXYGEN_INPUT_FILES - ${CMAKE_CURRENT_SOURCE_DIR}/*.md - ${PROJECT_SOURCE_DIR}/README.md) -# After the variable above is correctly initialized, we can add the additional -# files that are not source code but still part of the documentation. IMPORTANT: -# The order the files with the static content are added here influences their -# order in the generated documentation. +# This variable is only needed to setup the dependency tracking of CMake correctly and is not passed +# to Doxygen. Whenever such a file is modified, CMake detects that change and will rerun the Doxygen +# command instead of using the cached result when the target `qdmi-docs` is built. +file(GLOB_RECURSE DOXYGEN_INPUT_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.md + ${PROJECT_SOURCE_DIR}/README.md) +# After the variable above is correctly initialized, we can add the additional files that are not +# source code but still part of the documentation. IMPORTANT: The order the files with the static +# content are added here influences their order in the generated documentation. set(DOXYGEN_INPUT_DIRS ${DOXYGEN_INPUT_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/index.md @@ -44,45 +37,40 @@ set(DOXYGEN_INPUT_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/build.md ${CMAKE_CURRENT_SOURCE_DIR}/contributing.md ${CMAKE_CURRENT_SOURCE_DIR}/ai_usage.md) -# By default the files are separated by a semicolon. This is not what Doxygen -# wants, so we replace it with a space. +# By default the files are separated by a semicolon. This is not what Doxygen wants, so we replace +# it with a space. string(REPLACE ";" " " DOXYGEN_INPUT_DIRS "${DOXYGEN_INPUT_DIRS}") -# Such that the content of other files than files listed in DOXYGEN_INPUT_DIRS -# can be included with the `\include`or `\snippet` command, we need to add the -# directories where these files are located. -set(DOXYGEN_EXAMPLE_DIRS - ${PROJECT_SOURCE_DIR}/.github - ${PROJECT_SOURCE_DIR}/README.md) +# Such that the content of other files than files listed in DOXYGEN_INPUT_DIRS can be included with +# the `\include`or `\snippet` command, we need to add the directories where these files are located. +set(DOXYGEN_EXAMPLE_DIRS ${PROJECT_SOURCE_DIR}/.github ${PROJECT_SOURCE_DIR}/README.md) # Again, replace the semicolon with a space such that Doxygen can handle it. string(REPLACE ";" " " DOXYGEN_EXAMPLE_DIRS "${DOXYGEN_EXAMPLE_DIRS}") -# Set the output directory for the generated documentation: Place it in the -# CMake build directory. +# Set the output directory for the generated documentation: Place it in the CMake build directory. set(DOXYGEN_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}) -# Set the Doxygen configured configuration file. This will point to the Doxyfile -# that is written out by CMake with all placeholders substituted. +# Set the Doxygen configured configuration file. This will point to the Doxyfile that is written out +# by CMake with all placeholders substituted. set(DOXYGEN_CONFIG_FILE_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile) -# Save the location the files of the project doxygen-awesome-css were cloned -# into. This allows us to get the path to doxygen-awesome.css. For its usage -# also see the occurrences of @AWESOME_CSS_DIR@ in the Doxyfile.in. +# Save the location the files of the project doxygen-awesome-css were cloned into. This allows us to +# get the path to doxygen-awesome.css. For its usage also see the occurrences of @AWESOME_CSS_DIR@ +# in the Doxyfile.in. FetchContent_GetProperties(doxygen-awesome-css SOURCE_DIR AWESOME_CSS_DIR) # Ensure the output directory exists file(MAKE_DIRECTORY ${DOXYGEN_OUTPUT_DIR}/html) -# Copy over the dark mode logos as they are not automatically copied by Doxygen. -# `configure_file` is used here because `file(COPY ...)` does not detect changes -# and copies the files again after they have changed. +# Copy over the dark mode logos as they are not automatically copied by Doxygen. `configure_file` is +# used here because `file(COPY ...)` does not detect changes and copies the files again after they +# have changed. configure_file(_static/mqss_logo_dark.svg ${DOXYGEN_OUTPUT_DIR}/html COPYONLY) # Set the logo for the project. set(PROJECT_LOGO "mqss_logo.svg") -# Replace variables inside @@ with the current values, e.g., the placeholder -# @DOXYGEN_INPUT_DIRS@ is replaced by the content of the variable -# DOXYGEN_INPUT_DIRS. +# Replace variables inside @@ with the current values, e.g., the placeholder @DOXYGEN_INPUT_DIRS@ is +# replaced by the content of the variable DOXYGEN_INPUT_DIRS. configure_file(${DOXYGEN_CONFIG_FILE_IN} ${DOXYGEN_CONFIG_FILE_OUT} @ONLY) if(${DOXYGEN_EXECUTABLE} STREQUAL "DOXYGEN_EXECUTABLE-NOTFOUND") diff --git a/docs/Doxyfile.in b/docs/Doxyfile.in index 8cb4c23..25ed8b4 100644 --- a/docs/Doxyfile.in +++ b/docs/Doxyfile.in @@ -1,11 +1,11 @@ -# ------------------------------------------------------------------------------ -# Copyright 2024 Munich Quantum Software Stack Project +# Copyright (c) 2024 - 2026 MQSS Project +# All rights reserved. # -# Licensed under the Apache License, Version 2.0 with LLVM Exceptions (the -# "License"); you may not use this file except in compliance with the License. +# Licensed under the Apache License v2.0 with LLVM Exceptions (the "License"); +# you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# https://github.com/Munich-Quantum-Software-Stack/QDMI/blob/develop/LICENSE +# https://llvm.org/LICENSE.txt # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT @@ -14,7 +14,6 @@ # the License. # # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# ------------------------------------------------------------------------------ # Doxyfile 1.12.0 diff --git a/docs/ai_usage.md b/docs/ai_usage.md index 8a3fdf9..61b7778 100644 --- a/docs/ai_usage.md +++ b/docs/ai_usage.md @@ -133,12 +133,8 @@ Parts of this guide were inspired by or adapted from the contribution guidelines with the help of Gemini 3 Pro (Preview). The links above serve as attribution. [MQT]: https://github.com/munich-quantum-toolkit -[Astral]: - https://github.com/astral-sh/uv/blob/c89a78ec085077f6344b0439ddf07fdad7336310/CONTRIBUTING.md -[Qiskit]: - https://github.com/Qiskit/qiskit/blob/cd8701690723d3d9602fac63fe0bd7ea618799be/CONTRIBUTING.md#use-of-ai-tools -[LLVM]: - https://github.com/llvm/llvm-project/blob/9b6391f9c439c9926e8587b7b940e9a1e98a7819/llvm/docs/AIToolPolicy.md -[fedora]: - https://communityblog.fedoraproject.org/council-policy-proposal-policy-on-ai-assisted-contributions/ +[Astral]: https://github.com/astral-sh/uv/blob/c89a78ec085077f6344b0439ddf07fdad7336310/CONTRIBUTING.md +[Qiskit]: https://github.com/Qiskit/qiskit/blob/cd8701690723d3d9602fac63fe0bd7ea618799be/CONTRIBUTING.md#use-of-ai-tools +[LLVM]: https://github.com/llvm/llvm-project/blob/9b6391f9c439c9926e8587b7b940e9a1e98a7819/llvm/docs/AIToolPolicy.md +[fedora]: https://communityblog.fedoraproject.org/council-policy-proposal-policy-on-ai-assisted-contributions/ [cca]: https://creativecommons.org/licenses/by/4.0/ diff --git a/docs/build.md b/docs/build.md index afbc3b2..6d284cb 100644 --- a/docs/build.md +++ b/docs/build.md @@ -1,23 +1,6 @@ # Build Guide - diff --git a/docs/examples.md b/docs/examples.md index ab445c4..83a021a 100644 --- a/docs/examples.md +++ b/docs/examples.md @@ -2,24 +2,6 @@ - - diff --git a/docs/faq.md b/docs/faq.md index fb6c811..6deb0f5 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -2,24 +2,6 @@ - - diff --git a/docs/header.html b/docs/header.html index e6a957e..3510ae6 100644 --- a/docs/header.html +++ b/docs/header.html @@ -1,20 +1,4 @@ - diff --git a/docs/implementation.md b/docs/implementation.md index 6bdeafa..cf541c3 100644 --- a/docs/implementation.md +++ b/docs/implementation.md @@ -2,24 +2,6 @@ - - diff --git a/docs/index.md b/docs/index.md index a323573..c582303 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,23 +1,6 @@ # MQSS Client {#mainpage} - diff --git a/docs/layout.xml b/docs/layout.xml index 0b14bae..9a58168 100644 --- a/docs/layout.xml +++ b/docs/layout.xml @@ -1,4 +1,22 @@ + diff --git a/docs/style.css b/docs/style.css index 72e2427..1211b5f 100644 --- a/docs/style.css +++ b/docs/style.css @@ -1,20 +1,21 @@ -/*------------------------------------------------------------------------------ -Copyright 2024 Munich Quantum Software Stack Project - -Licensed under the Apache License, Version 2.0 with LLVM Exceptions (the -"License"); you may not use this file except in compliance with the License. -You may obtain a copy of the License at - -https://github.com/Munich-Quantum-Software-Stack/QDMI/blob/develop/LICENSE - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -License for the specific language governing permissions and limitations under -the License. - -SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -------------------------------------------------------------------------------*/ +/* + * Copyright (c) 2024 - 2026 MQSS Project + * All rights reserved. + * + * Licensed under the Apache License v2.0 with LLVM Exceptions (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://llvm.org/LICENSE.txt + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ /* Generated by doxygen 1.12.0 via `doxygen -w header.html footer.html style.css` */ /* Included in the Doxygen.in file under the tag HTML_EXTRA_STYLESHEETS */ diff --git a/include/mqss/client.h b/include/mqss/client.h index 21430e1..b6890bf 100644 --- a/include/mqss/client.h +++ b/include/mqss/client.h @@ -1,16 +1,35 @@ +/* + * Copyright (c) 2024 - 2026 MQSS Project + * All rights reserved. + * + * Licensed under the Apache License v2.0 with LLVM Exceptions (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://llvm.org/LICENSE.txt + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + #pragma once +#include "job.h" +#include "resource.h" + #include #include +#include #include #include #include #include -#include "job.h" -#include "resource.h" -#include - #define MQP_DEFAULT_URL "https://portal.quantum.lrz.de:4000/v1/" namespace mqss::client { @@ -18,34 +37,35 @@ namespace mqss::client { class MQSSBaseClient { public: virtual ~MQSSBaseClient() = default; - virtual std::string get(const std::string &path) = 0; - virtual std::string post(const std::string &path, - const nlohmann::json &data) = 0; - virtual void del(const std::string &path) = 0; + virtual std::string get(const std::string& path) = 0; + virtual std::string post(const std::string& path, + const nlohmann::json& data) = 0; + virtual void del(const std::string& path) = 0; }; class MQSSClient { private: - std::unique_ptr waitForJobResult(const JobRequest &job, size_t poll_seconds); + std::unique_ptr waitForJobResult(const JobRequest& job, + size_t poll_seconds); public: - MQSSClient(const std::string &token = "", - const std::string &url_or_queue = MQP_DEFAULT_URL, + MQSSClient(const std::string& token = "", + const std::string& url_or_queue = MQP_DEFAULT_URL, bool is_hpc = false); // Resources std::vector getAllResources() const; - std::optional getResourceInfo(const std::string &resource) const; + std::optional getResourceInfo(const std::string& resource) const; // Jobs - std::optional submitJob(JobRequest &job); - void cancelJob(JobRequest &job); - std::string getJobStatus(const JobRequest &job); + std::optional submitJob(JobRequest& job); + void cancelJob(JobRequest& job); + std::string getJobStatus(const JobRequest& job); std::unique_ptr - getJobResult(const JobRequest &job, bool wait = false, size_t timeout = 100); + getJobResult(const JobRequest& job, bool wait = false, size_t timeout = 100); - int getNumberPendingJobs(const std::string &resource) const; + int getNumberPendingJobs(const std::string& resource) const; private: std::unique_ptr mClient; diff --git a/include/mqss/job.h b/include/mqss/job.h index 5aa1a6b..788b154 100644 --- a/include/mqss/job.h +++ b/include/mqss/job.h @@ -1,9 +1,27 @@ +/* + * Copyright (c) 2024 - 2026 MQSS Project + * All rights reserved. + * + * Licensed under the Apache License v2.0 with LLVM Exceptions (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://llvm.org/LICENSE.txt + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#include #include #include #include -#include - namespace mqss::client { class JobRequest { @@ -15,7 +33,7 @@ class JobRequest { virtual nlohmann::json toJson() const = 0; virtual std::string getPath() const = 0; std::string getUuid() const { return mUuid; } - void setUuid(const std::string &uuid) { mUuid = uuid; } + void setUuid(const std::string& uuid) { mUuid = uuid; } }; class CircuitJobRequest : public JobRequest { @@ -28,7 +46,7 @@ class CircuitJobRequest : public JobRequest { bool mQueued; public: - CircuitJobRequest(){}; + CircuitJobRequest() {}; CircuitJobRequest(std::string circuit, std::string circuitFormat, std::string resourceName, unsigned int shots, bool noModify, @@ -40,7 +58,7 @@ class CircuitJobRequest : public JobRequest { mCircuitFormat = circuitFormat; } std::string getCircuitFormat() const { return mCircuitFormat; } - void setResourceName(const std::string &resourceName) { + void setResourceName(const std::string& resourceName) { mResourceName = resourceName; } std::string getResourceName() const { return mResourceName; } @@ -66,7 +84,7 @@ class HamiltonianJobRequest : public JobRequest { HamiltonianJobRequest(std::string resourceName, std::string interactionStr, std::string coefficientsStr); - HamiltonianJobRequest(){}; + HamiltonianJobRequest() {}; void setResourceName(std::string resourceName) { mResourceName = resourceName; @@ -100,7 +118,7 @@ class JobResult { std::string timestampCompleted, std::string timestampSubmitted, std::string timestampScheduled); - JobResult(const nlohmann::json &parsed); + JobResult(const nlohmann::json& parsed); std::map getResults() const { return mResults; } std::string getTimestampCompleted() const { return mTimestampCompleted; } diff --git a/include/mqss/resource.h b/include/mqss/resource.h index b38a7b0..44fdb0b 100644 --- a/include/mqss/resource.h +++ b/include/mqss/resource.h @@ -1,26 +1,44 @@ +/* + * Copyright (c) 2024 - 2026 MQSS Project + * All rights reserved. + * + * Licensed under the Apache License v2.0 with LLVM Exceptions (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://llvm.org/LICENSE.txt + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#include #include #include #include - -#include namespace mqss::client { class Resource { public: Resource(std::string name, unsigned qubitCount, bool online, - std::vector> couplingMap, - std::vector nativeGateset); + std::vector> couplingMap, + std::vector nativeGateset); - Resource(const nlohmann::json &json); + Resource(const nlohmann::json& json); - const std::string &getName() const noexcept { return mName; } + const std::string& getName() const noexcept { return mName; } unsigned getQubitCount() const noexcept { return mQubitCount; } bool isOnline() const noexcept { return mOnline; } - const std::vector> &getCouplingMap() const noexcept { + const std::vector>& getCouplingMap() const noexcept { return mCouplingMap; } - const std::vector &getNativeGateset() const noexcept { + const std::vector& getNativeGateset() const noexcept { return mNativeGateset; } diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 13aa989..6c63bce 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,10 +1,11 @@ -# Copyright 2024 Munich Quantum Software Stack Project +# Copyright (c) 2024 - 2026 MQSS Project +# All rights reserved. # -# Licensed under the Apache License, Version 2.0 with LLVM Exceptions (the -# "License"); you may not use this file except in compliance with the License. +# Licensed under the Apache License v2.0 with LLVM Exceptions (the "License"); +# you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# https://github.com/Munich-Quantum-Software-Stack/QDMI-Devices/blob/develop/LICENSE +# https://llvm.org/LICENSE.txt # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT @@ -13,26 +14,24 @@ # the License. # # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# ------------------------------------------------------------------------------ find_package(CURL REQUIRED) find_package(nlohmann_json REQUIRED) find_package(rabbitmq-c REQUIRED) file(GLOB CLIENT_SRC_FILES "${CMAKE_CURRENT_SOURCE_DIR}/clients/*.cpp") -add_library(mqss_client SHARED client.cpp resource.cpp job.cpp ${CLIENT_SRC_FILES}) +add_library(mqss_client SHARED ${CLIENT_SRC_FILES} client.cpp job.cpp resource.cpp) -target_include_directories( - mqss_client PUBLIC ${CMAKE_SOURCE_DIR}/include) +target_include_directories(mqss_client PUBLIC ${CMAKE_SOURCE_DIR}/include) -target_link_libraries(mqss_client PUBLIC curl nlohmann_json rabbitmq) +target_link_libraries(mqss_client PUBLIC curl nlohmann_json rabbitmq) add_subdirectory(python) include(GNUInstallDirs) -install(TARGETS mqss_client - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib) +install( + TARGETS mqss_client + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib) -install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/ - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) +install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) diff --git a/src/client.cpp b/src/client.cpp index df60a88..fc13c03 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -1,14 +1,35 @@ +/* + * Copyright (c) 2024 - 2026 MQSS Project + * All rights reserved. + * + * Licensed under the Apache License v2.0 with LLVM Exceptions (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://llvm.org/LICENSE.txt + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + #include "mqss/client.h" + #include "clients/hpc_client.h" #include "clients/rest_client.h" + #include #include #include using namespace mqss::client; -MQSSClient::MQSSClient(const std::string &token, - const std::string &url_or_queue, bool is_hpc) { +MQSSClient::MQSSClient(const std::string& token, + const std::string& url_or_queue, bool is_hpc) { if (is_hpc) { mClient = std::make_unique(token, url_or_queue); } else { @@ -22,14 +43,14 @@ std::vector MQSSClient::getAllResources() const { if (!nlohmann::json::accept(resp)) return {}; nlohmann::json parsed = nlohmann::json::parse(resp); - for (auto &item : parsed) { + for (auto& item : parsed) { Resources.push_back(Resource(item)); } return Resources; } std::optional -MQSSClient::getResourceInfo(const std::string &resource) const { +MQSSClient::getResourceInfo(const std::string& resource) const { std::string resp = mClient->get("resources/" + resource); if (resp.find("RESOURCE NOT FOUND") != std::string::npos) return std::nullopt; @@ -42,7 +63,7 @@ MQSSClient::getResourceInfo(const std::string &resource) const { return std::nullopt; return Resource(parsed); } -std::optional MQSSClient::submitJob(JobRequest &job) { +std::optional MQSSClient::submitJob(JobRequest& job) { std::string path = job.getPath(); std::string result = mClient->post(path, job.toJson()); if (result.empty() || !nlohmann::json::accept(result)) @@ -57,12 +78,12 @@ std::optional MQSSClient::submitJob(JobRequest &job) { return uuid; } -void MQSSClient::cancelJob(JobRequest &job) { +void MQSSClient::cancelJob(JobRequest& job) { std::string path = job.getPath() + "/" + job.getUuid(); mClient->del(path); } -std::string MQSSClient::getJobStatus(const JobRequest &job) { +std::string MQSSClient::getJobStatus(const JobRequest& job) { std::string path = job.getPath() + "/" + job.getUuid() + "/status"; std::string resp = mClient->get(path); if (resp.empty()) @@ -75,7 +96,7 @@ std::string MQSSClient::getJobStatus(const JobRequest &job) { return parsed.value("status", ""); } -std::unique_ptr MQSSClient::getJobResult(const JobRequest &job, +std::unique_ptr MQSSClient::getJobResult(const JobRequest& job, bool wait, size_t timeout) { if (wait) { @@ -91,7 +112,7 @@ std::unique_ptr MQSSClient::getJobResult(const JobRequest &job, return std::make_unique(JobResult(parsed)); } -std::unique_ptr MQSSClient::waitForJobResult(const JobRequest &job, +std::unique_ptr MQSSClient::waitForJobResult(const JobRequest& job, size_t timeout) { size_t poll_seconds = 2; @@ -107,7 +128,7 @@ std::unique_ptr MQSSClient::waitForJobResult(const JobRequest &job, return timeout <= 0 ? nullptr : getJobResult(job); } -int MQSSClient::getNumberPendingJobs(const std::string &resource) const { +int MQSSClient::getNumberPendingJobs(const std::string& resource) const { std::string resp = mClient->get("resources/" + resource + "/num_pending_jobs"); if (resp.empty() || !nlohmann::json::accept(resp)) diff --git a/src/clients/hpc_client.cpp b/src/clients/hpc_client.cpp index 456880e..d852643 100644 --- a/src/clients/hpc_client.cpp +++ b/src/clients/hpc_client.cpp @@ -1,3 +1,22 @@ +/* + * Copyright (c) 2024 - 2026 MQSS Project + * All rights reserved. + * + * Licensed under the Apache License v2.0 with LLVM Exceptions (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://llvm.org/LICENSE.txt + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + #include "hpc_client.h" inline std::string getHostName() { @@ -5,7 +24,7 @@ inline std::string getHostName() { if (max_hostname_size == -1) { max_hostname_size = 256; } - char *hostname = new char[max_hostname_size]; + char* hostname = new char[max_hostname_size]; if (gethostname(hostname, max_hostname_size) == 0) { std::string result(hostname); delete[] hostname; @@ -33,7 +52,7 @@ MQSSHPCClient::MQSSHPCClient(std::string token, mRabbitmqClient.declareQueue(mResponseQueueName); } -std::string MQSSHPCClient::get(const std::string &path) { +std::string MQSSHPCClient::get(const std::string& path) { std::string request, response; nlohmann::json request_json = { {"authorization", ""}, @@ -49,8 +68,8 @@ std::string MQSSHPCClient::get(const std::string &path) { return response; } -std::string MQSSHPCClient::post(const std::string &path, - const nlohmann::json &data) { +std::string MQSSHPCClient::post(const std::string& path, + const nlohmann::json& data) { nlohmann::json request_json = { {"authorization", ""}, {"method", "POST"}, @@ -65,7 +84,7 @@ std::string MQSSHPCClient::post(const std::string &path, return response; } -void MQSSHPCClient::del(const std::string &path) { +void MQSSHPCClient::del(const std::string& path) { std::string request, response; mRabbitmqClient.send(mOffloadListenerQueueName, request); response = mRabbitmqClient.receive(mResponseQueueName); diff --git a/src/clients/hpc_client.h b/src/clients/hpc_client.h index a886068..8336acc 100644 --- a/src/clients/hpc_client.h +++ b/src/clients/hpc_client.h @@ -1,3 +1,22 @@ +/* + * Copyright (c) 2024 - 2026 MQSS Project + * All rights reserved. + * + * Licensed under the Apache License v2.0 with LLVM Exceptions (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://llvm.org/LICENSE.txt + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + #pragma once #include "mqss/client.h" @@ -20,10 +39,10 @@ class MQSSHPCClient : public MQSSBaseClient { public: MQSSHPCClient(std::string token, std::string offloadListenerQueueName); - std::string get(const std::string &path) override; + std::string get(const std::string& path) override; - std::string post(const std::string &path, - const nlohmann::json &data) override; + std::string post(const std::string& path, + const nlohmann::json& data) override; - void del(const std::string &path) override; + void del(const std::string& path) override; }; diff --git a/src/clients/rabbitmq_client.cpp b/src/clients/rabbitmq_client.cpp index 670b7bc..7640397 100644 --- a/src/clients/rabbitmq_client.cpp +++ b/src/clients/rabbitmq_client.cpp @@ -1,3 +1,22 @@ +/* + * Copyright (c) 2024 - 2026 MQSS Project + * All rights reserved. + * + * Licensed under the Apache License v2.0 with LLVM Exceptions (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://llvm.org/LICENSE.txt + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + #include "rabbitmq_client.h" int MQSSRabbitMQClient::connect() { @@ -32,8 +51,8 @@ void MQSSRabbitMQClient::disconnect() { amqp_destroy_connection(mConnection); } -int MQSSRabbitMQClient::send(const std::string &queue, - const std::string &data) { +int MQSSRabbitMQClient::send(const std::string& queue, + const std::string& data) { amqp_basic_properties_t props; props._flags = AMQP_BASIC_CONTENT_TYPE_FLAG | AMQP_BASIC_DELIVERY_MODE_FLAG; props.content_type = amqp_cstring_bytes("text/plain"); @@ -43,7 +62,7 @@ int MQSSRabbitMQClient::send(const std::string &queue, amqp_cstring_bytes(data.c_str())); } -std::string MQSSRabbitMQClient::receive(const std::string &queue) { +std::string MQSSRabbitMQClient::receive(const std::string& queue) { declareQueue(queue); amqp_basic_consume(mConnection, 1, amqp_cstring_bytes(queue.c_str()), @@ -57,7 +76,7 @@ std::string MQSSRabbitMQClient::receive(const std::string &queue) { return amqp_error_string2(reply.library_error); } - std::string body(static_cast(envelope.message.body.bytes), + std::string body(static_cast(envelope.message.body.bytes), envelope.message.body.len); amqp_basic_ack(mConnection, 1, envelope.delivery_tag, false); @@ -66,7 +85,7 @@ std::string MQSSRabbitMQClient::receive(const std::string &queue) { return body; } -int MQSSRabbitMQClient::declareQueue(const std::string &queueName) { +int MQSSRabbitMQClient::declareQueue(const std::string& queueName) { if (std::find(mQueues.begin(), mQueues.end(), queueName) != mQueues.end()) return 0; diff --git a/src/clients/rabbitmq_client.h b/src/clients/rabbitmq_client.h index 1eb9e86..a0aefa0 100644 --- a/src/clients/rabbitmq_client.h +++ b/src/clients/rabbitmq_client.h @@ -1,9 +1,27 @@ +/* + * Copyright (c) 2024 - 2026 MQSS Project + * All rights reserved. + * + * Licensed under the Apache License v2.0 with LLVM Exceptions (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://llvm.org/LICENSE.txt + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + #pragma once +#include #include #include - -#include #include #include @@ -11,7 +29,7 @@ class MQSSRabbitMQClient { private: amqp_connection_state_t mConnection; - amqp_socket_t *mpSocket; + amqp_socket_t* mpSocket; std::string mHostname; std::string mUser; @@ -20,11 +38,10 @@ class MQSSRabbitMQClient { std::vector mQueues; public: - MQSSRabbitMQClient(std::string user = "guest", - std::string password = "guest", - std::string hostname = "host.docker.internal", - int port = 5672) - : mUser(user), mPassword(password), mHostname(hostname), mPort(port){}; + MQSSRabbitMQClient(std::string user = "guest", std::string password = "guest", + std::string hostname = "host.docker.internal", + int port = 5672) + : mUser(user), mPassword(password), mHostname(hostname), mPort(port) {}; ~MQSSRabbitMQClient() { disconnect(); } diff --git a/src/clients/rest_client.cpp b/src/clients/rest_client.cpp index 5d5eec0..ca2ea2b 100644 --- a/src/clients/rest_client.cpp +++ b/src/clients/rest_client.cpp @@ -1,22 +1,40 @@ +/* + * Copyright (c) 2024 - 2026 MQSS Project + * All rights reserved. + * + * Licensed under the Apache License v2.0 with LLVM Exceptions (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://llvm.org/LICENSE.txt + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ #include "rest_client.h" typedef struct MQSSRestResponse_d { - char *pResponse; + char* pResponse; size_t mSize; } MQSSRestResponse; -static size_t writeCallback(char *data, size_t size, size_t nmemb, - void *clientp) { +static size_t writeCallback(char* data, size_t size, size_t nmemb, + void* clientp) { size_t realsize = size * nmemb; - MQSSRestResponse *pResponse = (MQSSRestResponse *)clientp; - char *pTempResponse = - (char *)realloc(pResponse->pResponse, pResponse->mSize + realsize + 1); + MQSSRestResponse* pResponse = (MQSSRestResponse*)clientp; + char* pTempResponse = + (char*)realloc(pResponse->pResponse, pResponse->mSize + realsize + 1); if (!pTempResponse) return 0; pResponse->pResponse = pTempResponse; - void *dest = + void* dest = memcpy(&(pResponse->pResponse[pResponse->mSize]), data, realsize); if (dest == NULL) fprintf(stderr, "Memory error"); @@ -34,14 +52,14 @@ MQSSRestClient::MQSSRestClient(std::string token, std::string url) pHeaders = curl_slist_append(pHeaders, "Content-Type: application/json"); } -std::string MQSSRestClient::get(const std::string &path) { - CURL *curl = curl_easy_init(); +std::string MQSSRestClient::get(const std::string& path) { + CURL* curl = curl_easy_init(); if (!curl) return "1"; MQSSRestResponse response = {0}; curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeCallback); - curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&response); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)&response); curl_easy_setopt(curl, CURLOPT_URL, (mUrl + path).c_str()); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, pHeaders); @@ -56,10 +74,10 @@ std::string MQSSRestClient::get(const std::string &path) { return result; } -std::string MQSSRestClient::post(const std::string &path, - const nlohmann::json &data) { +std::string MQSSRestClient::post(const std::string& path, + const nlohmann::json& data) { - CURL *curl = curl_easy_init(); + CURL* curl = curl_easy_init(); if (!curl) return ""; @@ -84,9 +102,9 @@ std::string MQSSRestClient::post(const std::string &path, return result; } -void MQSSRestClient::del(const std::string &path) { +void MQSSRestClient::del(const std::string& path) { - CURL *curl = curl_easy_init(); + CURL* curl = curl_easy_init(); if (!curl) return; long response_code; @@ -94,7 +112,7 @@ void MQSSRestClient::del(const std::string &path) { curl_easy_setopt(curl, CURLOPT_URL, (mUrl + path).c_str()); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeCallback); - curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&response); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)&response); curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELETE"); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, pHeaders); diff --git a/src/clients/rest_client.h b/src/clients/rest_client.h index 731afa2..010f531 100644 --- a/src/clients/rest_client.h +++ b/src/clients/rest_client.h @@ -1,6 +1,26 @@ +/* + * Copyright (c) 2024 - 2026 MQSS Project + * All rights reserved. + * + * Licensed under the Apache License v2.0 with LLVM Exceptions (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://llvm.org/LICENSE.txt + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + #pragma once #include "mqss/client.h" + #include #include @@ -10,15 +30,15 @@ class MQSSRestClient : public MQSSBaseClient { private: std::string mUrl; std::string mToken; - struct curl_slist *pHeaders; + struct curl_slist* pHeaders; public: MQSSRestClient(std::string token, std::string url = MQP_DEFAULT_URL); - std::string get(const std::string &path) override; + std::string get(const std::string& path) override; - std::string post(const std::string &path, - const nlohmann::json &data) override; + std::string post(const std::string& path, + const nlohmann::json& data) override; - void del(const std::string &path) override; + void del(const std::string& path) override; }; diff --git a/src/job.cpp b/src/job.cpp index 867c7a6..dfe9f49 100644 --- a/src/job.cpp +++ b/src/job.cpp @@ -1,15 +1,31 @@ +/* + * Copyright (c) 2024 - 2026 MQSS Project + * All rights reserved. + * + * Licensed under the Apache License v2.0 with LLVM Exceptions (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://llvm.org/LICENSE.txt + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + #include "mqss/job.h" using namespace mqss::client; nlohmann::json CircuitJobRequest::toJson() const { - return {{"circuit", {mCircuit}}, - {"circuit_format", mCircuitFormat}, - {"resource_name", mResourceName}, - {"shots", mShots}, - {"no_modify", mNoModify}, - {"queued", mQueued}}; + return {{"circuit", {mCircuit}}, {"circuit_format", mCircuitFormat}, + {"resource_name", mResourceName}, {"shots", mShots}, + {"no_modify", mNoModify}, {"queued", mQueued}}; } CircuitJobRequest::CircuitJobRequest(std::string circuit, @@ -44,18 +60,18 @@ JobResult::JobResult(std::map results, mTimestampSubmitted(std::move(timestampSubmitted)), mTimestampScheduled(std::move(timestampScheduled)) {} -JobResult::JobResult(const nlohmann::json &parsed) { +JobResult::JobResult(const nlohmann::json& parsed) { - const auto &rResultStr = parsed.at("result").get_ref(); + const auto& rResultStr = parsed.at("result").get_ref(); - if(!nlohmann::json::accept(rResultStr)) + if (!nlohmann::json::accept(rResultStr)) return; nlohmann::json resultMap = nlohmann::json::parse(rResultStr); - if(resultMap.is_array()) + if (resultMap.is_array()) resultMap = resultMap[0]; - for (auto &[key, value] : resultMap.items()) { + for (auto& [key, value] : resultMap.items()) { resultMap[key] = value.get(); } diff --git a/src/python/CMakeLists.txt b/src/python/CMakeLists.txt index 42a176e..8b601a4 100644 --- a/src/python/CMakeLists.txt +++ b/src/python/CMakeLists.txt @@ -1,3 +1,20 @@ +# Copyright (c) 2024 - 2026 MQSS Project +# All rights reserved. +# +# Licensed under the Apache License v2.0 with LLVM Exceptions (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://llvm.org/LICENSE.txt +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. +# +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + find_package(pybind11 REQUIRED) pybind11_add_module(mqss THIN_LTO OPT_SIZE bindings.cpp) target_include_directories(mqss PRIVATE ${CMAKE_SOURCE_DIR}/include) diff --git a/src/python/bindings.cpp b/src/python/bindings.cpp index 57e180b..444384c 100644 --- a/src/python/bindings.cpp +++ b/src/python/bindings.cpp @@ -1,20 +1,21 @@ -/*------------------------------------------------------------------------------ -Copyright 2024 Munich Quantum Software Stack Project - -Licensed under the Apache License, Version 2.0 with LLVM Exceptions (the -"License"); you may not use this file except in compliance with the License. -You may obtain a copy of the License at - -https://github.com/Munich-Quantum-Software-Stack/QDMI/blob/develop/LICENSE - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -License for the specific language governing permissions and limitations under -the License. - -SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -------------------------------------------------------------------------------*/ +/* + * Copyright (c) 2024 - 2026 MQSS Project + * All rights reserved. + * + * Licensed under the Apache License v2.0 with LLVM Exceptions (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://llvm.org/LICENSE.txt + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ #include "mqss/client.h" @@ -30,7 +31,7 @@ PYBIND11_MODULE(mqss, m) { py::module_ clientModule = m.def_submodule("client", "Submodule Client"); py::class_(clientModule, "MQSSClient") - .def(py::init(), + .def(py::init(), py::arg("token") = "", py::arg("url_or_queue") = MQP_DEFAULT_URL, py::arg("is_hpc") = false) .def_property_readonly("resources", @@ -62,7 +63,7 @@ PYBIND11_MODULE(mqss, m) { py::class_( clientModule, "CircuitJobRequest") .def(py::init<>()) - .def(py::init(), py::arg("circuit"), py::arg("circuit_format"), py::arg("resource_name"), py::arg("shots"), py::arg("no_modify"), @@ -85,7 +86,7 @@ PYBIND11_MODULE(mqss, m) { py::class_( clientModule, "HamiltonianJobRequest") .def(py::init<>()) - .def(py::init(), + .def(py::init(), py::arg("resource_name"), py::arg("interaction"), py::arg("coefficients")) .def_property("resource_name", diff --git a/src/resource.cpp b/src/resource.cpp index 80fa9da..f74aa6b 100644 --- a/src/resource.cpp +++ b/src/resource.cpp @@ -1,4 +1,24 @@ +/* + * Copyright (c) 2024 - 2026 MQSS Project + * All rights reserved. + * + * Licensed under the Apache License v2.0 with LLVM Exceptions (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://llvm.org/LICENSE.txt + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + #include "mqss/resource.h" + #include using namespace mqss::client; @@ -10,15 +30,16 @@ const std::regex COUPLING_PATTERN(R"(\(\s*(\d+)\s*,\s*(\d+)\s*\))"); const std::regex GATE_PATTERN(R"('([^']+)')"); template -std::vector extractFromStringField(const nlohmann::json &response, const std::string &key, - const std::regex &pattern, Converter &&convert) { +std::vector +extractFromStringField(const nlohmann::json& response, const std::string& key, + const std::regex& pattern, Converter&& convert) { std::vector result; const auto it = response.find(key); if (it == response.end() || !it->is_string()) return result; - const std::string &text = it->get_ref(); + const std::string& text = it->get_ref(); if (text == "None") return result; @@ -37,26 +58,26 @@ std::vector extractFromStringField(const nlohmann::json &response, const std: } // namespace Resource::Resource(std::string name, unsigned qubitCount, bool online, - std::vector> couplingMap, - std::vector nativeGateset) + std::vector> couplingMap, + std::vector nativeGateset) : mName(std::move(name)), mQubitCount(qubitCount), mOnline(online), mCouplingMap(std::move(couplingMap)), mNativeGateset(std::move(nativeGateset)) {} -Resource::Resource(const nlohmann::json &json) { +Resource::Resource(const nlohmann::json& json) { std::string name = json.value("name", ""); unsigned qubitCount = json.value("qubits", 0); bool online = json.value("online", false); auto couplingMap = extractFromStringField>( - json, "connectivity", COUPLING_PATTERN, [](const std::smatch &m) { + json, "connectivity", COUPLING_PATTERN, [](const std::smatch& m) { return std::make_pair(std::stoi(m[1]), std::stoi(m[2])); }); - auto nativeGateset = - extractFromStringField(json, "instructions", GATE_PATTERN, - [](const std::smatch &m) { return m[1].str(); }); + auto nativeGateset = extractFromStringField( + json, "instructions", GATE_PATTERN, + [](const std::smatch& m) { return m[1].str(); }); mName = std::move(name); mQubitCount = qubitCount; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6a419f5..9103115 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,2 +1,19 @@ +# Copyright (c) 2024 - 2026 MQSS Project +# All rights reserved. +# +# Licensed under the Apache License v2.0 with LLVM Exceptions (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://llvm.org/LICENSE.txt +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. +# +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + enable_testing() add_subdirectory(unit_tests) diff --git a/tests/unit_tests/CMakeLists.txt b/tests/unit_tests/CMakeLists.txt index 118303d..3c118e6 100644 --- a/tests/unit_tests/CMakeLists.txt +++ b/tests/unit_tests/CMakeLists.txt @@ -1,25 +1,36 @@ +# Copyright (c) 2024 - 2026 MQSS Project +# All rights reserved. +# +# Licensed under the Apache License v2.0 with LLVM Exceptions (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://llvm.org/LICENSE.txt +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. +# +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + include(GoogleTest) add_executable(resource_unit_test resource_unit_test.cpp) -target_link_libraries( - resource_unit_test PRIVATE gtest gtest_main mqss_client) +target_link_libraries(resource_unit_test PRIVATE gtest gtest_main mqss_client) gtest_discover_tests(resource_unit_test) - add_executable(job_unit_test job_unit_test.cpp) -target_link_libraries( - job_unit_test PRIVATE gtest gtest_main mqss_client) +target_link_libraries(job_unit_test PRIVATE gtest gtest_main mqss_client) gtest_discover_tests(job_unit_test) - if(ENABLE_COVERAGE) - target_compile_options(resource_unit_test INTERFACE --coverage -fprofile-arcs - -ftest-coverage -O0) + target_compile_options(resource_unit_test INTERFACE --coverage -fprofile-arcs -ftest-coverage -O0) target_link_libraries(resource_unit_test INTERFACE gcov --coverage) - target_compile_options(job_unit_test INTERFACE --coverage -fprofile-arcs - -ftest-coverage -O0) + target_compile_options(job_unit_test INTERFACE --coverage -fprofile-arcs -ftest-coverage -O0) target_link_libraries(job_unit_test INTERFACE gcov --coverage) endif() diff --git a/tests/unit_tests/job_unit_test.cpp b/tests/unit_tests/job_unit_test.cpp index 3e7162c..eaf627d 100644 --- a/tests/unit_tests/job_unit_test.cpp +++ b/tests/unit_tests/job_unit_test.cpp @@ -1,22 +1,24 @@ -/*------------------------------------------------------------------------------ -Copyright 2024 Munich Quantum Software Stack Project - -Licensed under the Apache License, Version 2.0 with LLVM Exceptions (the -"License"); you may not use this file except in compliance with the License. -You may obtain a copy of the License at - -https://github.com/Munich-Quantum-Software-Stack/QDMI/blob/develop/LICENSE - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, WITHOUT> -WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -License for the specific language governing permissions and limitations under -the License. - -SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -------------------------------------------------------------------------------*/ +/* + * Copyright (c) 2024 - 2026 MQSS Project + * All rights reserved. + * + * Licensed under the Apache License v2.0 with LLVM Exceptions (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://llvm.org/LICENSE.txt + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ #include "mqss/client.h" + #include "gtest/gtest.h" #include #include @@ -38,7 +40,7 @@ struct ClientCtorParam { class MQSSClientJobTest : public ::testing::TestWithParam { protected: void SetUp() override { - const auto &p = GetParam(); + const auto& p = GetParam(); client = mqss::client::MQSSClient{p.token, p.url_or_queue, p.isHPC}; } @@ -53,7 +55,6 @@ INSTANTIATE_TEST_SUITE_P(MQSS_Test_Instantiation, MQSSClientJobTest, ClientCtorParam{MQSS_API_TOKEN, MQSS_API_URL, false})); - static const std::string TEST_CIRCUIT = R"( OPENQASM 2.0; include "qelib1.inc"; @@ -160,7 +161,7 @@ TEST_P(MQSSClientJobTest, ClientGetNumPendingJobs) { ASSERT_GE(n_job, 0); } -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/tests/unit_tests/python/test_job.py b/tests/unit_tests/python/test_job.py index 3f66ee8..7e0fda4 100644 --- a/tests/unit_tests/python/test_job.py +++ b/tests/unit_tests/python/test_job.py @@ -1,11 +1,11 @@ -# ------------------------------------------------------------------------------ -# Copyright 2024 Munich Quantum Software Stack Project +# Copyright (c) 2024 - 2026 MQSS Project +# All rights reserved. # -# Licensed under the Apache License, Version 2.0 with LLVM Exceptions (the -# "License"); you may not use this file except in compliance with the License. +# Licensed under the Apache License v2.0 with LLVM Exceptions (the "License"); +# you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# https://github.com/Munich-Quantum-Software-Stack/QDMI/blob/develop/LICENSE +# https://llvm.org/LICENSE.txt # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT @@ -14,7 +14,6 @@ # the License. # # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# ------------------------------------------------------------------------------ from mqss.client import MQSSClient import pytest diff --git a/tests/unit_tests/python/test_resource.py b/tests/unit_tests/python/test_resource.py index 3d94e0d..d2d0831 100644 --- a/tests/unit_tests/python/test_resource.py +++ b/tests/unit_tests/python/test_resource.py @@ -1,11 +1,11 @@ -# ------------------------------------------------------------------------------ -# Copyright 2024 Munich Quantum Software Stack Project +# Copyright (c) 2024 - 2026 MQSS Project +# All rights reserved. # -# Licensed under the Apache License, Version 2.0 with LLVM Exceptions (the -# "License"); you may not use this file except in compliance with the License. +# Licensed under the Apache License v2.0 with LLVM Exceptions (the "License"); +# you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# https://github.com/Munich-Quantum-Software-Stack/QDMI/blob/develop/LICENSE +# https://llvm.org/LICENSE.txt # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT @@ -14,7 +14,6 @@ # the License. # # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# ------------------------------------------------------------------------------ from mqss.client import MQSSClient import pytest @@ -59,10 +58,6 @@ def test_client_get_a_resource(client, resource_name): resource = client.resource(resource_name) assert resource is not None - -# --------------------------------------------------------------------- -# 3️⃣ ClientGetAResourceFalse -# --------------------------------------------------------------------- @pytest.mark.parametrize( "resource_name", ["Eviden", "IQM5", "IQM20", "AQT", "QExa120"], diff --git a/tests/unit_tests/resource_unit_test.cpp b/tests/unit_tests/resource_unit_test.cpp index 078235e..2934c45 100644 --- a/tests/unit_tests/resource_unit_test.cpp +++ b/tests/unit_tests/resource_unit_test.cpp @@ -1,22 +1,24 @@ -/*------------------------------------------------------------------------------ -Copyright 2024 Munich Quantum Software Stack Project - -Licensed under the Apache License, Version 2.0 with LLVM Exceptions (the -"License"); you may not use this file except in compliance with the License. -You may obtain a copy of the License at - -https://github.com/Munich-Quantum-Software-Stack/QDMI/blob/develop/LICENSE - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -License for the specific language governing permissions and limitations under -the License. - -SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -------------------------------------------------------------------------------*/ +/* + * Copyright (c) 2024 - 2026 MQSS Project + * All rights reserved. + * + * Licensed under the Apache License v2.0 with LLVM Exceptions (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://llvm.org/LICENSE.txt + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ #include "mqss/client.h" + #include "gtest/gtest.h" #include #include @@ -33,10 +35,11 @@ struct ClientCtorParam { bool isHPC = false; }; -class MQSSClientResourceTest : public ::testing::TestWithParam { +class MQSSClientResourceTest + : public ::testing::TestWithParam { protected: void SetUp() override { - const auto &p = GetParam(); + const auto& p = GetParam(); client = mqss::client::MQSSClient{p.token, p.url_or_queue, p.isHPC}; } @@ -57,7 +60,7 @@ TEST_P(MQSSClientResourceTest, ClientGetAllResources) { TEST_P(MQSSClientResourceTest, ClientGetAResource) { std::vector resourceNames = {"QLM", "Q5", "Q20", "AQT20", - "QExa20"}; + "QExa20"}; for (auto resourceName : resourceNames) { std::optional resource = client.getResourceInfo(resourceName); @@ -67,7 +70,7 @@ TEST_P(MQSSClientResourceTest, ClientGetAResource) { TEST_P(MQSSClientResourceTest, ClientGetAResourceFalse) { std::vector resourceNames = {"Eviden", "IQM5", "IQM20", "AQT", - "QExa120"}; + "QExa120"}; for (auto resourceName : resourceNames) { std::optional resource = client.getResourceInfo(resourceName); @@ -117,7 +120,7 @@ TEST_P(MQSSClientResourceTest, ClientCheckNativeGateset) { ASSERT_GE((*resource).getNativeGateset().size(), 0); } -int main(int argc, char **argv) { +int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); }