diff --git a/README.md b/README.md index 6af04caf..e32bf8e0 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ ## Installation +### Using pip ```bash pip install oqd-core ``` @@ -23,7 +24,36 @@ or through `git`, pip install git+https://github.com/OpenQuantumDesign/oqd-core.git ``` -To develop, clone the repository locally: +### Using Nix +If you have Nix installed with flakes enabled, you can create a development environment with all dependencies using: + +```bash +# Clone the repository +git clone https://github.com/OpenQuantumDesign/oqd-core +cd oqd-core + +# Enter the development shell with all dependencies +nix develop + +# You can also directly develop without cloning using: +nix develop github:OpenQuantumDesign/oqd-core + +# Once in the development shell, you can: +# 1. Run tests: pytest +# 2. Build documentation: mkdocs serve +# 3. Use the package directly in Python + +# The development environment includes: +# - Python with all required dependencies +# - Development tools (ruff, black, isort, mypy) +# - Documentation tools (mkdocs) +# - Testing tools (pytest) +``` + +The `nix develop` command will create an isolated development environment with all the necessary dependencies. This is the recommended way to develop and contribute to the project, as it ensures a consistent development environment across all contributors. + +### Development Installation +To develop without Nix, clone the repository locally: ```bash git clone https://github.com/OpenQuantumDesign/oqd-core @@ -152,4 +182,3 @@ block-beta class Interface,IRAnalog,IRAtomic highlight ``` -The stack components highlighted in red are contained in this repository. diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..81660271 --- /dev/null +++ b/flake.lock @@ -0,0 +1,117 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1747542820, + "narHash": "sha256-GaOZntlJ6gPPbbkTLjbd8BMWaDYafhuuYRNrxCGnPJw=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "292fa7d4f6519c074f0a50394dbbe69859bb6043", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "oqd-compiler-infrastructure": { + "inputs": { + "flake-utils": "flake-utils_2", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1747621390, + "narHash": "sha256-YYxFPAphpqajFHphLy2Yr1GHxd7h9D64xuqiMj8Oo+g=", + "owner": "OpenQuantumDesign", + "repo": "oqd-compiler-infrastructure", + "rev": "9ea0186801d21f3f21bcd43e5c82b8083decc222", + "type": "github" + }, + "original": { + "owner": "OpenQuantumDesign", + "ref": "Mahmoud-Yasser-18-patch-1", + "repo": "oqd-compiler-infrastructure", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "oqd-compiler-infrastructure": "oqd-compiler-infrastructure" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..20648712 --- /dev/null +++ b/flake.nix @@ -0,0 +1,78 @@ +# Copyright 2024-2025 Open Quantum Design + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# 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. +{ + description = "OpenQuantum Design Core Library"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + oqd-compiler-infrastructure = { + url = "github:OpenQuantumDesign/oqd-compiler-infrastructure/Mahmoud-Yasser-18-patch-1"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { self, nixpkgs, flake-utils, oqd-compiler-infrastructure }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + python = pkgs.python311; + pythonPackages = python.pkgs; + oqdCompilerInfra = oqd-compiler-infrastructure.packages.${system}.default; + in + { + packages.default = pythonPackages.callPackage ./pkgs/derivation.nix { + inherit (pythonPackages) setuptools; + oqd-compiler-infrastructure = oqdCompilerInfra; + }; + + devShells.default = pkgs.mkShell { + packages = with pkgs; [ + # Python with dependencies + (python.withPackages (ps: with ps; [ + # Core dependencies + pydantic + numpy + + # Documentation dependencies + pymdown-extensions + mkdocstrings + mkdocs-material + mkdocstrings-python + mdx-truly-sane-lists + + # Test dependencies + pytest + + # Development tools + pip + black + isort + mypy + ])) + oqdCompilerInfra + + # Additional development tools + git + ]; + + shellHook = '' + export PYTHONPATH="$PWD/src:$PYTHONPATH" + echo "OpenQuantum Design Core Library development environment" + echo "Python version: $(python --version)" + ''; + }; + } + ); +} diff --git a/pkgs/derivation.nix b/pkgs/derivation.nix new file mode 100644 index 00000000..708ef8e0 --- /dev/null +++ b/pkgs/derivation.nix @@ -0,0 +1,66 @@ +# Copyright 2024-2025 Open Quantum Design + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# 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. + +{ lib +, buildPythonPackage +, pythonOlder +, pydantic +, numpy +, pytest +, pymdown-extensions +, mkdocstrings +, mkdocs-material +, mkdocstrings-python +, mdx-truly-sane-lists +, oqd-compiler-infrastructure +, setuptools +}: + +buildPythonPackage rec { + pname = "oqd-core"; + version = "0.1.0"; + format = "pyproject"; + + disabled = pythonOlder "3.10"; + + src = ./..; + + propagatedBuildInputs = [ + pydantic + numpy + oqd-compiler-infrastructure + ]; + + checkInputs = [ + pytest + ]; + + nativeBuildInputs = [ + pymdown-extensions + mkdocstrings + mkdocs-material + mkdocstrings-python + mdx-truly-sane-lists + setuptools + ]; + + pythonImportsCheck = [ "oqd_core" ]; + + meta = with lib; { + description = "OpenQuantum Design Core Library"; + homepage = "https://github.com/OpenQuantumDesign/oqd-core"; + license = licenses.asl20; + maintainers = with maintainers; [ ]; + }; +}