Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add nix support #918

Merged
merged 61 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
38206b8
Avoid compilation error due to a maybe-uninitialized false-positive i…
jake-arkinstall-quantinuum Jul 3, 2023
9862614
Added breaks to SteinerTree switches to emphasise that switches will …
jake-arkinstall-quantinuum Jul 3, 2023
ad1db03
Imported size_t into the global namespace
jake-arkinstall-quantinuum Jul 3, 2023
a9c419d
Added default.nix for tklog.
jake-arkinstall-quantinuum Jul 3, 2023
5857113
Added default.nix to tkassert.
jake-arkinstall-quantinuum Jul 3, 2023
25c9083
Added default.nix to tkrng
jake-arkinstall-quantinuum Jul 3, 2023
ea9cbde
Add default.nix to tktokenswap
jake-arkinstall-quantinuum Jul 3, 2023
ea71d91
Add default.nix to tkwsm
jake-arkinstall-quantinuum Jul 3, 2023
8f4e385
Add default.nix for the full libs directory.
jake-arkinstall-quantinuum Jul 3, 2023
7955c03
Added default.nix to tket.
jake-arkinstall-quantinuum Jul 3, 2023
347f7f7
Added trivial flake.nix and flake.lock to overall project.
jake-arkinstall-quantinuum Jul 3, 2023
4622efc
Discarded overlay approach to flake.nix for now
jake-arkinstall-quantinuum Jul 3, 2023
1da6299
First steps towards building pytket with Nix.
jake-arkinstall-quantinuum Jul 3, 2023
a07df8b
Added an accidently-removed print statement back to pytket's setup.py…
jake-arkinstall-quantinuum Jul 3, 2023
ed04d80
Further progress on building pytket with nix.
jake-arkinstall-quantinuum Jul 4, 2023
9c04701
Removed partially-written test derivation from pytket's default.nix
jake-arkinstall-quantinuum Jul 4, 2023
359b739
Added devShell to flake.nix, loaded with tket and pytket
jake-arkinstall-quantinuum Jul 4, 2023
da2421c
Added static parameter to each C++ build file, allowing static or sha…
jake-arkinstall-quantinuum Jul 4, 2023
a289d01
Specify the correct location for binders dependencies in setup.py
jake-arkinstall-quantinuum Jul 4, 2023
e84979b
Merge branch 'CQCL:develop' into nix-support
jake-arkinstall-quantinuum Jul 5, 2023
5cf67d2
Several fixes to get pytket working
jake-arkinstall-quantinuum Jul 5, 2023
94a5ec1
Patch symengine's cmake to avoid the need for messing with the dynami…
jake-arkinstall-quantinuum Jul 6, 2023
e11a443
Merge branch 'CQCL:develop' into nix-support
jake-arkinstall-quantinuum Jul 6, 2023
62a9e22
Missed changes from previous commit.
jake-arkinstall-quantinuum Jul 7, 2023
52eb341
Moved all nix files into a nix-support directory, swapped to using fi…
jake-arkinstall-quantinuum Jul 7, 2023
fce8f9e
Removed Steiner Tree switch fix for inclusion in a different PR
jake-arkinstall-quantinuum Jul 7, 2023
7b53030
Removed size_t fix for inclusion in a different PR
jake-arkinstall-quantinuum Jul 7, 2023
01bbde3
Merge branch 'CQCL:develop' into nix-restructure
jake-arkinstall-quantinuum Jul 7, 2023
1386c4c
Trial adding tket tests derivation, adding it to the flake as a check…
jake-arkinstall-quantinuum Jul 7, 2023
4b2c2cd
Merge branch 'CQCL:develop' into nix-restructure
jake-arkinstall-quantinuum Jul 7, 2023
61fac82
Added test running to flake checks, swapped tket-tests to use the sha…
jake-arkinstall-quantinuum Jul 7, 2023
59448a6
Removed static libraries entirely. Now going full shared, which simpl…
jake-arkinstall-quantinuum Jul 7, 2023
eb2a54c
Formatted nix files with nixfmt
jake-arkinstall-quantinuum Jul 7, 2023
39953ec
Merge pull request #1 from jake-arkinstall-quantinuum/origin/nix-shar…
jake-arkinstall-quantinuum Jul 7, 2023
9510c26
Removed duplicate Wno-error on maybe-ununinitialized (a reminant of a…
jake-arkinstall-quantinuum Jul 7, 2023
40cdc4c
Provide devShells.default instead of the deprecated devShell
jake-arkinstall-quantinuum Jul 7, 2023
99d37e2
Merge branch 'develop' into nix-restructure
cqc-alec Jul 10, 2023
be0a381
Update tket/test/src/TokenSwapping/test_BestTsaFixedSwapSequences.cpp
cqc-alec Jul 10, 2023
73ce3f0
Satisfy black checks.
cqc-alec Jul 10, 2023
66e9710
Update pytket/setup.py
cqc-alec Jul 10, 2023
9cd4605
Update pytket/setup.py
cqc-alec Jul 10, 2023
edc4c2c
Merge branch 'develop' into nix-restructure
cqc-alec Jul 10, 2023
a3d89e7
Merge branch 'CQCL:develop' into nix-restructure
jake-arkinstall-quantinuum Jul 12, 2023
09ef93a
Added python tests and readme placeholder
jake-arkinstall-quantinuum Jul 12, 2023
82dc437
Add example flake project and nix-support README content.
jake-arkinstall-quantinuum Jul 12, 2023
e32699b
Fix README typo in nix-support examples
jake-arkinstall-quantinuum Jul 12, 2023
857e2a5
Clarify nix run location in the example flake project README
jake-arkinstall-quantinuum Jul 12, 2023
1816ccd
Merge branch 'CQCL:develop' into nix-restructure
jake-arkinstall-quantinuum Jul 12, 2023
932b30c
Modified build-with-nix.yaml to run on both Ubuntu 22.04 and MacOS 12
jake-arkinstall-quantinuum Jul 12, 2023
49b7223
Corrected symengine patch to correctly expose its link dependencies t…
jake-arkinstall-quantinuum Jul 12, 2023
d6d9e01
Added all tk libraries to pytket install directory for MacOS compatib…
jake-arkinstall-quantinuum Jul 12, 2023
a550cdb
Merge conflicts resolved
jake-arkinstall-quantinuum Oct 12, 2023
28164b3
Merge branch 'upstream-merge' into nix-restructure
jake-arkinstall-quantinuum Oct 12, 2023
385ea38
Fixed PassLibrary.hpp include path in tket/test/src/test_PhasePolynom…
jake-arkinstall-quantinuum Oct 12, 2023
cce9188
Merge branch 'CQCL:develop' into nix-restructure
jake-arkinstall-quantinuum Oct 19, 2023
e716ab0
Several fixes for Nix builds on MacOS. Removed @loader_path usage whe…
jake-arkinstall-quantinuum Oct 19, 2023
c5c8e10
Added flat_namespace linker flag (Apple only) to the main tket build …
jake-arkinstall-quantinuum Oct 19, 2023
28dee05
Pinned jsonschema to v4.18.0, resulting in passing serialisation tests
jake-arkinstall-quantinuum Oct 19, 2023
d0f738c
Reformatted nix example 'basic_circuits.py' to adhere to lint policy
jake-arkinstall Oct 19, 2023
4e7d5cd
Bump tket version.
cqc-alec Oct 20, 2023
6fa5dd0
Reformat.
cqc-alec Oct 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/build-with-nix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: build with nix
on:
schedule:
# 01:00 every Sunday morning
- cron: '0 1 * * 0'
workflow_dispatch: {}
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build_and_test:
strategy:
matrix:
os: ['ubuntu-22.04', 'macos-12']
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v20
- name: Build and test tket
run: nix flake check
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*.egg-info
*.o
*.so
*.swp
.cache
.eggs
.hypothesis
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ building and testing tket as a standalone C++ library.
See the [README](pytket/README.md) in the `pytket` directory for instructions on
building and testing pytket.

### Nix Support

Tket and pytket are available as a Nix flake. See the [README](nix-support/README.md)
in the `nix-support` directory for instructions on building and testing tket and pytket
through Nix, and on how to use it within a Nix project.

## API documentation

The `tket` (C++) API documentation (generated with `doxygen`, and still rather
Expand Down
60 changes: 60 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
description = "Tket Quantum SDK";
inputs.nixpkgs.url = "github:nixos/nixpkgs";
inputs.flake-utils.url = "github:numtide/flake-utils";
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [
(import ./nix-support/libs.nix)
(import ./nix-support/symengine.nix)
(import ./nix-support/tket.nix)
(import ./nix-support/third-party-python-packages.nix)
(import ./nix-support/pytket.nix)
];
};
in {
packages = {
tket = pkgs.tket;
pytket = pkgs.pytket;
};
devShells = {
default = pkgs.mkShell { buildInputs = [ pkgs.tket pkgs.pytket ]; };
};
checks = {
tket-tests = pkgs.run-tket-tests;
pytket-tests = pkgs.pytket;
};
});
}
7 changes: 6 additions & 1 deletion libs/tkassert/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ find_package(tklog CONFIG REQUIRED)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_EXTENSIONS OFF)

option(INSTALL_NAME_DIR "Set the install name dir for the library to @loader_path for Apple targets" ON)

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
Expand All @@ -35,7 +37,7 @@ if(WIN32)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS yes)
endif()

if(APPLE)
if(APPLE AND INSTALL_NAME_DIR)
set(CMAKE_INSTALL_NAME_DIR "@loader_path")
set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON)
endif()
Expand Down Expand Up @@ -64,6 +66,9 @@ target_include_directories(tkassert PUBLIC
$<INSTALL_INTERFACE:include/tkassert>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/tkassert>)
target_link_libraries(tkassert PRIVATE tklog::tklog)
IF(APPLE)
target_link_libraries(tkassert PRIVATE "-flat_namespace")
ENDIF()

target_sources(tkassert
PRIVATE src/AssertMessage.cpp
Expand Down
8 changes: 7 additions & 1 deletion libs/tklog/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_SOURCE_DIR}/cmake)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_EXTENSIONS OFF)

option(INSTALL_NAME_DIR "Set the install name dir for the library to @loader_path for Apple targets" ON)

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
Expand All @@ -33,7 +35,7 @@ if(WIN32)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS yes)
endif()

if(APPLE)
if(APPLE AND INSTALL_NAME_DIR)
set(CMAKE_INSTALL_NAME_DIR "@loader_path")
set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON)
endif()
Expand Down Expand Up @@ -62,6 +64,10 @@ target_include_directories(tklog PUBLIC
$<INSTALL_INTERFACE:include/tklog>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/tklog>)

IF(APPLE)
target_link_libraries(tklog PRIVATE "-flat_namespace")
ENDIF()

target_sources(tklog
PRIVATE src/TketLog.cpp
PUBLIC FILE_SET HEADERS
Expand Down
7 changes: 6 additions & 1 deletion libs/tkrng/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_SOURCE_DIR}/cmake)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_EXTENSIONS OFF)

option(INSTALL_NAME_DIR "Set the install name dir for the library to @loader_path for Apple targets" ON)

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
Expand All @@ -33,7 +35,7 @@ if(WIN32)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS yes)
endif()

if(APPLE)
if(APPLE AND INSTALL_NAME_DIR)
set(CMAKE_INSTALL_NAME_DIR "@loader_path")
set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON)
endif()
Expand Down Expand Up @@ -62,6 +64,9 @@ target_include_directories(tkrng PUBLIC
$<INSTALL_INTERFACE:include/tkrng>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/tkrng>)

IF(APPLE)
target_link_libraries(tkrng PRIVATE "-flat_namespace")
ENDIF()
target_sources(tkrng
PRIVATE src/RNG.cpp
PUBLIC FILE_SET HEADERS
Expand Down
8 changes: 7 additions & 1 deletion libs/tktokenswap/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ find_package(Boost CONFIG REQUIRED)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_EXTENSIONS OFF)

option(INSTALL_NAME_DIR "Set the install name dir for the library to @loader_path for Apple targets" ON)

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
Expand All @@ -38,7 +40,7 @@ if(WIN32)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS yes)
endif()

if(APPLE)
if(APPLE AND INSTALL_NAME_DIR)
set(CMAKE_INSTALL_NAME_DIR "@loader_path")
set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON)
endif()
Expand Down Expand Up @@ -71,6 +73,10 @@ target_link_libraries(tktokenswap PRIVATE tkassert::tkassert)
target_link_libraries(tktokenswap PRIVATE tkrng::tkrng)
target_link_libraries(tktokenswap PRIVATE Boost::headers)

IF(APPLE)
target_link_libraries(tktokenswap PRIVATE "-flat_namespace")
ENDIF()

