Skip to content

Commit

Permalink
Merge branch 'develop' into feature/openqasm
Browse files Browse the repository at this point in the history
  • Loading branch information
Takishima committed Jul 1, 2021
2 parents e214a38 + 0c44fba commit f50755d
Show file tree
Hide file tree
Showing 10 changed files with 769 additions and 45 deletions.
82 changes: 43 additions & 39 deletions .github/workflows/publish_release.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: "Publish new release"

on:
workflow_dispatch:
push:
tags:
- v[0-9]+.*
Expand All @@ -14,78 +15,59 @@ jobs:
packaging:
name: Build wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
if: startsWith(github.ref, 'refs/tags/') || (github.event_name == 'pull_request' && github.event.pull_request.merged == true)
if: startsWith(github.ref, 'refs/tags/') || (github.event_name == 'pull_request' && github.event.pull_request.merged == true) || github.event_name == 'workflow_dispatch'
strategy:
matrix:
os: [ubuntu-20.04, windows-2019, macos-10.15]
os:
- ubuntu-latest

steps:
- uses: actions/checkout@v2
if: github.event_name != 'workflow_dispatch'

- uses: actions/checkout@v2
if: github.event_name == 'workflow_dispatch'
with:
ref: 'master'

- name: Get history and tags for SCM versioning to work
run: |
git fetch --prune --unshallow
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
- name: Extract version from tag name (Unix)
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') && runner.os != 'Windows'
run: |
TAG_NAME="${GITHUB_REF/refs\/tags\//}"
VERSION=${TAG_NAME#v}
echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV
# ========================================================================

- name: Extract version from branch name (for release branches) (Unix)
if: github.event_name == 'pull_request' && startsWith(github.event.pull_request.head.ref, 'release/') && runner.os != 'Windows'
run: |
BRANCH_NAME="${{ github.event.pull_request.head.ref }}"
VERSION=${BRANCH_NAME#release/}
echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV
git tag v${RELEASE_VERSION} master
git tag v${VERSION} master
- name: Extract version from branch name (for hotfix branches) (Unix)
if: github.event_name == 'pull_request' && startsWith(github.event.pull_request.head.ref, 'hotfix/') && runner.os != 'Windows'
run: |
BRANCH_NAME="${{ github.event.pull_request.head.ref }}"
VERSION=${BRANCH_NAME#hotfix/}
git tag v${VERSION} master
echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV
git tag v${RELEASE_VERSION} master
- name: Extract version from tag name (Windows)
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') && runner.os == 'Windows'
run: |
$TAG_NAME = $GITHUB_REF -replace "refs/tags/",""
$VERSION = $TAG_NAME -replace "v",""
Write-Output "RELEASE_VERSION=$VERSION" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
# ------------------------------------------------------------------------

- name: Extract version from branch name (for release branches) (Windows)
if: github.event_name == 'pull_request' && startsWith(github.event.pull_request.head.ref, 'release/') && runner.os == 'Windows'
run: |
$BRANCH_NAME="${{ github.event.pull_request.head.ref }}"
$VERSION = $BRANCH_NAME -replace "release/",""
git tag v${VERSION} master
Write-Output "RELEASE_VERSION=$VERSION" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
git tag v${RELEASE_VERSION} master
- name: Extract version from branch name (for hotfix branches) (Unix)
- name: Extract version from branch name (for hotfix branches) (Windows)
if: github.event_name == 'pull_request' && startsWith(github.event.pull_request.head.ref, 'hotfix/') && runner.os == 'Windows'
run: |
$BRANCH_NAME="${{ github.event.pull_request.head.ref }}"
$VERSION = $BRANCH_NAME -replace "hotfix/",""
git tag v${VERSION} master
Write-Output "RELEASE_VERSION=$VERSION" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
git tag v${RELEASE_VERSION} master
- name: Build wheels
uses: joerick/cibuildwheel@v1.11.1
env:
CIBW_ARCHS: auto64
CIBW_SKIP: cp27-* pp* cp35-*
CIBW_BEFORE_BUILD: python -m pip install pybind11
# ========================================================================

- name: Build source distribution
if: runner.os == 'Linux'
Expand All @@ -101,11 +83,21 @@ jobs:
name: packages
path: ./wheelhouse/*


release:
name: Publish new release
runs-on: ubuntu-latest
needs: packaging
needs:
- packaging
steps:
- name: Extract version from tag name (workflow_dispatch)
if: github.event_name == 'workflow_dispatch'
run: |
TAG_NAME=$(git describe --tags `git rev-list --tags --max-count=1`)
VERSION=${TAG_NAME#v}
echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV
- name: Extract version from tag name
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
run: |
Expand All @@ -130,8 +122,18 @@ jobs:
echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV
# ------------------------------------------------------------------------
# Checkout repository to get CHANGELOG

- uses: actions/checkout@v2
if: github.event_name != 'workflow_dispatch'

- uses: actions/checkout@v2
if: github.event_name == 'workflow_dispatch'
with:
ref: 'master'

# ------------------------------------------------------------------------
# Downloads all to directories matching the artifact names
- uses: actions/download-artifact@v2

Expand Down Expand Up @@ -164,7 +166,7 @@ jobs:
upload_to_pypi:
name: Upload to PyPI
runs-on: ubuntu-latest
needs: release # Only upload to PyPi if everything was successful
needs: release
steps:
- uses: actions/setup-python@v2

Expand All @@ -181,7 +183,9 @@ jobs:
master_to_develop_pr:
name: Merge master back into develop
runs-on: ubuntu-latest
needs: release # Only create PR if everything was successful
needs:
- release
- upload_to_pypi
steps:
- name: Merge master into develop branch
uses: thomaseizinger/create-pull-request@1.1.0
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- UnitarySimulator backend for computing the unitary transformation corresponding to a quantum circuit.
- Added OpenQASMBackend to output QASM from ProjectQ circuits


### Changed
### Deprecated
### Fixed

- Prevent infinite recursion errors when too many compiler engines are added to the MainEngine

### Removed
### Repository

Expand All @@ -24,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Fix GitHub workflow for publishing a new release


## [0.6.0] - 2021-06-23

### Added
Expand Down
82 changes: 82 additions & 0 deletions examples/unitary_simulator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# -*- coding: utf-8 -*-
# Copyright 2021 ProjectQ-Framework (www.projectq.ch)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# pylint: skip-file

"""Example of using the UnitarySimulator."""


import numpy as np

from projectq.backends import UnitarySimulator
from projectq.cengines import MainEngine
from projectq.meta import Control
from projectq.ops import All, X, QFT, Measure, CtrlAll


def run_circuit(eng, n_qubits, circuit_num, gate_after_measure=False):
"""Run a quantum circuit demonstrating the capabilities of the UnitarySimulator."""
qureg = eng.allocate_qureg(n_qubits)

if circuit_num == 1:
All(X) | qureg
elif circuit_num == 2:
X | qureg[0]
with Control(eng, qureg[:2]):
All(X) | qureg[2:]
elif circuit_num == 3:
with Control(eng, qureg[:2], ctrl_state=CtrlAll.Zero):
All(X) | qureg[2:]
elif circuit_num == 4:
QFT | qureg

eng.flush()
All(Measure) | qureg

if gate_after_measure:
QFT | qureg
eng.flush()
All(Measure) | qureg


def main():
"""Definition of the main function of this example."""
# Create a MainEngine with a unitary simulator backend
eng = MainEngine(backend=UnitarySimulator())

n_qubits = 3

# Run out quantum circuit
# 1 - circuit applying X on all qubits
# 2 - circuit applying an X gate followed by a controlled-X gate
# 3 - circuit applying a off-controlled-X gate
# 4 - circuit applying a QFT on all qubits (QFT will get decomposed)
run_circuit(eng, n_qubits, 3, gate_after_measure=True)

# Output the unitary transformation of the circuit
print('The unitary of the circuit is:')
print(eng.backend.unitary)

# Output the final state of the qubits (assuming they all start in state |0>)
print('The final state of the qubits is:')
print(eng.backend.unitary @ np.array([1] + ([0] * (2 ** n_qubits - 1))))
print('\n')

# Show the unitaries separated by measurement:
for history in eng.backend.history:
print('Previous unitary is: \n', history, '\n')


if __name__ == '__main__':
main()
1 change: 1 addition & 0 deletions projectq/backends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@
from ._aqt import AQTBackend
from ._awsbraket import AWSBraketBackend
from ._ionq import IonQBackend
from ._unitary import UnitarySimulator
Loading

0 comments on commit f50755d

Please sign in to comment.