Skip to content
Open
Show file tree
Hide file tree
Changes from 10 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: 28 additions & 8 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,15 @@
cache: pip
cache-dependency-path: |
requirements.txt
dev-requirements.txt
pyproject.toml

- name: Upgrade pip
run: python -m pip install --upgrade pip

Check warning

Code scanning / Scorecard

Pinned-Dependencies Medium

score is 2: pipCommand not pinned by hash
Click Remediation section below to solve this issue
- name: Install dependencies

Check warning

Code scanning / Scorecard

Pinned-Dependencies Medium

score is 2: pipCommand not pinned by hash
Click Remediation section below to solve this issue
run: pip install -r requirements.txt -r dev-requirements.txt
run: |
pip install -r requirements.txt
pip install --group dev
Comment on lines +83 to +84
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is better to run these together in one pip process.
That way any shared dependencies would need to resolve consistently for both requirements.txt and the dev group.


- name: Check format
continue-on-error: ${{inputs.soft-linting == 'true'}}
Expand Down Expand Up @@ -237,10 +242,15 @@
cache: pip
cache-dependency-path: |
requirements.txt
dev-requirements.txt
pyproject.toml

- name: Upgrade pip
run: python -m pip install --upgrade pip

- name: Install dependencies
run: pip install -r requirements.txt -r dev-requirements.txt
run: |
pip install -r requirements.txt
pip install --group dev

- name: Set up Bazel
uses: './.github/actions/set-up-bazel'
Expand Down Expand Up @@ -320,12 +330,17 @@
with:
python-version: ${{env.python-version}}
cache: pip
cache-dependency-path: |

Check warning

Code scanning / Scorecard

Pinned-Dependencies Medium

score is 2: pipCommand not pinned by hash
Click Remediation section below to solve this issue
requirements.txt

Check warning

Code scanning / Scorecard

Pinned-Dependencies Medium

score is 2: pipCommand not pinned by hash
Click Remediation section below to solve this issue
dev-requirements.txt
pyproject.toml

- name: Upgrade pip
run: python -m pip install --upgrade pip

- name: Install dependencies
run: pip install -r requirements.txt -r dev-requirements.txt
run: |
pip install -r requirements.txt
pip install --group dev

- name: Set up Bazel
uses: './.github/actions/set-up-bazel'
Expand Down Expand Up @@ -372,15 +387,20 @@

- name: Set up Python
uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v5
with:

Check warning

Code scanning / Scorecard

Pinned-Dependencies Medium

score is 2: pipCommand not pinned by hash
Click Remediation section below to solve this issue
python-version: ${{env.python-version}}

Check warning

Code scanning / Scorecard

Pinned-Dependencies Medium

score is 2: pipCommand not pinned by hash
Click Remediation section below to solve this issue
cache: pip
cache-dependency-path: |
requirements.txt
dev-requirements.txt
pyproject.toml

- name: Upgrade pip
run: python -m pip install --upgrade pip

- name: Install dependencies
run: pip install -r requirements.txt -r dev-requirements.txt
run: |
pip install -r requirements.txt
pip install --group dev

- name: Set up Bazel
uses: './.github/actions/set-up-bazel'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/cirq_compatibility.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ jobs:
cache: pip
cache-dependency-path: |
requirements.txt
dev-requirements.txt
pyproject.toml

- name: Install latest dev version of Cirq
run: pip install --upgrade cirq~=1.0.dev

- name: Install qsim dev requirements
run: |
pip install -r requirements.txt
pip install -r dev-requirements.txt
pip install --group dev

- name: Run Python tests
env:
Expand Down
14 changes: 8 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,23 @@ COPY ./lib/ /qsim/lib/
COPY ./pybind_interface/ /qsim/lib/
COPY ./qsimcirq_tests/ /qsim/qsimcirq_tests/
COPY ./requirements.txt /qsim/requirements.txt
COPY ./dev-requirements.txt /qsim/dev-requirements.txt
COPY ./pyproject.toml /qsim/pyproject.toml

# Create venv to avoid collision between system packages and what we install.
RUN python3 -m venv --upgrade-deps test_env
RUN python3 -m venv --upgrade-deps test_env && \
. test_env/bin/activate
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not very familiar with docker, but if every RUN invokes a new shell, the activate has no effect and can be dropped:

Suggested change
. test_env/bin/activate


WORKDIR /qsim/

# Activate venv.
ENV PATH="/test_env/bin:$PATH"

# Install qsim requirements.
# hadolint ignore=DL3042
RUN python3 -m pip install -r /qsim/requirements.txt && \
python3 -m pip install -r /qsim/dev-requirements.txt
# hadolint ignore=DL3013
RUN python3 -m pip install --no-cache-dir --upgrade pip && \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think upgrade of pip should be unnecessary after venv --upgrade-deps above.

python3 -m pip install --no-cache-dir -r requirements.txt

# Compile qsim.
WORKDIR /qsim/
RUN make -j qsim

ENTRYPOINT ["/qsim/apps/qsim_base.x"]
1 change: 0 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
include requirements.txt
include dev-requirements.txt
include CMakeLists.txt

graft pybind_interface
Expand Down
12 changes: 0 additions & 12 deletions dev-requirements.txt

This file was deleted.

20 changes: 13 additions & 7 deletions docs/install_qsimcirq.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,24 @@ directly in C++ code without building and installing the qsimcirq interface.

## Before installation

Prior to installation, consider opening a
Prior to installation, consider creating a
[virtual environment](https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/).

Prerequisites are included in the
Prerequisites for installing and running qsim are included in the
[`requirements.txt`](https://github.com/quantumlib/qsim/blob/main/requirements.txt)
file, and will be automatically installed along with qsimcirq.
file, and will be automatically installed along with qsimcirq when you install
it with pip.

If you'd like to develop qsimcirq, a separate set of dependencies are includes
If you'd like to develop qsimcirq, a separate set of dependencies are defined
in the
[`dev-requirements.txt`](https://github.com/quantumlib/qsim/blob/main/dev-requirements.txt)
file. You can install them with `pip3 install -r dev-requirements.txt` or
`pip3 install qsimcirq[dev]`.
[`pyproject.toml`](https://github.com/quantumlib/qsim/blob/main/pyproject.toml)
file. Using pip version 25.1 or higher, you can install them with the following
commands:

```shell
pip install -r requirements.txt
pip install --group dev
Comment on lines +28 to +29
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider joining these in one pip command.

```

## Linux installation

Expand Down
4 changes: 4 additions & 0 deletions pybind_interface/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,9 @@
# Build pybind code early to cache the results
RUN make -j -C /qsim/ pybind

# Install Python development dependencies.
# hadolint ignore=DL3013
RUN pip install --no-cache-dir --group dev

# Compile and run qsim tests
ENTRYPOINT ["make", "-C", "/qsim/", "run-py-tests"]
129 changes: 118 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,135 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# Note: there are altogether 3 types of dependencies listed in this file:
#
# [build-system].requires: the packages needed for the build system. This list
# is not stored in the package metadata.
#
# [project].dependencies: other packages are minimally needed to be able to
# install and run qsimcirq. These are things like Cirq, NumPy, etc. Equivalent
# to "install_requires" in setuptools' setup.py. The list gets stored in the
# metadata of the package; when the project is installed by pip, this is the
# specification that is used to install its dependencies.
#
# [dependency-groups].dev: the development dependencies; i.e., what a
# developer needs in order to run unit tests, linters, and formatters. The
# "[dependency-groups]" section is a Python packaging feature introduced in
# 2025. This list is not stored in the metadata of the package. To install the
# development dependencies, use "pip install --group dev".

[build-system]
build-backend = "setuptools.build_meta"
requires = [
"packaging",
"setuptools>=78.1.1",
"pybind11[global]",
# "pip install" from sources needs to build Pybind, which needs CMake too.
"cmake~=3.28.1",
"setuptools>=78.1.1",
"setuptools-scm[toml]>=6.2",
"wheel",
]
build-backend = "setuptools.build_meta"

[project]
name = "qsimcirq"
description = "High-performance quantum circuit simulator for C++ and Python."
authors = [
{ name = "The qsim/qsimh Developers", email = "[email protected]" }
]
maintainers = [
{ name = "Google Quantum AI", email = "[email protected]" }
]
readme = {file = "README.md", content-type = "text/markdown"}
license = "Apache-2.0"
requires-python = ">=3.10.0"
dynamic = ["version", "dependencies"]
classifiers = [
"Development Status :: 5 - Production/Stable",
"Environment :: GPU :: NVIDIA CUDA",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"Operating System :: MacOS :: MacOS X",
"Operating System :: Microsoft :: Windows",
"Operating System :: POSIX :: Linux",
"Programming Language :: C++",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Topic :: Scientific/Engineering :: Quantum Computing",
"Topic :: Software Development :: Libraries :: Python Modules",
"Typing :: Typed",
]
keywords = [
"algorithms",
"cirq",
"nisq",
"quantum algorithm development",
"quantum circuit simulator",
"quantum computer simulator",
"quantum computing",
"quantum programming",
"quantum simulation",
"quantum",
"schrödinger-feynman simulation",
"simulation",
"state vector simulator",
]

[project.urls]
documentation = "https://quantumai.google/qsim"
download = "https://pypi.org/project/qsimcirq/#files"
homepage = "https://quantumai.google/qsim"
issues = "https://github.com/quantumlib/qsim/issues"
source = "https://github.com/quantumlib/qsim"

[dependency-groups]
# Development dependencies. Install these with "pip install --group dev".
dev = [
"black~=25.9.0",
"cibuildwheel",
# Distutils was removed from Python in 3.12.
"setuptools; python_version >= '3.12'",
"flynt~=1.0",
"isort[colors]~=6.0.1",
"py-cpuinfo",
"pylint~=4.0.2",
"pytest",
"pytest-xdist",
]

[tool.setuptools]
packages = ["qsimcirq"]
package-data = {"qsimcirq" = ["py.typed"]}

[tool.setuptools.dynamic]
# The next one becomes the value of [project].version.
version = {attr = "qsimcirq._version.__version__"}
# The next one becomes [project].dependencies, equivalent to "install_requires"
# in setuptools' setup.py. "pip install qsim" installs these automatically.
dependencies = {file = ["requirements.txt"] }

[tool.cibuildwheel]
test-extras = "dev"
build = "cp310-* cp311-* cp312-* cp313-*"
dependency-versions = "latest"
enable = ["cpython-prerelease"]
environment.PIP_PREFER_BINARY = "1"
# Due to package & module name conflict, temporarily move it away to run tests:
before-test = "mv {package}/qsimcirq /tmp"
test-command = "pytest -s -v {package}/qsimcirq_tests/qsimcirq_test.py && mv /tmp/qsimcirq {package}"
before-test = "pip install --group dev && mv {package}/qsimcirq /tmp"
test-command = """
pytest -s -v {package}/qsimcirq_tests/qsimcirq_test.py &&
mv /tmp/qsimcirq {package}
Comment on lines +128 to +129
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is to prevent the import of {package}/qsimcirq, it should be doable without moving it away and back -

Suggested change
pytest -s -v {package}/qsimcirq_tests/qsimcirq_test.py &&
mv /tmp/qsimcirq {package}
cd {package}/qsimcirq_tests && pytest -s -v qsimcirq_test.py

(should probably be in separate PR if you'd like to add it in).

"""

[tool.cibuildwheel.macos]
before-build = "brew install -q libomp llvm@19 && brew unlink libomp && brew unlink llvm@19 && brew link --force libomp && brew link --force llvm@19"
repair-wheel-command = "delocate-listdeps {wheel} && delocate-wheel --verbose --require-archs {delocate_archs} -w {dest_dir} {wheel}"
before-build = """
brew install -q libomp llvm@19 &&
brew unlink libomp &&
brew unlink llvm@19 &&
brew link --force libomp &&
brew link --force llvm@19
"""
repair-wheel-command = """
delocate-listdeps {wheel} &&
delocate-wheel --verbose --require-archs {delocate_archs} -w {dest_dir} {wheel}
"""

[tool.cibuildwheel.linux]
manylinux-x86_64-image = "manylinux2014"
Expand Down
16 changes: 15 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Installation and run-time dependencies for qsimcirq. This file is read
# by pyproject.toml.

absl-py
cirq-core~=1.0
numpy>=1.26.0
numpy>=1.26.0,<2.0; python_version < '3.11'
numpy>=2.0; python_version >= '3.11'

# These are needed because installing qsimcirq in some environments may require
# pip to compile Pybind for that specific platform:
cmake~=3.28.1
pybind11[global]
Comment on lines +9 to +12
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these be in [build-system].requires instead?

cmake is quite a heavy weight of about 73Mb, but is unlikely needed at qsimcirq runtime.


# These are transitive dependencies we need to constrain to avoid unresolvable
# installation conflicts due to them requiring higher Python versions:
scipy<1.16; python_version < '3.11'
contourpy<1.3; python_version < '3.11'
Loading
Loading