Skip to content

Commit

Permalink
Merge pull request #35 from zapatacomputing/dev
Browse files Browse the repository at this point in the history
Merge dev to master
  • Loading branch information
alexjuda authored Aug 2, 2021
2 parents 57c24d1 + 9421425 commit d2235ae
Show file tree
Hide file tree
Showing 11 changed files with 200 additions and 76 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/coverage_base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- uses: actions/checkout@v2

- name: Get z-quantum-core
uses: actions/checkout@master
uses: actions/checkout@v2
with:
repository: zapatacomputing/z-quantum-core
path: z-quantum-core
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/coverage_development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- uses: actions/checkout@v2

- name: Get z-quantum-core
uses: actions/checkout@master
uses: actions/checkout@v2
with:
repository: zapatacomputing/z-quantum-core
path: z-quantum-core
Expand Down
34 changes: 17 additions & 17 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@
# "publish-release" action in "z-quantum-actions". This allows reusing it between repos.
name: publish-release

# on:
# push:
# branches:
# - master
on:
push:
branches:
- master

# jobs:
# run-action:
# runs-on: ubuntu-latest
jobs:
run-action:
runs-on: ubuntu-latest

# steps:
# # Needed to get access to publish-release action definition
# - name: Check out the released repo
# uses: actions/checkout@v2
# with:
# # Fetch whole repo to get access to tags. We need tags to read current package
# # version.
# fetch-depth: 0
steps:
# Needed to get access to publish-release action definition
- name: Check out the released repo
uses: actions/checkout@v2
with:
# Fetch whole repo to get access to tags. We need tags to read current package
# version.
fetch-depth: 0

# - name: Run publish release action
# uses: ./vendor/z-quantum-actions/publish-release
- name: Run publish release action
uses: ./subtrees/z-quantum-actions/publish-release

32 changes: 16 additions & 16 deletions .github/workflows/submit-dev-master-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
# composite action instead. This allows reusing it between repos.
name: submit-dev-master-pr

# on:
# workflow_dispatch:
on:
workflow_dispatch:

# jobs:
# submit-pr:
# runs-on: ubuntu-latest
# steps:
# - name: Submit dev -> master PR
# uses: actions/github-script@v4
# with:
# script: |
# github.pulls.create({
# ...context.repo,
# title: "Merge dev to master",
# head: "dev",
# base: "master",
# })
jobs:
submit-pr:
runs-on: ubuntu-latest
steps:
- name: Submit dev -> master PR
uses: actions/github-script@v4
with:
script: |
github.pulls.create({
...context.repo,
title: "Merge dev to master",
head: "dev",
base: "master",
})
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import setuptools
import os

with open("README.md", "r") as f:
long_description = f.read()

