Skip to content

Commit f50755d

Browse files
authored
Merge branch 'develop' into feature/openqasm
2 parents e214a38 + 0c44fba commit f50755d

File tree

10 files changed

+769
-45
lines changed

10 files changed

+769
-45
lines changed

.github/workflows/publish_release.yml

+43-39
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: "Publish new release"
22

33
on:
4+
workflow_dispatch:
45
push:
56
tags:
67
- v[0-9]+.*
@@ -14,78 +15,59 @@ jobs:
1415
packaging:
1516
name: Build wheels on ${{ matrix.os }}
1617
runs-on: ${{ matrix.os }}
17-
if: startsWith(github.ref, 'refs/tags/') || (github.event_name == 'pull_request' && github.event.pull_request.merged == true)
18+
if: startsWith(github.ref, 'refs/tags/') || (github.event_name == 'pull_request' && github.event.pull_request.merged == true) || github.event_name == 'workflow_dispatch'
1819
strategy:
1920
matrix:
20-
os: [ubuntu-20.04, windows-2019, macos-10.15]
21+
os:
22+
- ubuntu-latest
2123

2224
steps:
2325
- uses: actions/checkout@v2
26+
if: github.event_name != 'workflow_dispatch'
27+
28+
- uses: actions/checkout@v2
29+
if: github.event_name == 'workflow_dispatch'
30+
with:
31+
ref: 'master'
2432

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

