-
Notifications
You must be signed in to change notification settings - Fork 272
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Init * Apply control through compute engine. Added Enum class * Apply control through compute engine. Added Enum class * Apply control through compute engine, added enum class * Fix small bug due to wrong default value, clean up output * abolished decomp * Revert "abolished decomp" This reverts commit 36743a1. * Apply Control through decomposition. Added Test Files * Fix a few issues with new control state - Address inconsistency with qubit state ordering when using integers as input control state - Add canonical_ctrl_state function to centralise functionality - Fix some file encoding - Fix tests * Update examples/control_tester.py * Add some missing license headers and fix some tests * Add missing docstring * Cleanup some code in AQT and IBM backends * Some code cleanup in _simulator.py * Change autoreplacer priority for control. Added Additional test for autoreplacer. Added check for canonical ctrl state func. * Update projectq/setups/default.py * Update projectq/setups/decompositions/cnu2toffoliandcu.py * Update projectq/setups/decompositions/cnu2toffoliandcu.py * Cleanup code in _replacer.py * Tweak some of the unit tests + add comments * Add more tests for canonical_ctrl_state and has_negative_control * Short pass of reformatting using black * Bug fixing for rebasing * Reformat files. Improve control_tester examples. Update change log * Dummy change to trigger CI with new state * Use pytest-mock for awsbraket client testing * Fix Linter warnings * Use pytest-mock also for awsbraket backend tests * Fix missing tests in backends and added support for IonQ * Fix linter warning * Add support for AWSBraketBackend * Fix small typo * Use backported mock instead of unittest.mock * Sort requirements_tests.txt * Fix a bunch of errors that happens at program exit Monkeypatching or patching of external may unload the patch before the MainEngine calls the last flush operations which would then call the original API although unwanted. Co-authored-by: Damien Nguyen <[email protected]>
- Loading branch information
Showing
30 changed files
with
736 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# -*- 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. | ||
|
||
from projectq.cengines import MainEngine | ||
from projectq.meta import Control | ||
from projectq.ops import All, X, Measure, CtrlAll | ||
|
||
|
||
def run_circuit(eng, circuit_num): | ||
qubit = eng.allocate_qureg(2) | ||
ctrl_fail = eng.allocate_qureg(3) | ||
ctrl_success = eng.allocate_qureg(3) | ||
|
||
if circuit_num == 1: | ||
with Control(eng, ctrl_fail): | ||
X | qubit[0] | ||
All(X) | ctrl_success | ||
with Control(eng, ctrl_success): | ||
X | qubit[1] | ||
|
||
elif circuit_num == 2: | ||
All(X) | ctrl_fail | ||
with Control(eng, ctrl_fail, ctrl_state=CtrlAll.Zero): | ||
X | qubit[0] | ||
with Control(eng, ctrl_success, ctrl_state=CtrlAll.Zero): | ||
X | qubit[1] | ||
|
||
elif circuit_num == 3: | ||
All(X) | ctrl_fail | ||
with Control(eng, ctrl_fail, ctrl_state='101'): | ||
X | qubit[0] | ||
|
||
X | ctrl_success[0] | ||
X | ctrl_success[2] | ||
with Control(eng, ctrl_success, ctrl_state='101'): | ||
X | qubit[1] | ||
|
||
elif circuit_num == 4: | ||
All(X) | ctrl_fail | ||
with Control(eng, ctrl_fail, ctrl_state=5): | ||
X | qubit[0] | ||
|
||
X | ctrl_success[0] | ||
X | ctrl_success[2] | ||
with Control(eng, ctrl_success, ctrl_state=5): | ||
X | qubit[1] | ||
|
||
All(Measure) | qubit | ||
All(Measure) | ctrl_fail | ||
All(Measure) | ctrl_success | ||
eng.flush() | ||
return qubit, ctrl_fail, ctrl_success | ||
|
||
|
||
if __name__ == '__main__': | ||
# Create a MainEngine with a unitary simulator backend | ||
eng = MainEngine() | ||
|
||
# Run out quantum circuit | ||
# 1 - Default behaviour of the control: all control qubits should be 1 | ||
# 2 - Off-control: all control qubits should remain 0 | ||
# 3 - Specific state given by a string | ||
# 4 - Specific state given by an integer | ||
|
||
qubit, ctrl_fail, ctrl_success = run_circuit(eng, 4) | ||
|
||
# Measured value of the failed qubit should be 0 in all cases | ||
print('The final value of the qubit with failed control is:') | ||
print(int(qubit[0])) | ||
print('with the state of control qubits are:') | ||
print([int(qubit) for qubit in ctrl_fail], '\n') | ||
|
||
# Measured value of the success qubit should be 1 in all cases | ||
print('The final value of the qubit with successful control is:') | ||
print(int(qubit[1])) | ||
print('with the state of control qubits are:') | ||
print([int(qubit) for qubit in ctrl_success], '\n') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.