Comments (2)
Using current Q# capabilities it is possible to express the example you refer to by using a combination of Assert
and adjoint
( which seems like what uncompute
should do):
namespace CCXwithQubitInZero
{
open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Primitive;
open Microsoft.Quantum.Extensions.Testing;
/// # Summary
/// Applies doubly controlled X to qubits assuming the target qubit is in zero state.
/// For Adjoint version assumes that target qubit is returned back to zero
/// after applying CCX.
/// # Remarks
/// See Figure 3 in https://arxiv.org/pdf/1709.06648.pdf#page=3
operation CCXwithTargetZero( control1 : Qubit, control2 : Qubit, target : Qubit ) : Unit {
body(...) {
AssertAllZero([target]);
TStateFromZeroSt(target);
CNOT(control1,target);
CNOT(control2,target);
CNOT(target,control1);
CNOT(target,control2);
Adjoint T(control1);
Adjoint T(control2);
T(target);
CNOT(target,control1);
CNOT(target,control2);
H(target);
S(target);
}
adjoint(...) {
AssertCCXTargetIsBackToZero(control1,control2,target);
H(target);
AssertProb([PauliZ],[target],One,0.5, "Probability of the measurement must be 0.5", 1e-10);
if ( M(target) == One ) {
Controlled Z([control1], control2);
X(target);
}
}
}
/// #Summary
/// Assert that target is going to be returned back to zero
/// after applying CCX
operation AssertCCXTargetIsBackToZero( control1 : Qubit, control2 : Qubit, target : Qubit ) : Unit
{
With(
ApplyToFirstThreeQubitsA(CCNOT,_),
Assert([PauliI,PauliI,PauliZ],_,Zero,""),
[control1,control2,target]);
}
/// # Summary
/// Uses CCXwithTargetZero to implement CCX with 4 T gates
operation CCX( control1 : Qubit, control2 : Qubit, target : Qubit ) : Unit {
body(...) {
using( anc = Qubit() ) {
WithA(CCXwithTargetZero(control1,control2,_),CNOT(_,target),anc);
}
}
adjoint auto;
}
/// # Summary
/// Creates |T⟩ state starting zero state
operation TStateFromZeroSt ( target : Qubit ) : Unit {
AssertAllZero([target]);
H(target);
T(target);
}
/// Test the correctness of CCX implementation
operation CCXTest () : Unit {
for( i in 0 .. 10 ) {
AssertOperationsEqualReferenced(
ApplyToFirstThreeQubitsA(CCX,_),
ApplyToFirstThreeQubitsA(CCNOT,_),3);
}
Message("Test passed");
}
}
Note that AssertCCXTargetIsBackToZero
must be replaced by NoOp for resource estimation purposes to get accurate gate counts.
from quantum.
I see. Yes, that is a good strategy for performing these kinds of operations-for-specific-states. Have a separate operation with an understood precondition (and postcondition for adjoint).
from quantum.
Related Issues (20)
- H2 Broombridge file seems incorrect
- Q# installation issue through dotnet , VS code. HOT 4
- "External component has thrown an exception." for SudokuGrover running 4x4-classic HOT 5
- Resource estimator for factorization of 2048-bit semi prime integers HOT 12
- Latest LLVM version for qir/oracle-generator is 14.0. Need to update CMakefile.txt if just following instructions
- Typo in samples / interoperability / python / environment.yml HOT 1
- lo
- Using nuget restore from .NET 5.0 no longer requires first updating ca-certificates HOT 1
- Optimization: Remove redundant `list` call in `check_file` in `Build/check_indents.py` HOT 3
- PI
- Add Sparse Simulator Samples HOT 6
- BayesianPEIsCorrect test fails probabilistically HOT 1
- Add sparse simulator sample to main
- mybinder notebook integer-factorization does not work HOT 3
- Quantum Random Number Generator not working HOT 1
- `TimeoutError` but azure still connects? HOT 4
- HalfMoon example on Quantum Hardware HOT 2
- Don't use "failed" in the normal RUS loop logs
- "Prebuild Docker image" Action is broken. HOT 1
- Error in Shor's algorithm HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from quantum.