target_sources(tktokenswap
PRIVATE
src/BestFullTsa.cpp
Expand Down
8 changes: 7 additions & 1 deletion libs/tkwsm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ find_package(Boost CONFIG REQUIRED)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_EXTENSIONS OFF)

option(INSTALL_NAME_DIR "Set the install name dir for the library to @loader_path for Apple targets" ON)

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
Expand All @@ -38,7 +40,7 @@ if(WIN32)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS yes)
endif()

if(APPLE)
if(APPLE AND INSTALL_NAME_DIR)
set(CMAKE_INSTALL_NAME_DIR "@loader_path")
set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON)
endif()
Expand Down Expand Up @@ -69,6 +71,9 @@ target_include_directories(tkwsm PUBLIC
target_link_libraries(tkwsm PRIVATE tkassert::tkassert)
target_link_libraries(tkwsm PRIVATE tkrng::tkrng)
target_link_libraries(tkwsm PRIVATE Boost::headers)
IF(APPLE)
target_link_libraries(tkwsm PRIVATE "-flat_namespace")
ENDIF()

target_sources(tkwsm
PRIVATE
Expand Down Expand Up @@ -157,6 +162,7 @@ target_sources(tkwsm
include/tkwsm/WeightPruning/WeightNogoodDetectorManager.hpp
)


include(GNUInstallDirs)
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/tkwsm)

Expand Down
33 changes: 33 additions & 0 deletions nix-support/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Nix support for tket and pytket

Tket exposes a Nix flake that you can build, test and use within a Nix environment.
To build and test tket and pytket on your local system, you can run

```
$ nix flake check github:CQCL/tket
```

This will take some time, as it requires the building of a patched symengine,
the compilation of tket and tket tests, and the compilation of pytket's dependencies,
before testing.

You can enter a development environment with tket and pytket available
with use of `nix develop`. For example,

```
$ nix develop github:CQCL/tket

$ python3
Python 3.10.12 (main, Jun 6 2023, 22:43:10) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pytket import Circuit
>>> circuit = Circuit(5)
>>> circuit.X(1)
[X q[1]; ]
>>> circuit.X(2)
[X q[1]; X q[2]; ]
```

You can also use tket and pytket within your own flake project.
An example of such a project is given in the [example-flake-project](example-flake-project)
directory.
18 changes: 18 additions & 0 deletions nix-support/example-flake-project/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Example flake project

In this example, we create a [flake.nix](flake.nix) file that tells Nix
where to fetch nixpkgs, flake-utils and tket. It also builds an example
application, using [pyproject.toml](pyproject.toml) and the
[src](src) directory. This application [exposes](src/examples/basic_circuits.py)
two scripts: `entanglement` and `teleport`, that set up trivial circuits
and display them in your browser.

To run these scripts, simply run the following commands from within this directory:

```
nix run .#entanglement
```
and
```
nix run .#teleport
```
45 changes: 45 additions & 0 deletions nix-support/example-flake-project/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-23.05";
inputs.flake-utils.url = "github:numtide/flake-utils";
# fetch tket from github
inputs.tket.url = "github:CQCL/tket";

outputs = { self, nixpkgs, flake-utils, tket }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [
(self: super: {
# add tket and pytket to pkgs for later use
tket = tket.packages.${system}.tket;
pytket = tket.packages.${system}.pytket;
})
];
};
examples = pkgs.python3Packages.buildPythonApplication {
pname = "examples";
version = "0.0.1";
format = "pyproject";
# copy pyproject.toml and src to the build directory
unpackPhase = ''
cp ${./pyproject.toml} pyproject.toml
cp -r ${./src} src
chmod 700 src;
'';
# provide pytket as a dependency
propagatedBuildInputs = [ pkgs.pytket ];
};
in {
apps = {
entanglement = {
type = "app";
program = "${examples}/bin/entanglement";
};
teleport = {
type = "app";
program = "${examples}/bin/teleport";
};
};
});
}
9 changes: 9 additions & 0 deletions nix-support/example-flake-project/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[project]
name = "examples"
version = "0.0.1"
dependencies = ["pytket"]

[project.scripts]
entanglement = "examples.basic_circuits:entanglement_circuit"
teleport = "examples.basic_circuits:teleport_circuit"

Empty file.
Loading
Loading