setuptools.setup(
name="qe-qulacs",
version="0.1.0",
use_scm_version=True,
author="Zapata Computing, Inc.",
author_email="info@zapatacomputing.com",
description="Qulacs backend for Orquestra.",
Expand All @@ -15,10 +14,11 @@
url="https://github.com/zapatacomputing/qe-qulacs",
packages=setuptools.find_packages(where="src/python"),
package_dir={"": "src/python"},
classifiers=(
classifiers=[
"Programming Language :: Python :: 3",
"Operating System :: OS Independent",
),
],
setup_requires=["setuptools_scm~=6.0"],
install_requires=[
"cmake>=3.18",
"gcc7==0.0.7", # The latest version 0.0.9 only has wheels for Mac
Expand Down
32 changes: 10 additions & 22 deletions src/python/qequlacs/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import itertools
import numpy as np
from qulacs.observable import create_observable_from_openfermion_text
from openfermion import QubitOperator
from pyquil.wavefunction import Wavefunction
from zquantum.core.interfaces.backend import QuantumSimulator
from zquantum.core.measurement import (
Expand All @@ -14,50 +15,37 @@
from zquantum.core.circuits import Circuit, GateOperation
from zquantum.core.wip.compatibility_tools import compatible_with_old_type
from .conversions import convert_to_qulacs
from typing import Optional
from typing import Any


class QulacsSimulator(QuantumSimulator):

supports_batching = False

def __init__(self, n_samples=None):
super().__init__(n_samples)
def __init__(self):
super().__init__()

def run_circuit_and_measure(
self, circuit: Circuit, n_samples: Optional[int] = None, **kwargs
):
def run_circuit_and_measure(self, circuit: Circuit, n_samples: int) -> Measurements:
"""
Run a circuit and measure a certain number of bitstrings
Args:
circuit: the circuit to prepare the state
n_samples: the number of bitstrings to sample
Returns:
The measured bitstrings.
"""
if n_samples is None:
if self.n_samples is None:
raise ValueError(
"n_samples needs to be specified either as backend attribute or as an function argument."
)
else:
n_samples = self.n_samples
wavefunction = self.get_wavefunction(circuit)
bitstrings = sample_from_wavefunction(wavefunction, n_samples)
return Measurements(bitstrings)

def get_wavefunction(self, circuit):
def get_wavefunction(self, circuit) -> Wavefunction:
super().get_wavefunction(circuit)
qulacs_state = self.get_qulacs_state_from_circuit(circuit)
amplitudes = qulacs_state.get_vector()
return Wavefunction(amplitudes)

def get_exact_expectation_values(self, circuit, qubit_operator, **kwargs):
if self.n_samples is not None:
raise Exception(
"Exact expectation values work only for n_samples equal to None."
)
def get_exact_expectation_values(
self, circuit: Circuit, qubit_operator: QubitOperator
) -> ExpectationValues:
self.number_of_circuits_run += 1
self.number_of_jobs_run += 1

Expand Down Expand Up @@ -91,5 +79,5 @@ def get_qulacs_state_from_circuit(self, circuit: Circuit):
qulacs_state.load(wavefunction)
return qulacs_state

def can_be_executed_natively(self, operation):
def can_be_executed_natively(self, operation: Any) -> bool:
return isinstance(operation, GateOperation)
27 changes: 27 additions & 0 deletions subtrees/z-quantum-actions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# z-quantum-actions

This repo contains definitions of custom GitHub Action used in `z-quantum-*` and `qe-*`
repositories.

## Usage

This repo is private, so actions can't be referenced directly via `uses:` [step keyword](https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idstepsuses).
The recommended workaround is to add this repo into your "client" repo using git subtree:

```bash
cd your-client-repo
git subtree add -P vendor/z-quantum-actions git@github.com:zapatacomputing/z-quantum-actions.git master --squash
```

Actions can be then referred to via their local paths, like:
```yaml
# inside your GitHub workflow
steps:
- name: Run publish release action
uses: ./vendor/z-quantum-actions/publish-release
```
## Repo contents
- `publish-release` - single action that wraps a couple of workflow steps
- `workflow-templates` - workflow .ymls that can't be used directly, but can be copied to your repo to set up the release process.
68 changes: 68 additions & 0 deletions subtrees/z-quantum-actions/publish-release/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# This workflow is meant to be run on each push to the base branch. It allows executing
# the "publish release" action.
#
# Don't extend this workflow. If any more steps are needed please add them to the
# action instead. This allows reusing it between repos.
name: Publish release

description: Infers current project version, pushes a tag with a new version, and creates an entry on GitHub Releases

# Note: this action assumes that the repo was already cloned

inputs:
new-version:
description: Optional override for the release version. If not provided, will be inferred from current version.
required: false


outputs:
release-version:
description: Version that the release ended up running for.
value: ${{ steps.infer-release-version.outputs.inferred_version }}

runs:
using: composite
steps:
- name: Infer release version
id: infer-release-version
shell: bash
run: |
NEW_VERSION="${{ inputs.new_version }}"
if [ -n "$NEW_VERSION" ]; then
INFERRED_VERSION="$NEW_VERSION"
echo "using $INFERRED_VERSION provided as action input"
else
PKG_VERSION=$(python3 setup.py --version)
MAJOR=$(echo $PKG_VERSION | sed -r 's/^([0-9]+)\.([0-9]+)\.([0-9]+)([-\.].+)?$/\1/')
MINOR=$(echo $PKG_VERSION | sed -r 's/^([0-9]+)\.([0-9]+)\.([0-9]+)([-\.].+)?$/\2/')
PATCH=$(echo $PKG_VERSION | sed -r 's/^([0-9]+)\.([0-9]+)\.([0-9]+)([-\.].+)?$/\3/')
DEV=$(echo $PKG_VERSION | sed -r 's/^([0-9]+)\.([0-9]+)\.([0-9]+)([-\.].+)?$/\4/')
echo "read version: $MAJOR.$MINOR.$PATCH$DEV"
INFERRED_VERSION="$MAJOR.$(expr $MINOR + 1).0"
echo "inferred version: $INFERRED_VERSION"
fi
# special github syntax for setting step outputs
# see https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-output-parameter
echo "::set-output name=inferred_version::$INFERRED_VERSION"
- name: Push new version tag
id: push-new-version-tag
shell: bash
run: |
TAG="v${{steps.infer-release-version.outputs.inferred_version}}"
git tag "$TAG"
git push --tags
echo "::set-output name=tag::$TAG"
- name: Create entry on GH Releases
shell: bash
run: |
curl \
-X POST \
curl -H "Authorization: token ${{ github.token }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/releases \
-d '{"tag_name":"${{ steps.push-new-version-tag.outputs.tag }}"}'
27 changes: 27 additions & 0 deletions subtrees/z-quantum-actions/workflow-templates/publish-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# This workflow is meant to be triggered by push to master when running the release
# process.
#
# Don't extend this workflow. If any more steps are needed please extend the
# "publish-release" action in "z-quantum-actions". This allows reusing it between repos.
name: publish-release

on:
push:
branches:
- master

jobs:
run-action:
runs-on: ubuntu-latest

steps:
# Needed to get access to publish-release action definition
- name: Check out the released repo
uses: actions/checkout@v2
with:
# Fetch whole repo to get access to tags. We need tags to read current package
# version.
fetch-depth: 0

- name: Run publish release action
uses: ./vendor/z-quantum-actions/publish-release
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# This workflow is meant to be triggered by an Operator with via cURL.
#
# Don't extend this workflow. If any more steps are needed please extract the steps as a
# composite action instead. This allows reusing it between repos.
name: submit-dev-master-pr

on:
workflow_dispatch:

jobs:
submit-pr:
runs-on: ubuntu-latest
steps:
- name: Submit dev -> master PR
uses: actions/github-script@v4
with:
script: |
github.pulls.create({
...context.repo,
title: "Merge dev to master",
head: "dev",
base: "master",
})
21 changes: 6 additions & 15 deletions tests/qequlacs/simulator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,14 @@
import numpy as np


@pytest.fixture(
params=[
{"n_samples": None},
{"n_samples": 1000},
]
)
def backend(request):
return QulacsSimulator(**request.param)
@pytest.fixture
def backend():
return QulacsSimulator()


@pytest.fixture(
params=[
{"n_samples": None},
]
)
def wf_simulator(request):
return QulacsSimulator(**request.param)
@pytest.fixture
def wf_simulator():
return QulacsSimulator()


class TestQulacs(QuantumSimulatorTests):
Expand Down

0 comments on commit d2235ae

Please sign in to comment.