From 9af903c12175f8d66444551676a28f5c1a3c7eec Mon Sep 17 00:00:00 2001 From: Mahmoud Badawy Date: Sun, 18 May 2025 21:03:32 +0300 Subject: [PATCH 1/5] intitial unoptimized flake --- flake.lock | 61 +++++++++++++++++++++++++++++++++++++++ flake.nix | 69 +++++++++++++++++++++++++++++++++++++++++++++ pkgs/derivation.nix | 62 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 192 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 pkgs/derivation.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..bcaa61c5 --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "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" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1747327360, + "narHash": "sha256-LSmTbiq/nqZR9B2t4MRnWG7cb0KVNU70dB7RT4+wYK4=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e06158e58f3adee28b139e9c2bcfcc41f8625b46", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "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..15a6801b --- /dev/null +++ b/flake.nix @@ -0,0 +1,69 @@ +# 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"; + }; + + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + python = pkgs.python311; + pythonPackages = python.pkgs; + in + { + packages.default = pythonPackages.callPackage ./pkgs/derivation.nix { }; + + 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 + ])) + + # 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..c4f522e5 --- /dev/null +++ b/pkgs/derivation.nix @@ -0,0 +1,62 @@ +# 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 +}: + +buildPythonPackage rec { + pname = "oqd-core"; + version = "0.1.0"; + format = "pyproject"; + + disabled = pythonOlder "3.10"; + + src = ./..; + + propagatedBuildInputs = [ + pydantic + numpy + ]; + + checkInputs = [ + pytest + ]; + + nativeBuildInputs = [ + pymdown-extensions + mkdocstrings + mkdocs-material + mkdocstrings-python + mdx-truly-sane-lists + ]; + + pythonImportsCheck = [ "oqd_core" ]; + + meta = with lib; { + description = "OpenQuantum Design Core Library"; + homepage = "https://github.com/OpenQuantumDesign/oqd-core"; + license = licenses.apache20; + maintainers = with maintainers; [ ]; + }; +} From d602bf2f1a5dd06febb6ee8b9223666e348a1a71 Mon Sep 17 00:00:00 2001 From: Mahmoud Badawy Date: Sun, 18 May 2025 21:05:40 +0300 Subject: [PATCH 2/5] adding nix to readme --- README.md | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6af04caf..e990a629 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ ## Installation +### Using pip ```bash pip install oqd-core ``` @@ -23,7 +24,25 @@ 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 + +# The development environment includes: +# - Python with all required dependencies +# - Development tools (black, isort, mypy) +# - Documentation tools +``` + +### Development Installation +To develop without Nix, clone the repository locally: ```bash git clone https://github.com/OpenQuantumDesign/oqd-core @@ -152,4 +171,3 @@ block-beta class Interface,IRAnalog,IRAtomic highlight ``` -The stack components highlighted in red are contained in this repository. From bb5fb4a7b231bc337cc0ed193ff2423c8ef7af3f Mon Sep 17 00:00:00 2001 From: Mahmoud Badawy Date: Mon, 19 May 2025 04:25:14 +0300 Subject: [PATCH 3/5] adding the oqd compiler --- flake.lock | 64 ++++++++++++++++++++++++++++++++++++++++++--- flake.nix | 6 ++++- pkgs/derivation.nix | 3 ++- 3 files changed, 67 insertions(+), 6 deletions(-) diff --git a/flake.lock b/flake.lock index bcaa61c5..98f5477b 100644 --- a/flake.lock +++ b/flake.lock @@ -18,13 +18,31 @@ "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": 1747327360, - "narHash": "sha256-LSmTbiq/nqZR9B2t4MRnWG7cb0KVNU70dB7RT4+wYK4=", + "lastModified": 1747542820, + "narHash": "sha256-GaOZntlJ6gPPbbkTLjbd8BMWaDYafhuuYRNrxCGnPJw=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "e06158e58f3adee28b139e9c2bcfcc41f8625b46", + "rev": "292fa7d4f6519c074f0a50394dbbe69859bb6043", "type": "github" }, "original": { @@ -34,10 +52,33 @@ "type": "github" } }, + "oqd-compiler-infrastructure": { + "inputs": { + "flake-utils": "flake-utils_2", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1747594837, + "narHash": "sha256-q9NKZ017hv5YlTlYFfWtyP0GIRcF11lLceoO6Ctzoac=", + "owner": "OpenQuantumDesign", + "repo": "oqd-compiler-infrastructure", + "rev": "b03a9327296fc82a2b510a716e20fa381405502a", + "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" + "nixpkgs": "nixpkgs", + "oqd-compiler-infrastructure": "oqd-compiler-infrastructure" } }, "systems": { @@ -54,6 +95,21 @@ "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", diff --git a/flake.nix b/flake.nix index 15a6801b..16a044dc 100644 --- a/flake.nix +++ b/flake.nix @@ -17,9 +17,13 @@ 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 }: + outputs = { self, nixpkgs, flake-utils, oqd-compiler-infrastructure }: flake-utils.lib.eachDefaultSystem (system: let pkgs = nixpkgs.legacyPackages.${system}; diff --git a/pkgs/derivation.nix b/pkgs/derivation.nix index c4f522e5..a2a4bb7b 100644 --- a/pkgs/derivation.nix +++ b/pkgs/derivation.nix @@ -37,6 +37,7 @@ buildPythonPackage rec { propagatedBuildInputs = [ pydantic numpy + oqd-compiler-infrastructure ]; checkInputs = [ @@ -56,7 +57,7 @@ buildPythonPackage rec { meta = with lib; { description = "OpenQuantum Design Core Library"; homepage = "https://github.com/OpenQuantumDesign/oqd-core"; - license = licenses.apache20; + license = licenses.asl20; maintainers = with maintainers; [ ]; }; } From 9a93ac9926ba4e85751da248d226b958de5365f7 Mon Sep 17 00:00:00 2001 From: Mahmoud Badawy Date: Mon, 19 May 2025 05:33:33 +0300 Subject: [PATCH 4/5] oqd core can now see oqd compiler --- flake.lock | 6 +++--- flake.nix | 7 ++++++- pkgs/derivation.nix | 3 +++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/flake.lock b/flake.lock index 98f5477b..81660271 100644 --- a/flake.lock +++ b/flake.lock @@ -60,11 +60,11 @@ ] }, "locked": { - "lastModified": 1747594837, - "narHash": "sha256-q9NKZ017hv5YlTlYFfWtyP0GIRcF11lLceoO6Ctzoac=", + "lastModified": 1747621390, + "narHash": "sha256-YYxFPAphpqajFHphLy2Yr1GHxd7h9D64xuqiMj8Oo+g=", "owner": "OpenQuantumDesign", "repo": "oqd-compiler-infrastructure", - "rev": "b03a9327296fc82a2b510a716e20fa381405502a", + "rev": "9ea0186801d21f3f21bcd43e5c82b8083decc222", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 16a044dc..20648712 100644 --- a/flake.nix +++ b/flake.nix @@ -29,9 +29,13 @@ 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 { }; + packages.default = pythonPackages.callPackage ./pkgs/derivation.nix { + inherit (pythonPackages) setuptools; + oqd-compiler-infrastructure = oqdCompilerInfra; + }; devShells.default = pkgs.mkShell { packages = with pkgs; [ @@ -57,6 +61,7 @@ isort mypy ])) + oqdCompilerInfra # Additional development tools git diff --git a/pkgs/derivation.nix b/pkgs/derivation.nix index a2a4bb7b..708ef8e0 100644 --- a/pkgs/derivation.nix +++ b/pkgs/derivation.nix @@ -23,6 +23,8 @@ , mkdocs-material , mkdocstrings-python , mdx-truly-sane-lists +, oqd-compiler-infrastructure +, setuptools }: buildPythonPackage rec { @@ -50,6 +52,7 @@ buildPythonPackage rec { mkdocs-material mkdocstrings-python mdx-truly-sane-lists + setuptools ]; pythonImportsCheck = [ "oqd_core" ]; From 17d832e713f637b214e2b928e9d1521b0e7b4d07 Mon Sep 17 00:00:00 2001 From: Mahmoud Badawy Date: Mon, 19 May 2025 17:28:44 +0300 Subject: [PATCH 5/5] updating readme --- README.md | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e990a629..e32bf8e0 100644 --- a/README.md +++ b/README.md @@ -35,12 +35,23 @@ 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 (black, isort, mypy) -# - Documentation tools +# - 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: