Skip to content

Commit

Permalink
Merge pull request #4 from boblinchuan/without_OA
Browse files Browse the repository at this point in the history
Merging without_OA and develop branches
  • Loading branch information
boblinchuan authored Jul 23, 2024
2 parents ffccf4c + 70cbcd1 commit 7e75897
Show file tree
Hide file tree
Showing 22 changed files with 725 additions and 599 deletions.
97 changes: 97 additions & 0 deletions .github/workflows/conda_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Testing if we can install Conda successfully. Sanity checking the CI flow.
name: conda-test

on: [push]

env:
CONDA_ENV_NAME: conda_test

jobs:
conda-cache:
runs-on: ubuntu-20.04
defaults:
run:
shell: bash -el {0}
continue-on-error: true
outputs:
pytestOutput: ${{ steps.unit-tests.outputs.test }}
strategy:
matrix:
python-version: ["3.7"]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
- name: Setup conda
uses: conda-incubator/[email protected]
with:
activate-environment: ${{ env.CONDA_ENV_NAME }}
python-version: ${{ matrix.python-version }}
auto-activate-base: false
- name: Save Conda Env
# Workaround, this isn't working otherwise.
run: |
echo "CONDA=$CONDA"
echo "CONDA=$CONDA" >> "$GITHUB_ENV"
- name: Cache Conda env
uses: actions/cache@v3
with:
path: ${{ env.CONDA }}/envs/${{ env.CONDA_ENV_NAME }}
key:
conda-test-conda-${{ runner.os }}--${{ runner.arch }}--${{
steps.get-date.outputs.today }}-${{
hashFiles('conda_test.yml') }}-${{
env.CACHE_NUMBER }}
env:
CACHE_NUMBER: 0
id: cache
- name: Update environment
run: |
echo "CONDA=$CONDA"
conda env update -n ${{ env.CONDA_ENV_NAME }} -f conda_test.yml
ls $CONDA/envs/
if: steps.cache.outputs.cache-hit != 'true'
conda-cache-load:
needs: conda-cache
runs-on: ubuntu-20.04
defaults:
run:
shell: bash -el {0}
continue-on-error: true
outputs:
pytestOutput: ${{ steps.unit-tests.outputs.test }}
strategy:
matrix:
python-version: ["3.7"]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
- name: Setup conda
uses: conda-incubator/[email protected]
with:
activate-environment: ${{ env.CONDA_ENV_NAME }}
python-version: ${{ matrix.python-version }}
auto-activate-base: false
- name: Save Conda Env
# Workaround, this isn't working otherwise.
run: |
echo "CONDA=$CONDA"
echo "CONDA=$CONDA" >> "$GITHUB_ENV"
- name: Cache Conda env
uses: actions/cache@v3
with:
path: ${{ env.CONDA }}/envs/${{ env.CONDA_ENV_NAME }}
key:
conda-test-conda-${{ runner.os }}--${{ runner.arch }}--${{
steps.get-date.outputs.today }}-${{
hashFiles('conda_test.yml') }}-${{
env.CACHE_NUMBER }}
env:
CACHE_NUMBER: 0
id: cache
- name: Fail
run: exit 1
if: steps.cache.outputs.cache-hit != 'true'
157 changes: 157 additions & 0 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# CI flow
name: pybag-pr-ci

on:
push:
schedule:
- cron: '0 9 * * *' # 9AM UTC = 2AM PST

env:
CONDA_ENV_NAME: bag_py3d7_c

jobs:
build:
runs-on: ubuntu-20.04
defaults:
run:
shell: bash -el {0}
continue-on-error: true
outputs:
pytestOutput: ${{ steps.unit-tests.outputs.test }}
strategy:
matrix:
python-version: ["3.7"]
steps:
- name: Install packages
run: |
sudo apt update
sudo apt -y install \
autoconf \
curl \
gcc-8 \
g++-8 \
git \
libtool \
libltdl-dev \
pkg-config \
make \
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive
- name: Setup conda
uses: conda-incubator/[email protected]
with:
activate-environment: ${{ env.CONDA_ENV_NAME }}
python-version: ${{ matrix.python-version }}
auto-activate-base: false
- name: Save Conda Env
# Workaround, this isn't working otherwise.
run: |
echo "CONDA=$CONDA"
echo "CONDA=$CONDA" >> "$GITHUB_ENV"
- name: Cache Conda env
uses: actions/cache@v3
with:
path: ${{ env.CONDA }}/envs/${{ env.CONDA_ENV_NAME }}
key:
conda-${{ runner.os }}--${{ runner.arch }}--${{
steps.get-date.outputs.today }}-${{
hashFiles('environment.yml') }}-${{
env.CACHE_NUMBER }}
env:
# Increase this value to reset cache if etc/example-environment.yml has not changed
CACHE_NUMBER: 0
id: cache-conda
- name: Update conda environment
run: |
echo "CONDA=$CONDA"
conda env update -n ${{ env.CONDA_ENV_NAME }} -f environment.yml
if: steps.cache-conda.outputs.cache-hit != 'true'
- name: Install additional dependencies
if: steps.cache-conda.outputs.cache-hit != 'true'
run: |
cd setup
mkdir install
cp setup_script.sh install/
cp render_template.py install/
cp project-config.template install/
cd install
./setup_script.sh
cd ../../
- name: Build cbag and pybag
id: cpp-build
run: |
export PYBAG_PYTHON=python
echo "PYBAG_PYTHON=$PYBAG_PYTHON"
./run_test.sh
- name: Cache pybag build
uses: actions/cache@v3
with:
path: _build
key:
build-${{ runner.os }}--${{ runner.arch }}--${{
steps.get-date.outputs.today }}-${{
env.CACHE_NUMBER }}
env:
# Increase this value to reset cache if etc/example-environment.yml has not changed
CACHE_NUMBER: 0
id: cache-pybag
test:
needs: build
runs-on: ubuntu-20.04
defaults:
run:
shell: bash -el {0}
continue-on-error: true
outputs:
pytestOutput: ${{ steps.unit-tests.outputs.test }}
strategy:
matrix:
python-version: ["3.7"]
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive
- name: Setup conda
uses: conda-incubator/[email protected]
with:
activate-environment: bag_py3d7_c
python-version: ${{ matrix.python-version }}
auto-activate-base: false
- name: Save Conda Env
# Workaround, this isn't working otherwise.
run: |
echo "CONDA=$CONDA"
echo "CONDA=$CONDA" >> "$GITHUB_ENV"
- name: Cache Conda env
uses: actions/cache@v3
with:
path: ${{ env.CONDA }}/envs/${{ env.CONDA_ENV_NAME }}
key:
conda-${{ runner.os }}--${{ runner.arch }}--${{
steps.get-date.outputs.today }}-${{
hashFiles('environment.yml') }}-${{
env.CACHE_NUMBER }}
env:
# Increase this value to reset cache if etc/example-environment.yml has not changed
CACHE_NUMBER: 0
id: cache-conda
- name: Cache pybag build
uses: actions/cache@v3
with:
path: _build
key:
build-${{ runner.os }}--${{ runner.arch }}--${{
steps.get-date.outputs.today }}-${{
env.CACHE_NUMBER }}
env:
# Increase this value to reset cache if etc/example-environment.yml has not changed
CACHE_NUMBER: 0
id: cache-pybag
- name: Run test
id: run-pytest
run: |
which pytest
pytest tests -v
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ __pycache__
# build related files
_build
.pytest_cache
src/pybag/core.pyi
30 changes: 29 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ add_subdirectory(pybind11_generics)
find_package(yaml-cpp REQUIRED CONFIG)

# add python bindings for cbag
pybind11_add_module(core
if(DEFINED ENV{OA_LINK_DIR})
# Optionally support OA libraries
message("INFO: Building pybag with OpenAccess support.")
message("OA include directory: " $ENV{OA_INCLUDE_DIR})
message("OA link directory: " $ENV{OA_LINK_DIR})
pybind11_add_module(core
${CMAKE_CURRENT_SOURCE_DIR}/src/pybag/bbox.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/pybag/bbox_array.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/pybag/bbox_collection.cpp
Expand All @@ -111,6 +116,29 @@ pybind11_add_module(core
${CMAKE_CURRENT_SOURCE_DIR}/src/pybag/tech.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/pybag/transform.cpp
)
target_compile_definitions(core PUBLIC OA_LINK_DIR=$ENV{OA_LINK_DIR})
else()
message("INFO: Building pybag without OpenAccess support.")
pybind11_add_module(core
${CMAKE_CURRENT_SOURCE_DIR}/src/pybag/bbox.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/pybag/bbox_array.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/pybag/bbox_collection.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/pybag/core.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/pybag/enum_conv.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/pybag/gds.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/pybag/geometry.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/pybag/grid.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/pybag/interval.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/pybag/lay_objects.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/pybag/layout.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/pybag/logging.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/pybag/name.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/pybag/rtree.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/pybag/schematic.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/pybag/tech.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/pybag/transform.cpp
)
endif()

target_include_directories(core
PUBLIC
Expand Down
28 changes: 25 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
# PYBAG

Python wrapper for [CBAG](https://github.com/bluecheetah/cbag) library.
Python wrapper for [cbag](https://github.com/ucb-art/cbag) library for BAG3++.

This is a fork of [PYBAG] (https://github.com/ucb-art/pybag), which as of May 13th, 2019,
has been taken offline temporarily.
Pybag provides `enum.py` and `core.pyi` as an interface between `BAG` and `cbag`.
`core.pyi` is created during `cbag` compilation and is not tracked by Git.

## Setup

This library should be used with [BAG3++](https://github.com/ucb-art/bag). To setup BAG, follow the instructions outlined on the [RTD page](https://bag3-readthedocs.readthedocs.io/en/latest/dependencies/).

Alternative, if you are using Ubuntu, you can use the `setup_script.sh` under the `setup` directory. This runs the steps described in the RTD page above. See the `setup/README.md` for discussion.

To build the `pybag` library, run `./run_test.sh`. This will compile `cbag` as well as create the `pybag` Python wrappers for `BAG`.

Running `./run_test.sh`requires the `PYBAG_PYTHON` environment variable be set to the Python from your Miniconda install from the setup process.

### Building with OpenAccess Libraries

Pybag (and the underlying cbag) can be compiled with the OpenAccess (OA) C++ libraries from Si2 to provide minor acceleration in creating OA views for tools such as Cadence Virtuoso. These libraries are **NOT required** for using BAG in general. If the OA libraries are not included, BAG can still create OA views using SKILL commands.

To compile with these libraries, the following environment variables must be set:
- `OA_INCLUDE_DIR`: Include directory.
- `OA_LINK_DIR`: Link directory.

Compiling with the OA libraries will add the `PyOADatabase` class to `core.pyi` after compile time. If `PyOADatabase` does not exist, then you did not compile with the OA libraries.

Pybag has been tested with the OpenAccess 2.2 API. These features are included for legacy compatibility and are not actively maintained.

## Licensing

Expand Down
5 changes: 3 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@

if [ -z ${OA_LINK_DIR+x} ]
then
echo "OA_LINK_DIR is unset"
exit 1
echo "OA_LINK_DIR is unset. Building pybag without OpenAccess support."
else
echo "OA_LINK_DIR is set. Building pybag with OpenAccess support."
fi

if [ -z ${PYBAG_PYTHON+x} ]
Expand Down
5 changes: 3 additions & 2 deletions build_util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@

if [ -z ${OA_LINK_DIR+x} ]
then
echo "OA_LINK_DIR is unset"
exit 1
echo "OA_LINK_DIR is unset. Building pybag without OpenAccess support."
else
echo "OA_LINK_DIR is set. Building pybag with OpenAccess support."
fi

export NUM_CORES=$(nproc --all)
Expand Down
8 changes: 8 additions & 0 deletions conda_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: conda_test
channels:
- anaconda
- conda-forge
- defaults
dependencies:
- numpy-base>=1.21.5

Loading

0 comments on commit 7e75897

Please sign in to comment.