Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
36 changes: 36 additions & 0 deletions .github/workflows/nix_environment_testing.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: nix-flake-test
on:
workflow_dispatch:
push:
branches: [ develop ]
pull_request:
branches:
- develop
jobs:
build-and-test:
runs-on: ubuntu-latest

steps:
# Step 1: Checkout the repository
- name: Checkout Repository
uses: actions/checkout@v3

# Step 2: Install Nix
- name: Install Nix with Extra Options
run: |
curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix/pr/1145 | sh -s -- install --no-confirm --extra-conf "
extra-substituters = https://openlane.cachix.org
extra-trusted-public-keys = openlane.cachix.org-1:qqdwh+QMNGmZAuyeQJTH9ErW57OWSvdtuwfBKdS254E=
"
# Step 3: Enable Nix Flakes
- name: Enable Nix Flakes
run: |
mkdir -p ~/.config/nix
echo "experimental-features = nix-command flakes" >> ~/.config/nix/nix.conf
# Step 5: Build the flake with no options
- name: Build Flake
run: nix build .

# Step 6: Run flake checks/tests
- name: Run Flake Checks
run: nix flake check
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ jobs:
- name: Run tests
run: |
source venv/bin/activate
uv run pytest -rA tests
python -m pytest -rA tests
2 changes: 1 addition & 1 deletion .github/workflows/test_notebooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ jobs:
- name: Run tests
run: |
source venv/bin/activate
uv run python docs/examples/run_all_notebooks.py
python docs/examples/run_all_notebooks.py
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,4 @@ RUN_*
*.sif
.idea/
docs/autoapi/
result
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

# All the imports we will need throughout this flows.

# +
# We begin by importing a parametric circuit from `gdsfactory`:
import hdl21 as h
import numpy as np
Expand All @@ -26,9 +25,6 @@
straight_heater_metal_simple,
)


# -

# First, let's set up the filesystem in the directory in which all our files will be generated and stored. This is really an extension of a full mixed-signal design compatible with the tools supported by `piel`.

current_example_directory = piel.return_path(".")
Expand Down Expand Up @@ -116,6 +112,7 @@ def create_switch_fabric():
chain_fock_state_transitions = piel.flows.get_state_phase_transitions(
circuit_component=chain_3_mode_lattice_circuit,
models=optical_logic_verification_models,
switch_states=[0, np.pi],
mode_amount=3,
target_mode_index=2,
)
Expand Down
115 changes: 53 additions & 62 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,126 +1,117 @@
# file: flake.nix
{
description = "Python application packaged using poetry2nix and additional EDA tools";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
poetry2nix.url = "github:nix-community/poetry2nix";
nix-eda.url = "github:efabless/nix-eda";
openlane2.url = "github:efabless/openlane2";
nix-eda.url = "github:efabless/nix-eda";
openlane2.url = "github:efabless/openlane2";
};

outputs = { self, nixpkgs, poetry2nix, nix-eda, openlane2 }:
let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
edaPkgs = import nix-eda { inherit pkgs; };
openlane = import openlane2 { inherit pkgs; };

# Correctly accessing nix-eda and openlane2 outputs
edaPkgs = nix-eda.packages.${system};
openlane = openlane2.packages.${system}.openlane; # Verify the exact output name

# Use the same Python version as OpenLane
python = pkgs.python311Full;

# create a custom "mkPoetryApplication" API function that under the hood uses
# the packages and versions (python3, poetry etc.) from our pinned nixpkgs above:
# Create a custom "mkPoetryApplication" using poetry2nix
inherit (poetry2nix.lib.mkPoetry2Nix { inherit pkgs; }) mkPoetryApplication defaultPoetryOverrides;

# Define build requirements for specific Python packages
pypkgs-build-requirements = {
rectpack = [ "setuptools" ];
vlsir = [ "setuptools" ];
vlsirtools = [ "setuptools" ];
hdl21 = [ "flit-core" ];
sky130-hdl21 = [ "flit-core" ];
gdsfactory = [ "flit-core" ];
sky130 = [ "flit-core" ];
thewalrus = [ "setuptools" ];
rectpack = [ "setuptools" ];
vlsir = [ "setuptools" ];
vlsirtools = [ "setuptools" ];
hdl21 = [ "flit-core" ];
sky130-hdl21 = [ "flit-core" ];
gdsfactory = [ "flit-core" ];
sky130 = [ "flit-core" ];
thewalrus = [ "setuptools" ];
};

# Extend default poetry overrides with custom build requirements
custom_overrides = defaultPoetryOverrides.extend (final: prev:
builtins.mapAttrs (package: build-requirements:
(builtins.getAttr package prev).overridePythonAttrs (old: {
buildInputs = (old.buildInputs or [ ]) ++ (builtins.map (pkg: if builtins.isString pkg then builtins.getAttr pkg prev else pkg) build-requirements);
buildInputs = (old.buildInputs or []) ++ (builtins.map (pkg: if builtins.isString pkg then builtins.getAttr pkg prev else pkg) build-requirements);
})
) pypkgs-build-requirements
);

# Define the main application using poetry2nix
app = mkPoetryApplication {
projectDir = ./.;
projectDir = ./.;
preferWheels = true;
extras = [] ;
overrides = custom_overrides;
python=python;
extras = [];
overrides = custom_overrides;
python = python;
};

# Test support for overriding the app passed to the environment
# Override app to depend on hatchling and scikit-build-core
# Override the application to include additional build inputs
overridden = app.overrideAttrs (old: {
name = "${old.pname}-overridden-${old.version}";
nativeBuildInputs = old.nativeBuildInputs or [] ++ [
name = "${old.pname}-overridden-${old.version}";
nativeBuildInputs = old.nativeBuildInputs or [] ++ [
pkgs.python3Packages.hatchling
pkgs.python3Packages.scikit-build-core
pkgs.python3Packages.scikit-learn
];
# Include scikit-build-core in propagatedBuildInputs to ensure it's available to dependencies
propagatedBuildInputs = old.propagatedBuildInputs or [] ++ [
pkgs.python3Packages.hatchling
pkgs.python3Packages.scikit-build-core
pkgs.python3Packages.scikit-learn
];
});

# Define a dependency environment
depEnv = app.dependencyEnv.override {
app = overridden;
};
packages.x86_64-linux.piel = nixpkgs.legacyPackages.x86_64-linux.piel;

in
{
packages.${system} = {
default = app;
python = python;
};
# Define packages
packages.${system} = {
default = app;
python = python;
};

apps.${system}.default = {
type = "app";
# replace <script> with the name in the [tool.poetry.scripts] section of your pyproject.toml
program = "${app}/bin/piel";
};
# Define applications
apps.${system}.default = {
type = "app";
program = "${app}/bin/piel"; # Ensure 'piel' is the correct entry script
};

shell.${system}.default = pkgs.mkShell {
# Define development shells
devShells.${system}.default = pkgs.mkShell {
buildInputs = [
pkgs.python3Full # Include Python 3
app
edaPkgs.ngspice
edaPkgs.xschem
edaPkgs.verilator
edaPkgs.yosys
openlane.openlane2
openlane
pkgs.verilog
pkgs.gtkwave
pkgs.uv # Added uv to buildInputs
];
# Optionally, set PYTHONPATH to include the app's path in other shells if needed
shellHook = ''
echo "Setting Piel-Nix Environment Up"
export PATH=${app}/bin:$PATH
export PATH=${app}/lib/python${python.version}/site-packages:$PATH
'';
};

devShells.${system}.default = pkgs.mkShell {
buildInputs = [
app
edaPkgs.ngspice
edaPkgs.xschem
edaPkgs.verilator
edaPkgs.yosys
openlane.openlane2
pkgs.verilog
pkgs.gtkwave
];
# Optionally, set PYTHONPATH to include the app's path in other shells if needed
shellHook = ''
echo "Setting Piel-Nix Environment Up"
export PATH=${app}/bin:$PATH
export PATH=${app}/lib/python${python.version}/site-packages:$PATH
echo "Setting Piel-Nix Environment Up"
export PATH=${app}/bin:$PATH
export PYTHONPATH=${app}/lib/python${python.version}/site-packages:$PYTHONPATH
alias python=python3 # Alias 'python' to 'python3'
python -m venv .venv
source .venv/bin/activate # Activate the virtual environment
echo "Virtual environment activated. Installing additional packages with pip..."
uv pip install -e .[dev]
'';
};

};
};
}
21 changes: 13 additions & 8 deletions piel/flows/electro_optic.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import jax.numpy as jnp # TODO add typing
import logging
from itertools import product
from typing import Optional, Callable, Any
from ..types import (
Expand All @@ -23,6 +24,8 @@
from ..models.frequency.defaults import get_default_models
from ..integration.thewalrus_qutip import fock_transition_probability_amplitude

logger = logging.getLogger(__name__)


def compose_phase_address_state(
switch_instance_map: dict,
Expand Down Expand Up @@ -196,7 +199,7 @@ def calculate_classical_transition_probability_amplitudes(
)
else:
classical_transition_target_mode_probability = None
print(
logger.debug(
ValueError(
"No target mode index provided and no method to determine it. Will continue."
)
Expand Down Expand Up @@ -298,6 +301,8 @@ def compose_network_matrix_from_models(
switch_fabric_switch_phase_configurations = dict()
switch_amount = len(switch_instance_list_i)
switch_instance_valid_phase_configurations_i = []
logger.debug("switch_states")
logger.debug(switch_states)
for phase_configuration_i in product(switch_states, repeat=switch_amount):
switch_instance_valid_phase_configurations_i.append(phase_configuration_i)

Expand Down Expand Up @@ -495,13 +500,13 @@ def generate_s_parameter_circuit_from_photonic_circuit(
netlist[specific_model_key],
models=models,
)
print("Error in generating S-parameters. Check the following:")
print("Required measurement for the top-level circuit:")
print(required_models)
print("Required measurement for the specific model:")
print(specific_model_key)
print("Required measurement for the specific model:")
print(specific_model_required)
logger.error("Error in generating S-parameters. Check the following:")
logger.error("Required measurement for the top-level circuit:")
logger.error(required_models)
logger.error("Required measurement for the specific model:")
logger.error(specific_model_key)
logger.error("Required measurement for the specific model:")
logger.error(specific_model_required)

raise e

Expand Down
Loading