3840
- name: Extract version from branch name (for release branches) (Unix)
3941
if: github.event_name == 'pull_request' && startsWith(github.event.pull_request.head.ref, 'release/') && runner.os != 'Windows'
4042
run: |
4143
BRANCH_NAME="${{ github.event.pull_request.head.ref }}"
4244
VERSION=${BRANCH_NAME#release/}
43-
44-
echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV
45-
git tag v${RELEASE_VERSION} master
45+
git tag v${VERSION} master
4646
4747
- name: Extract version from branch name (for hotfix branches) (Unix)
4848
if: github.event_name == 'pull_request' && startsWith(github.event.pull_request.head.ref, 'hotfix/') && runner.os != 'Windows'
4949
run: |
5050
BRANCH_NAME="${{ github.event.pull_request.head.ref }}"
5151
VERSION=${BRANCH_NAME#hotfix/}
52+
git tag v${VERSION} master
5253
53-
echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV
54-
git tag v${RELEASE_VERSION} master
55-
56-
57-
- name: Extract version from tag name (Windows)
58-
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') && runner.os == 'Windows'
59-
run: |
60-
$TAG_NAME = $GITHUB_REF -replace "refs/tags/",""
61-
$VERSION = $TAG_NAME -replace "v",""
62-
63-
Write-Output "RELEASE_VERSION=$VERSION" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
54+
# ------------------------------------------------------------------------
6455

6556
- name: Extract version from branch name (for release branches) (Windows)
6657
if: github.event_name == 'pull_request' && startsWith(github.event.pull_request.head.ref, 'release/') && runner.os == 'Windows'
6758
run: |
6859
$BRANCH_NAME="${{ github.event.pull_request.head.ref }}"
6960
$VERSION = $BRANCH_NAME -replace "release/",""
61+
git tag v${VERSION} master
7062
71-
Write-Output "RELEASE_VERSION=$VERSION" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
72-
git tag v${RELEASE_VERSION} master
73-
74-
- name: Extract version from branch name (for hotfix branches) (Unix)
63+
- name: Extract version from branch name (for hotfix branches) (Windows)
7564
if: github.event_name == 'pull_request' && startsWith(github.event.pull_request.head.ref, 'hotfix/') && runner.os == 'Windows'
7665
run: |
7766
$BRANCH_NAME="${{ github.event.pull_request.head.ref }}"
7867
$VERSION = $BRANCH_NAME -replace "hotfix/",""
68+
git tag v${VERSION} master
7969
80-
Write-Output "RELEASE_VERSION=$VERSION" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
81-
git tag v${RELEASE_VERSION} master
82-
83-
- name: Build wheels
84-
uses: joerick/[email protected]
85-
env:
86-
CIBW_ARCHS: auto64
87-
CIBW_SKIP: cp27-* pp* cp35-*
88-
CIBW_BEFORE_BUILD: python -m pip install pybind11
70+
# ========================================================================
8971

9072
- name: Build source distribution
9173
if: runner.os == 'Linux'
@@ -101,11 +83,21 @@ jobs:
10183
name: packages
10284
path: ./wheelhouse/*
10385

86+
10487
release:
10588
name: Publish new release
10689
runs-on: ubuntu-latest
107-
needs: packaging
90+
needs:
91+
- packaging
10892
steps:
93+
- name: Extract version from tag name (workflow_dispatch)
94+
if: github.event_name == 'workflow_dispatch'
95+
run: |
96+
TAG_NAME=$(git describe --tags `git rev-list --tags --max-count=1`)
97+
VERSION=${TAG_NAME#v}
98+
99+
echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV
100+
109101
- name: Extract version from tag name
110102
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
111103
run: |
@@ -130,8 +122,18 @@ jobs:
130122
131123
echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV
132124
125+
# ------------------------------------------------------------------------
126+
# Checkout repository to get CHANGELOG
127+
133128
- uses: actions/checkout@v2
129+
if: github.event_name != 'workflow_dispatch'
130+
131+
- uses: actions/checkout@v2
132+
if: github.event_name == 'workflow_dispatch'
133+
with:
134+
ref: 'master'
134135

136+
# ------------------------------------------------------------------------
135137
# Downloads all to directories matching the artifact names
136138
- uses: actions/download-artifact@v2
137139

@@ -164,7 +166,7 @@ jobs:
164166
upload_to_pypi:
165167
name: Upload to PyPI
166168
runs-on: ubuntu-latest
167-
needs: release # Only upload to PyPi if everything was successful
169+
needs: release
168170
steps:
169171
- uses: actions/setup-python@v2
170172

@@ -181,7 +183,9 @@ jobs:
181183
master_to_develop_pr:
182184
name: Merge master back into develop
183185
runs-on: ubuntu-latest
184-
needs: release # Only create PR if everything was successful
186+
needs:
187+
- release
188+
- upload_to_pypi
185189
steps:
186190
- name: Merge master into develop branch
187191
uses: thomaseizinger/[email protected]

CHANGELOG.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

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

14-
1515
### Changed
1616
### Deprecated
1717
### Fixed
18+
19+
- Prevent infinite recursion errors when too many compiler engines are added to the MainEngine
20+
1821
### Removed
1922
### Repository
2023

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

2528
- Fix GitHub workflow for publishing a new release
2629

30+
2731
## [0.6.0] - 2021-06-23
2832

2933
### Added

examples/unitary_simulator.py

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2021 ProjectQ-Framework (www.projectq.ch)
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
# pylint: skip-file
16+
17+
"""Example of using the UnitarySimulator."""
18+
19+
20+
import numpy as np
21+
22+
from projectq.backends import UnitarySimulator
23+
from projectq.cengines import MainEngine
24+
from projectq.meta import Control
25+
from projectq.ops import All, X, QFT, Measure, CtrlAll
26+
27+
28+
def run_circuit(eng, n_qubits, circuit_num, gate_after_measure=False):
29+
"""Run a quantum circuit demonstrating the capabilities of the UnitarySimulator."""
30+
qureg = eng.allocate_qureg(n_qubits)
31+
32+
if circuit_num == 1:
33+
All(X) | qureg
34+
elif circuit_num == 2:
35+
X | qureg[0]
36+
with Control(eng, qureg[:2]):
37+
All(X) | qureg[2:]
38+
elif circuit_num == 3:
39+
with Control(eng, qureg[:2], ctrl_state=CtrlAll.Zero):
40+
All(X) | qureg[2:]
41+
elif circuit_num == 4:
42+
QFT | qureg
43+
44+
eng.flush()
45+
All(Measure) | qureg
46+
47+
if gate_after_measure:
48+
QFT | qureg
49+
eng.flush()
50+
All(Measure) | qureg
51+
52+
53+
def main():
54+
"""Definition of the main function of this example."""
55+
# Create a MainEngine with a unitary simulator backend
56+
eng = MainEngine(backend=UnitarySimulator())
57+
58+
n_qubits = 3
59+
60+
# Run out quantum circuit
61+
# 1 - circuit applying X on all qubits
62+
# 2 - circuit applying an X gate followed by a controlled-X gate
63+
# 3 - circuit applying a off-controlled-X gate
64+
# 4 - circuit applying a QFT on all qubits (QFT will get decomposed)
65+
run_circuit(eng, n_qubits, 3, gate_after_measure=True)
66+
67+
# Output the unitary transformation of the circuit
68+
print('The unitary of the circuit is:')
69+
print(eng.backend.unitary)
70+
71+
# Output the final state of the qubits (assuming they all start in state |0>)
72+
print('The final state of the qubits is:')
73+
print(eng.backend.unitary @ np.array([1] + ([0] * (2 ** n_qubits - 1))))
74+
print('\n')
75+
76+
# Show the unitaries separated by measurement:
77+
for history in eng.backend.history:
78+
print('Previous unitary is: \n', history, '\n')
79+
80+
81+
if __name__ == '__main__':
82+
main()

projectq/backends/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@
3636
from ._aqt import AQTBackend
3737
from ._awsbraket import AWSBraketBackend
3838
from ._ionq import IonQBackend
39+
from ._unitary import UnitarySimulator

0 commit comments

Comments
 (0)