Update deprecated syntax.
This commit is contained in:
Родитель
dae271baad
Коммит
ed4d272d7c
|
@ -15,7 +15,7 @@ namespace Microsoft.Quantum.Research.Samples {
|
|||
/// Applies the time evolution unitary generated by Hamiltonian
|
||||
/// H = X_1 + Z_1 Z_2, as simulated using a simple Trotter decomposition.
|
||||
operation EvolveByTrotter (time: Double, nStep: Int, qubits: Qubit[]) : Unit is Adj + Ctl {
|
||||
for (idxStep in 1..nStep) {
|
||||
for idxStep in 1..nStep {
|
||||
Exp([PauliZ, PauliZ], -time / IntAsDouble(nStep), qubits);
|
||||
Exp([PauliX, PauliI], -time / IntAsDouble(nStep), qubits);
|
||||
}
|
||||
|
@ -35,7 +35,11 @@ namespace Microsoft.Quantum.Research.Samples {
|
|||
let idxPhysical2 = 2;
|
||||
|
||||
ExpFrac([PauliI], -1, 1, [qubits[idxControl]]); // global phase -i.
|
||||
ApplyWithCA(X, CX(_, qubits[idxPhysical1]), qubits[idxControl]); // control-X activated on |0> rather than |1>.
|
||||
within { // control-X activated on |0> rather than |1>.
|
||||
X(qubits[idxControl]);
|
||||
} apply {
|
||||
CX(qubits[idxControl], qubits[idxPhysical1]);
|
||||
}
|
||||
ApplyToEachCA(CZ(qubits[idxControl], _), qubits[idxPhysical1..idxPhysical2]);
|
||||
X(qubits[idxControl]); // This is 2|G><G|-1, where |G> happens to be (|0> + |1>)/sqrt(2).
|
||||
}
|
||||
|
@ -69,29 +73,28 @@ namespace Microsoft.Quantum.Research.Samples {
|
|||
fail "An odd number of calls to the quantum walk operator is forbidden.";
|
||||
}
|
||||
|
||||
using (aux = Qubit()) {
|
||||
H(aux); // Preparing the auxillary qubit in the |+⟩ state.
|
||||
for (idx in 0..((nQueries / 2) - 1)) {
|
||||
within {
|
||||
Rz(-angles[2 * idx], aux);
|
||||
H(aux);
|
||||
X(aux);
|
||||
} apply {
|
||||
(Controlled walkOperation)([aux], qubits);
|
||||
}
|
||||
|
||||
within {
|
||||
Rz(-angles[2 * idx + 1], aux);
|
||||
H(aux);
|
||||
} apply {
|
||||
Controlled Adjoint walkOperation([aux], qubits);
|
||||
}
|
||||
|
||||
use aux = Qubit();
|
||||
H(aux); // Preparing the auxillary qubit in the |+⟩ state.
|
||||
for idx in 0..((nQueries / 2) - 1) {
|
||||
within {
|
||||
Rz(-angles[2 * idx], aux);
|
||||
H(aux);
|
||||
X(aux);
|
||||
} apply {
|
||||
(Controlled walkOperation)([aux], qubits);
|
||||
}
|
||||
Rz(angles[nQueries], aux); // The last unitary correction.
|
||||
if (MResetX(aux) == One) {
|
||||
fail "QSP's postselection failed.";
|
||||
|
||||
within {
|
||||
Rz(-angles[2 * idx + 1], aux);
|
||||
H(aux);
|
||||
} apply {
|
||||
Controlled Adjoint walkOperation([aux], qubits);
|
||||
}
|
||||
|
||||
}
|
||||
Rz(angles[nQueries], aux); // The last unitary correction.
|
||||
if (MResetX(aux) == One) {
|
||||
fail "QSP's postselection failed.";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -108,15 +111,14 @@ namespace Microsoft.Quantum.Research.Samples {
|
|||
/// which should be called beforehand by a C# driver.
|
||||
operation SampleHamiltonianEvolutionByQSP(tau : Double, angles : Double[])
|
||||
: Unit {
|
||||
using (qubits = Qubit[3]) {
|
||||
H(Head(qubits)); // Preparing an auxillary qubit in the state $\ket{G}$.
|
||||
DumpMachine(());
|
||||
QuantumSignalProcessOnEquator(angles, ApplyBlockEncodedHamiltonian, qubits);
|
||||
// Now we roll back by Trotter evolution.
|
||||
EvolveByTrotter(-tau / 2.0, 1000, qubits[1..2]);
|
||||
// The factor of 2 that divides tau is the 1-norm of the Hamiltonian's coefficients.
|
||||
DumpMachine(());
|
||||
ResetAll(qubits);
|
||||
}
|
||||
use qubits = Qubit[3];
|
||||
H(Head(qubits)); // Preparing an auxillary qubit in the state $\ket{G}$.
|
||||
DumpMachine(());
|
||||
QuantumSignalProcessOnEquator(angles, ApplyBlockEncodedHamiltonian, qubits);
|
||||
// Now we roll back by Trotter evolution.
|
||||
EvolveByTrotter(-tau / 2.0, 1000, qubits[1..2]);
|
||||
// The factor of 2 that divides tau is the 1-norm of the Hamiltonian's coefficients.
|
||||
DumpMachine(());
|
||||
ResetAll(qubits);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,20 +10,18 @@ namespace Microsoft.Quantum.Research.Characterization {
|
|||
open Microsoft.Quantum.Oracles;
|
||||
open Microsoft.Quantum.Characterization;
|
||||
|
||||
operation _PrepAndMeasurePhaseEst(
|
||||
internal operation _PrepAndMeasurePhaseEst(
|
||||
wInv : Double,
|
||||
t : Double,
|
||||
op : ((Double, Double, Qubit) => Unit))
|
||||
: Result {
|
||||
using (target = Qubit()) {
|
||||
op(t, wInv, target);
|
||||
return MResetZ(target);
|
||||
}
|
||||
use target = Qubit();
|
||||
op(t, wInv, target);
|
||||
return MResetZ(target);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// NB: we take std.dev instead of variance here to avoid having to take a square root.
|
||||
|
||||
|
||||
/// # Summary
|
||||
/// Performs iterative phase estimation using a random walk to approximate
|
||||
/// Bayesian inference on the classical measurement results from a given
|
||||
|
@ -109,79 +107,39 @@ namespace Microsoft.Quantum.Research.Characterization {
|
|||
mutable datum = Zero;
|
||||
mutable nTotalMeasurements = 0;
|
||||
mutable nAcceptedMeasurements = 0;
|
||||
|
||||
|
||||
repeat {
|
||||
|
||||
if (nTotalMeasurements >= maxMeasurements) {
|
||||
|
||||
if nTotalMeasurements >= maxMeasurements {
|
||||
return mu;
|
||||
}
|
||||
|
||||
|
||||
let wInv = mu - (PI() * sigma) / 2.0;
|
||||
let t = 1.0 / sigma;
|
||||
set datum = sampleOp(wInv, t);
|
||||
set nTotalMeasurements += 1;
|
||||
|
||||
if (datum == Zero) {
|
||||
|
||||
if datum == Zero {
|
||||
set mu -= sigma * INV_SQRT_E;
|
||||
} else {
|
||||
set mu += sigma * INV_SQRT_E;
|
||||
}
|
||||
|
||||
|
||||
set sigma *= PREFACTOR;
|
||||
set dataRecord += [datum];
|
||||
|
||||
|
||||
// Perform consistency check.
|
||||
if (nTotalMeasurements >= maxMeasurements) {
|
||||
return mu;
|
||||
}
|
||||
|
||||
if (unwind > 0) {
|
||||
mutable checkDatum = sampleOp(mu, 1.0 / sigma);
|
||||
set nTotalMeasurements = nTotalMeasurements + 1;
|
||||
|
||||
if (checkDatum == One) {
|
||||
|
||||
repeat {
|
||||
|
||||
for (idxUnwind in 0 .. unwind - 1) {
|
||||
set sigma /= PREFACTOR;
|
||||
|
||||
if (Length(dataRecord) > 0) {
|
||||
let unwoundDatum = Tail(dataRecord);
|
||||
set dataRecord = Most(dataRecord);
|
||||
|
||||
if (unwoundDatum == Zero) {
|
||||
set mu += sigma * INV_SQRT_E;
|
||||
}
|
||||
else {
|
||||
set mu -= sigma * INV_SQRT_E;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (nTotalMeasurements >= maxMeasurements) {
|
||||
Message("RWPE used too many measurements during unwinding.");
|
||||
return mu;
|
||||
}
|
||||
|
||||
set checkDatum = sampleOp(mu, 1.0 / sigma);
|
||||
set nTotalMeasurements += 1;
|
||||
}
|
||||
until (checkDatum == Zero)
|
||||
fixup {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
set nAcceptedMeasurements = nAcceptedMeasurements + 1;
|
||||
}
|
||||
until (nAcceptedMeasurements >= nMeasurements)
|
||||
fixup {
|
||||
}
|
||||
|
||||
until nAcceptedMeasurements >= nMeasurements;
|
||||
|
||||
return mu;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<Project Sdk="Microsoft.Quantum.Sdk/0.11.2003.3107">
|
||||
<Project Sdk="Microsoft.Quantum.Sdk/0.16.2104138035">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
|
|
|
@ -48,8 +48,8 @@ namespace Microsoft.Quantum.Research.Chemistry {
|
|||
// Circuit with cancellation of neighbouring CNOTS
|
||||
let (minInt, bitStringApplyCNOT) = _DeltaParityCNOTbitstring(prevFermionicTerm, nextFermionicTerm);
|
||||
|
||||
for (idx in 0 .. Length(bitStringApplyCNOT) - 1) {
|
||||
if (bitStringApplyCNOT[idx] == true) {
|
||||
for idx in 0 .. Length(bitStringApplyCNOT) - 1 {
|
||||
if bitStringApplyCNOT[idx] == true {
|
||||
CNOT(qubits[idx + minInt], aux);
|
||||
}
|
||||
}
|
||||
|
@ -74,21 +74,19 @@ namespace Microsoft.Quantum.Research.Chemistry {
|
|||
mutable prevBitString = new Bool[nInts];
|
||||
mutable nextBitString = new Bool[nInts];
|
||||
|
||||
for (idxGroup in 0 .. Length(prevFermionicTerm) / 2 - 1) {
|
||||
|
||||
for (idxQubit in (prevFermionicTerm[idxGroup * 2] + 1) - minInt .. (prevFermionicTerm[idxGroup * 2 + 1] - 1) - minInt) {
|
||||
for idxGroup in 0 .. Length(prevFermionicTerm) / 2 - 1 {
|
||||
for idxQubit in (prevFermionicTerm[idxGroup * 2] + 1) - minInt .. (prevFermionicTerm[idxGroup * 2 + 1] - 1) - minInt {
|
||||
set prevBitString w/= idxQubit <- true;
|
||||
}
|
||||
}
|
||||
|
||||
for (idxGroup in 0 .. Length(nextFermionicTerm) / 2 - 1) {
|
||||
|
||||
for (idxQubit in (nextFermionicTerm[idxGroup * 2] + 1) - minInt .. (nextFermionicTerm[idxGroup * 2 + 1] - 1) - minInt) {
|
||||
for idxGroup in 0 .. Length(nextFermionicTerm) / 2 - 1 {
|
||||
for idxQubit in (nextFermionicTerm[idxGroup * 2] + 1) - minInt .. (nextFermionicTerm[idxGroup * 2 + 1] - 1) - minInt {
|
||||
set nextBitString w/= idxQubit <- true;
|
||||
}
|
||||
}
|
||||
|
||||
for (idx in 0 .. nInts - 1) {
|
||||
for idx in 0 .. nInts - 1 {
|
||||
set nextBitString w/= idx <- Xor(prevBitString[idx], nextBitString[idx]);
|
||||
}
|
||||
|
||||
|
@ -127,7 +125,7 @@ namespace Microsoft.Quantum.Research.Chemistry {
|
|||
targetQubit : Qubit
|
||||
)
|
||||
: Unit is Adj + Ctl {
|
||||
for ((op, target) in Zip(ops, qubits + [targetQubit])) {
|
||||
for (op, target) in Zipped(ops, qubits + [targetQubit]) {
|
||||
op(target);
|
||||
}
|
||||
}
|
||||
|
@ -142,9 +140,9 @@ namespace Microsoft.Quantum.Research.Chemistry {
|
|||
/// Angle of Rz rotation.
|
||||
/// ## parityQubit
|
||||
/// Qubit that determines the sign of time-evolution.
|
||||
/// ## qubits
|
||||
/// ## qubit
|
||||
/// Qubit acted on by Rz.
|
||||
operation _JWOptimizedZ(angle : Double, parityQubit : Qubit, qubit : Qubit)
|
||||
internal operation _JWOptimizedZ(angle : Double, parityQubit : Qubit, qubit : Qubit)
|
||||
: Unit is Adj + Ctl {
|
||||
ApplyWithCA(CNOT(parityQubit, _), Rz(-2.0 * angle, _), qubit);
|
||||
}
|
||||
|
@ -162,7 +160,7 @@ namespace Microsoft.Quantum.Research.Chemistry {
|
|||
/// Qubit that determines the sign of time-evolution.
|
||||
/// ## qubits
|
||||
/// Qubits of Hamiltonian.
|
||||
operation _JWOptimizedZTerm(term : GeneratorIndex, stepSize : Double, parityQubit : Qubit, qubits : Qubit[])
|
||||
internal operation _JWOptimizedZTerm(term : GeneratorIndex, stepSize : Double, parityQubit : Qubit, qubits : Qubit[])
|
||||
: Unit is Adj + Ctl {
|
||||
let ((idxTermType, coeff), idxFermions) = term!;
|
||||
let angle = (1.0 * coeff[0]) * stepSize;
|
||||
|
@ -183,7 +181,7 @@ namespace Microsoft.Quantum.Research.Chemistry {
|
|||
/// Qubit that determines the sign of time-evolution.
|
||||
/// ## qubits
|
||||
/// Qubits of Hamiltonian.
|
||||
operation _JWOptimizedZZTerm(term : GeneratorIndex, stepSize : Double, parityQubit : Qubit, qubits : Qubit[])
|
||||
internal operation _JWOptimizedZZTerm(term : GeneratorIndex, stepSize : Double, parityQubit : Qubit, qubits : Qubit[])
|
||||
: Unit is Adj + Ctl {
|
||||
let ((idxTermType, coeff), idxFermions) = term!;
|
||||
let angle = (1.0 * coeff[0]) * stepSize;
|
||||
|
@ -204,7 +202,7 @@ namespace Microsoft.Quantum.Research.Chemistry {
|
|||
/// Qubit that determines the sign of time-evolution.
|
||||
/// ## qubits
|
||||
/// Qubits of Hamiltonian.
|
||||
operation _JWOptimizedHpqTerm(term : GeneratorIndex, stepSize : Double, parityQubit : Qubit, qubits : Qubit[])
|
||||
internal operation _JWOptimizedHpqTerm(term : GeneratorIndex, stepSize : Double, parityQubit : Qubit, qubits : Qubit[])
|
||||
: Unit is Adj + Ctl {
|
||||
let ((idxTermType, coeff), idxFermions) = term!;
|
||||
ApplyWithCA(ApplyDeltaParity(new Int[0], idxFermions, parityQubit, _), _JWOptimizedHpqTermImpl(term, stepSize, parityQubit, _), qubits);
|
||||
|
@ -213,7 +211,7 @@ namespace Microsoft.Quantum.Research.Chemistry {
|
|||
|
||||
/// # Summary
|
||||
/// Implementation step of `JWOptimizedHpqTerm_`.
|
||||
operation _JWOptimizedHpqTermImpl (
|
||||
internal operation _JWOptimizedHpqTermImpl (
|
||||
term : GeneratorIndex, stepSize : Double, parityQubit : Qubit, qubits : Qubit[]
|
||||
)
|
||||
: Unit is Adj + Ctl {
|
||||
|
@ -224,7 +222,7 @@ namespace Microsoft.Quantum.Research.Chemistry {
|
|||
let qubitsPQ = Subarray(idxFermions[0 .. 1], qubits);
|
||||
let ops = [TransformZToX, TransformZToY];
|
||||
|
||||
for (op in ops) {
|
||||
for op in ops {
|
||||
within {
|
||||
ApplyBasisChange([op, op], [qubitP], qubitQ);
|
||||
ApplyCNOTChainWithTarget([qubitP], qubitQ);
|
||||
|
@ -247,7 +245,7 @@ namespace Microsoft.Quantum.Research.Chemistry {
|
|||
/// Qubit that determines the sign of time-evolution.
|
||||
/// ## qubits
|
||||
/// Qubits of Hamiltonian.
|
||||
operation _JWOptimizedPQandPQQRTerm(term : GeneratorIndex, stepSize : Double, parityQubit : Qubit, qubits : Qubit[])
|
||||
internal operation _JWOptimizedPQandPQQRTerm(term : GeneratorIndex, stepSize : Double, parityQubit : Qubit, qubits : Qubit[])
|
||||
: Unit is Adj + Ctl {
|
||||
let ((idxTermType, coeff), idxFermions) = term!;
|
||||
let angle = (1.0 * coeff[0]) * stepSize;
|
||||
|
@ -283,7 +281,7 @@ namespace Microsoft.Quantum.Research.Chemistry {
|
|||
/// Qubit that determines the sign of time-evolution.
|
||||
/// ## qubits
|
||||
/// Qubits of Hamiltonian.
|
||||
operation _JWOptimized0123Term(term : GeneratorIndex, stepSize : Double, parityQubit : Qubit, qubits : Qubit[])
|
||||
internal operation _JWOptimized0123Term(term : GeneratorIndex, stepSize : Double, parityQubit : Qubit, qubits : Qubit[])
|
||||
: Unit is Adj + Ctl {
|
||||
let ((idxTermType, coeff), idxFermions) = term!;
|
||||
ApplyWithCA(
|
||||
|
@ -296,7 +294,7 @@ namespace Microsoft.Quantum.Research.Chemistry {
|
|||
|
||||
/// # Summary
|
||||
/// Implementation step of `JWOptimized0123Term_`;
|
||||
operation _JWOptimized0123TermImpl (term : GeneratorIndex, stepSize : Double, parityQubit : Qubit, qubits : Qubit[])
|
||||
internal operation _JWOptimized0123TermImpl (term : GeneratorIndex, stepSize : Double, parityQubit : Qubit, qubits : Qubit[])
|
||||
: Unit is Adj + Ctl {
|
||||
let x = TransformZToX;
|
||||
let y = TransformZToY;
|
||||
|
@ -318,7 +316,7 @@ namespace Microsoft.Quantum.Research.Chemistry {
|
|||
let qubitsPQR = qubitsPQRS[0 .. Length(qubitsPQRS) - 2];
|
||||
let qubitS = qubitsPQRS[3];
|
||||
|
||||
for (idxOp in 0 .. 7) {
|
||||
for idxOp in 0 .. 7 {
|
||||
if (IsNotZero(v0123[idxOp % 4])) {
|
||||
let op0 = _JWOptimizedZ(angle * v0123[idxOp % 4], parityQubit, _);
|
||||
let op1 = ApplyWithCA(ApplyCNOTChainWithTarget(qubitsPQR, _), op0, _);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<Project Sdk="Microsoft.Quantum.Sdk/0.11.2003.3107">
|
||||
<Project Sdk="Microsoft.Quantum.Sdk/0.16.2104138035">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
|
@ -19,7 +19,7 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Quantum.Chemistry" Version="0.11.2003.3107" />
|
||||
<PackageReference Include="Microsoft.Quantum.Chemistry" Version="0.16.2104138035" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -10,510 +10,481 @@ namespace SystemTestJWOptimizedES {
|
|||
open Microsoft.Quantum.Chemistry.JordanWigner;
|
||||
open Microsoft.Quantum.Research.Chemistry;
|
||||
open Microsoft.Quantum.Measurement;
|
||||
open Microsoft.Quantum.Diagnostics as Diag;
|
||||
|
||||
// Test phase of PP term.
|
||||
operation PPTermFromGeneralHamiltonianTestOp (identity : Double, data : JWOptimizedHTerms) : Unit {
|
||||
|
||||
let time = 1.0;
|
||||
|
||||
using ((qubits, parityQubit) = (Qubit[3], Qubit())) {
|
||||
|
||||
// Create |00> + |10>
|
||||
let qubitSys = qubits[0 .. Length(qubits) - 2];
|
||||
H(qubits[0]);
|
||||
JWOptimizedApplyTrotterStep(data, time, time, parityQubit, qubitSys);
|
||||
AssertPhase(-0.5 * time, qubits[0], 1E-10);
|
||||
ResetAll(qubits);
|
||||
use qubits = Qubit[3];
|
||||
use parityQubit = Qubit();
|
||||
|
||||
// Create |00> + |01>
|
||||
H(qubits[1]);
|
||||
JWOptimizedApplyTrotterStep(data, time, time, parityQubit, qubitSys);
|
||||
AssertPhase(-0.0 * time, qubits[1], 1E-10);
|
||||
ResetAll(qubits);
|
||||
let ctrl = qubits[Length(qubits) - 1];
|
||||
H(ctrl);
|
||||
X(qubitSys[0]);
|
||||
(Controlled (Exp([PauliI], time * identity, _)))([ctrl], [qubits[0]]);
|
||||
(Controlled (JWOptimizedApplyTrotterStep(data, time, time, parityQubit, _)))([ctrl], qubitSys);
|
||||
AssertPhase(-0.5 * time, ctrl, 1E-10);
|
||||
ResetAll(qubits + [parityQubit]);
|
||||
}
|
||||
// Create |00> + |10>
|
||||
let qubitSys = qubits[0 .. Length(qubits) - 2];
|
||||
H(qubits[0]);
|
||||
JWOptimizedApplyTrotterStep(data, time, time, parityQubit, qubitSys);
|
||||
Diag.AssertPhase(-0.5 * time, qubits[0], 1E-10);
|
||||
ResetAll(qubits);
|
||||
|
||||
// Create |00> + |01>
|
||||
H(qubits[1]);
|
||||
JWOptimizedApplyTrotterStep(data, time, time, parityQubit, qubitSys);
|
||||
Diag.AssertPhase(-0.0 * time, qubits[1], 1E-10);
|
||||
ResetAll(qubits);
|
||||
let ctrl = qubits[Length(qubits) - 1];
|
||||
H(ctrl);
|
||||
X(qubitSys[0]);
|
||||
(Controlled (Exp([PauliI], time * identity, _)))([ctrl], [qubits[0]]);
|
||||
(Controlled (JWOptimizedApplyTrotterStep(data, time, time, parityQubit, _)))([ctrl], qubitSys);
|
||||
Diag.AssertPhase(-0.5 * time, ctrl, 1E-10);
|
||||
ResetAll(qubits + [parityQubit]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Test hopping from site A to site B.
|
||||
operation PQTermABFromGeneralHamiltonianTestOp (data : JWOptimizedHTerms) : Unit {
|
||||
|
||||
|
||||
// Test probability
|
||||
let time = 0.5 * PI();
|
||||
mutable arrPrep = new Int[4];
|
||||
set arrPrep = [0, 1, 2, 3];
|
||||
mutable arrMeasure = new Int[4];
|
||||
set arrMeasure = [1, 0, 2, 3];
|
||||
|
||||
using (parityQubit = Qubit[1]) {
|
||||
|
||||
using (qubits = Qubit[4]) {
|
||||
|
||||
// Create |1000>
|
||||
for (idx in 0 .. 3) {
|
||||
X(qubits[arrPrep[idx]]);
|
||||
JWOptimizedApplyTrotterStep(data, time, time, parityQubit[0], qubits);
|
||||
AssertProb([PauliZ], [qubits[arrMeasure[idx]]], One, 1.0, "PQTermTest probability failed.", 1E-10);
|
||||
ResetAll(qubits + parityQubit);
|
||||
}
|
||||
}
|
||||
|
||||
// Test phase
|
||||
using (qubitsC = Qubit[5]) {
|
||||
|
||||
// Create |1000>(|0>+|1>)
|
||||
let ctrl = qubitsC[4];
|
||||
H(ctrl);
|
||||
X(qubitsC[arrPrep[0]]);
|
||||
|
||||
// Create |1000>|0>+ i|0100>|1>
|
||||
(Controlled (JWOptimizedApplyTrotterStep(data, time, time, parityQubit[0], _)))([ctrl], qubitsC[0 .. 3]);
|
||||
AssertProb([PauliZ], [qubitsC[arrMeasure[0]]], One, 0.5, "PQTermTest probability failed.", 1E-10);
|
||||
|
||||
// Create |1000>|0>+ i|1000>|1>
|
||||
CNOT(ctrl, qubitsC[0]);
|
||||
CNOT(ctrl, qubitsC[1]);
|
||||
AssertProb([PauliZ], [qubitsC[arrMeasure[0]]], One, 0.0, "PQTermTest probability failed.", 1E-10);
|
||||
AssertPhase(-0.25 * PI(), ctrl, 1E-10);
|
||||
ResetAll(qubitsC + parityQubit);
|
||||
use parityQubit = Qubit();
|
||||
|
||||
|
||||
use qubits = Qubit[4] {
|
||||
// Create |1000>
|
||||
for idx in 0 .. 3 {
|
||||
X(qubits[arrPrep[idx]]);
|
||||
JWOptimizedApplyTrotterStep(data, time, time, parityQubit, qubits);
|
||||
Diag.AssertMeasurementProbability([PauliZ], [qubits[arrMeasure[idx]]], One, 1.0, "PQTermTest probability failed.", 1E-10);
|
||||
ResetAll(qubits + [parityQubit]);
|
||||
}
|
||||
}
|
||||
|
||||
// Test phase
|
||||
use qubitsC = Qubit[5] {
|
||||
|
||||
// Create |1000>(|0>+|1>)
|
||||
let ctrl = qubitsC[4];
|
||||
H(ctrl);
|
||||
X(qubitsC[arrPrep[0]]);
|
||||
|
||||
// Create |1000>|0>+ i|0100>|1>
|
||||
(Controlled (JWOptimizedApplyTrotterStep(data, time, time, parityQubit, _)))([ctrl], qubitsC[0 .. 3]);
|
||||
Diag.AssertMeasurementProbability([PauliZ], [qubitsC[arrMeasure[0]]], One, 0.5, "PQTermTest probability failed.", 1E-10);
|
||||
|
||||
// Create |1000>|0>+ i|1000>|1>
|
||||
CNOT(ctrl, qubitsC[0]);
|
||||
CNOT(ctrl, qubitsC[1]);
|
||||
Diag.AssertMeasurementProbability([PauliZ], [qubitsC[arrMeasure[0]]], One, 0.0, "PQTermTest probability failed.", 1E-10);
|
||||
Diag.AssertPhase(-0.25 * PI(), ctrl, 1E-10);
|
||||
ResetAll(qubitsC + [parityQubit]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Test hopping from site A to site C
|
||||
operation PQTermACFromGeneralHamiltonianTestOp (data : JWOptimizedHTerms) : Unit {
|
||||
|
||||
|
||||
// Test probability
|
||||
let time = 0.5 * PI();
|
||||
mutable arrPrep = new Int[4];
|
||||
set arrPrep = [0, 2, 3, 5];
|
||||
mutable arrMeasure = new Int[4];
|
||||
set arrMeasure = [2, 0, 3, 5];
|
||||
|
||||
using (parityQubit = Qubit[1]) {
|
||||
|
||||
using (qubits = Qubit[6]) {
|
||||
|
||||
// Create |100000>
|
||||
for (idx in 0 .. 3) {
|
||||
X(qubits[arrPrep[idx]]);
|
||||
JWOptimizedApplyTrotterStep(data, time, time, parityQubit[0], qubits);
|
||||
AssertProb([PauliZ], [qubits[arrMeasure[idx]]], One, 1.0, "PQTermTest probability failed.", 1E-10);
|
||||
ResetAll(qubits + parityQubit);
|
||||
}
|
||||
}
|
||||
|
||||
// Test phase
|
||||
using (qubitsC = Qubit[7]) {
|
||||
|
||||
// Create |1000>(|0>+|1>)
|
||||
let ctrl = qubitsC[6];
|
||||
H(ctrl);
|
||||
X(qubitsC[arrPrep[0]]);
|
||||
|
||||
// Create |10000>|0>+ i|00100>|1>
|
||||
(Controlled (JWOptimizedApplyTrotterStep(data, time, time, parityQubit[0], _)))([ctrl], qubitsC[0 .. 5]);
|
||||
AssertProb([PauliZ], [qubitsC[arrMeasure[0]]], One, 0.5, "PQTermTest probability failed.", 1E-10);
|
||||
|
||||
// Create |10000>|0>+ i|10000>|1>
|
||||
CNOT(ctrl, qubitsC[0]);
|
||||
CNOT(ctrl, qubitsC[2]);
|
||||
AssertProb([PauliZ], [qubitsC[arrMeasure[0]]], One, 0.0, "PQTermTest probability failed.", 1E-10);
|
||||
AssertPhase(-0.25 * PI(), ctrl, 1E-10);
|
||||
ResetAll(qubitsC + parityQubit);
|
||||
H(ctrl);
|
||||
X(qubitsC[arrPrep[0]]);
|
||||
X(qubitsC[1]);
|
||||
|
||||
// Create |11000>|0>- i|01100>|1>
|
||||
(Controlled (JWOptimizedApplyTrotterStep(data, time, time, parityQubit[0], _)))([ctrl], qubitsC[0 .. 5]);
|
||||
AssertProb([PauliZ], [qubitsC[arrMeasure[0]]], One, 0.5, "PQTermTest probability failed.", 1E-10);
|
||||
|
||||
// Create |11000>|0>- i|11000>|1>
|
||||
CNOT(ctrl, qubitsC[0]);
|
||||
CNOT(ctrl, qubitsC[2]);
|
||||
AssertProb([PauliZ], [qubitsC[arrMeasure[0]]], One, 0.0, "PQTermTest probability failed.", 1E-10);
|
||||
AssertPhase(0.25 * PI(), ctrl, 1E-10);
|
||||
ResetAll(qubitsC + parityQubit);
|
||||
|
||||
use parityQubit = Qubit();
|
||||
use qubits = Qubit[6] {
|
||||
// Create |100000>
|
||||
for idx in 0 .. 3 {
|
||||
X(qubits[arrPrep[idx]]);
|
||||
JWOptimizedApplyTrotterStep(data, time, time, parityQubit, qubits);
|
||||
Diag.AssertMeasurementProbability([PauliZ], [qubits[arrMeasure[idx]]], One, 1.0, "PQTermTest probability failed.", 1E-10);
|
||||
ResetAll(qubits + [parityQubit]);
|
||||
}
|
||||
}
|
||||
|
||||
// Test phase
|
||||
use qubitsC = Qubit[7] {
|
||||
|
||||
// Create |1000>(|0>+|1>)
|
||||
let ctrl = qubitsC[6];
|
||||
H(ctrl);
|
||||
X(qubitsC[arrPrep[0]]);
|
||||
|
||||
// Create |10000>|0>+ i|00100>|1>
|
||||
(Controlled (JWOptimizedApplyTrotterStep(data, time, time, parityQubit, _)))([ctrl], qubitsC[0 .. 5]);
|
||||
Diag.AssertMeasurementProbability([PauliZ], [qubitsC[arrMeasure[0]]], One, 0.5, "PQTermTest probability failed.", 1E-10);
|
||||
|
||||
// Create |10000>|0>+ i|10000>|1>
|
||||
CNOT(ctrl, qubitsC[0]);
|
||||
CNOT(ctrl, qubitsC[2]);
|
||||
Diag.AssertMeasurementProbability([PauliZ], [qubitsC[arrMeasure[0]]], One, 0.0, "PQTermTest probability failed.", 1E-10);
|
||||
Diag.AssertPhase(-0.25 * PI(), ctrl, 1E-10);
|
||||
ResetAll(qubitsC + [parityQubit]);
|
||||
H(ctrl);
|
||||
X(qubitsC[arrPrep[0]]);
|
||||
X(qubitsC[1]);
|
||||
|
||||
// Create |11000>|0>- i|01100>|1>
|
||||
(Controlled (JWOptimizedApplyTrotterStep(data, time, time, parityQubit, _)))([ctrl], qubitsC[0 .. 5]);
|
||||
Diag.AssertMeasurementProbability([PauliZ], [qubitsC[arrMeasure[0]]], One, 0.5, "PQTermTest probability failed.", 1E-10);
|
||||
|
||||
// Create |11000>|0>- i|11000>|1>
|
||||
CNOT(ctrl, qubitsC[0]);
|
||||
CNOT(ctrl, qubitsC[2]);
|
||||
Diag.AssertMeasurementProbability([PauliZ], [qubitsC[arrMeasure[0]]], One, 0.0, "PQTermTest probability failed.", 1E-10);
|
||||
Diag.AssertPhase(0.25 * PI(), ctrl, 1E-10);
|
||||
ResetAll(qubitsC + [parityQubit]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Test phase of PP term.
|
||||
operation PQQPTermFromGeneralHamiltonianTestOp (identity : Double, data : JWOptimizedHTerms) : Unit {
|
||||
|
||||
|
||||
let time = 1.0;
|
||||
|
||||
using (qubits = Qubit[5]) {
|
||||
|
||||
using (parityQubit = Qubit[1]) {
|
||||
let ctrl = qubits[Length(qubits) - 1];
|
||||
let qubitSys = qubits[0 .. Length(qubits) - 2];
|
||||
|
||||
// Create |1100>(|0>+|1>);
|
||||
H(ctrl);
|
||||
X(qubitSys[0]);
|
||||
X(qubitSys[1]);
|
||||
|
||||
// Create |1100>(|0>+e^{i t}|1>);
|
||||
(Controlled (JWOptimizedApplyTrotterStep(data, time, time, parityQubit[0], _)))([ctrl], qubitSys);
|
||||
(Controlled (Exp([PauliI], time * identity, _)))([ctrl], [qubitSys[0]]);
|
||||
AssertPhase(-0.5 * time, ctrl, 1E-10);
|
||||
ResetAll(qubits + parityQubit);
|
||||
|
||||
// Create |1110>(|0>+|1>);
|
||||
H(ctrl);
|
||||
X(qubitSys[0]);
|
||||
X(qubitSys[1]);
|
||||
X(qubitSys[2]);
|
||||
|
||||
// Create |1100>(|0>+e^{i t}|1>);
|
||||
(Controlled (JWOptimizedApplyTrotterStep(data, time, time, parityQubit[0], _)))([ctrl], qubitSys);
|
||||
(Controlled (Exp([PauliI], time * identity, _)))([ctrl], [qubitSys[0]]);
|
||||
AssertPhase(-0.5 * time, ctrl, 1E-10);
|
||||
ResetAll(qubits + parityQubit);
|
||||
|
||||
// Create |1111>(|0>+|1>);
|
||||
H(ctrl);
|
||||
X(qubitSys[0]);
|
||||
X(qubitSys[1]);
|
||||
X(qubitSys[2]);
|
||||
X(qubitSys[3]);
|
||||
|
||||
// Create |1100>(|0>+e^{i t}|1>);
|
||||
(Controlled (JWOptimizedApplyTrotterStep(data, time, time, parityQubit[0], _)))([ctrl], qubitSys);
|
||||
(Controlled (Exp([PauliI], time * identity, _)))([ctrl], [qubitSys[0]]);
|
||||
AssertPhase(-0.5 * time, ctrl, 1E-10);
|
||||
ResetAll(qubits + parityQubit);
|
||||
}
|
||||
}
|
||||
|
||||
use qubits = Qubit[5];
|
||||
use parityQubit = Qubit();
|
||||
|
||||
let ctrl = qubits[Length(qubits) - 1];
|
||||
let qubitSys = qubits[0 .. Length(qubits) - 2];
|
||||
|
||||
// Create |1100>(|0>+|1>);
|
||||
H(ctrl);
|
||||
X(qubitSys[0]);
|
||||
X(qubitSys[1]);
|
||||
|
||||
// Create |1100>(|0>+e^{i t}|1>);
|
||||
(Controlled (JWOptimizedApplyTrotterStep(data, time, time, parityQubit, _)))([ctrl], qubitSys);
|
||||
(Controlled (Exp([PauliI], time * identity, _)))([ctrl], [qubitSys[0]]);
|
||||
Diag.AssertPhase(-0.5 * time, ctrl, 1E-10);
|
||||
ResetAll(qubits + [parityQubit]);
|
||||
|
||||
// Create |1110>(|0>+|1>);
|
||||
H(ctrl);
|
||||
X(qubitSys[0]);
|
||||
X(qubitSys[1]);
|
||||
X(qubitSys[2]);
|
||||
|
||||
// Create |1100>(|0>+e^{i t}|1>);
|
||||
(Controlled (JWOptimizedApplyTrotterStep(data, time, time, parityQubit, _)))([ctrl], qubitSys);
|
||||
(Controlled (Exp([PauliI], time * identity, _)))([ctrl], [qubitSys[0]]);
|
||||
Diag.AssertPhase(-0.5 * time, ctrl, 1E-10);
|
||||
ResetAll(qubits + [parityQubit]);
|
||||
|
||||
// Create |1111>(|0>+|1>);
|
||||
H(ctrl);
|
||||
X(qubitSys[0]);
|
||||
X(qubitSys[1]);
|
||||
X(qubitSys[2]);
|
||||
X(qubitSys[3]);
|
||||
|
||||
// Create |1100>(|0>+e^{i t}|1>);
|
||||
(Controlled (JWOptimizedApplyTrotterStep(data, time, time, parityQubit, _)))([ctrl], qubitSys);
|
||||
(Controlled (Exp([PauliI], time * identity, _)))([ctrl], [qubitSys[0]]);
|
||||
Diag.AssertPhase(-0.5 * time, ctrl, 1E-10);
|
||||
ResetAll(qubits + [parityQubit]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
operation PQQRTermFromGeneralHamiltonianTestOp (data : JWOptimizedHTerms) : Unit {
|
||||
|
||||
|
||||
// Test probability
|
||||
mutable time = (4.0 * 0.5) * PI();
|
||||
mutable arrPrep = new Int[4];
|
||||
set arrPrep = [0, 2, 1, 3];
|
||||
mutable arrMeasure = new Int[4];
|
||||
set arrMeasure = [2, 0, 3, 1];
|
||||
|
||||
using (qubits = Qubit[4]) {
|
||||
|
||||
using (parityQubit = Qubit[1]) {
|
||||
|
||||
// Create |1000>
|
||||
for (idx in 0 .. 3) {
|
||||
X(qubits[arrPrep[idx]]);
|
||||
JWOptimizedApplyTrotterStep(data, time, 0.1 * time, parityQubit[0], qubits);
|
||||
AssertProb([PauliZ], [qubits[arrMeasure[idx]]], One, 0.0, "PQQRTermTest a probability failed.", 1E-10);
|
||||
ResetAll(qubits);
|
||||
}
|
||||
|
||||
// Create |1100>
|
||||
set time = PI();
|
||||
X(qubits[arrPrep[0]]);
|
||||
X(qubits[1]);
|
||||
JWOptimizedApplyTrotterStep(data, time, 0.1 * time, parityQubit[0], qubits);
|
||||
AssertProb([PauliZ], [qubits[arrMeasure[0]]], One, 1.0, "PQQRTermTest b probability failed.", 0.01);
|
||||
ResetAll(qubits);
|
||||
|
||||
// Create |1001>
|
||||
set time = PI();
|
||||
X(qubits[arrPrep[0]]);
|
||||
X(qubits[3]);
|
||||
JWOptimizedApplyTrotterStep(data, time, 0.1 * time, parityQubit[0], qubits);
|
||||
AssertProb([PauliZ], [qubits[arrMeasure[0]]], One, 0.0, "PQQRTermTest c probability failed.", 0.01);
|
||||
ResetAll(qubits);
|
||||
}
|
||||
|
||||
use qubits = Qubit[4];
|
||||
use parityQubit = Qubit();
|
||||
|
||||
// Create |1000>
|
||||
for idx in 0 .. 3 {
|
||||
X(qubits[arrPrep[idx]]);
|
||||
JWOptimizedApplyTrotterStep(data, time, 0.1 * time, parityQubit, qubits);
|
||||
Diag.AssertMeasurementProbability([PauliZ], [qubits[arrMeasure[idx]]], One, 0.0, "PQQRTermTest a probability failed.", 1E-10);
|
||||
ResetAll(qubits);
|
||||
}
|
||||
|
||||
// Create |1100>
|
||||
set time = PI();
|
||||
X(qubits[arrPrep[0]]);
|
||||
X(qubits[1]);
|
||||
JWOptimizedApplyTrotterStep(data, time, 0.1 * time, parityQubit, qubits);
|
||||
Diag.AssertMeasurementProbability([PauliZ], [qubits[arrMeasure[0]]], One, 1.0, "PQQRTermTest b probability failed.", 0.01);
|
||||
ResetAll(qubits);
|
||||
|
||||
// Create |1001>
|
||||
set time = PI();
|
||||
X(qubits[arrPrep[0]]);
|
||||
X(qubits[3]);
|
||||
JWOptimizedApplyTrotterStep(data, time, 0.1 * time, parityQubit, qubits);
|
||||
Diag.AssertMeasurementProbability([PauliZ], [qubits[arrMeasure[0]]], One, 0.0, "PQQRTermTest c probability failed.", 0.01);
|
||||
ResetAll(qubits);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
operation PQRSTermFromGeneralHamiltonianTestOp (data : JWOptimizedHTerms) : Unit {
|
||||
|
||||
|
||||
// Test probability
|
||||
mutable time = 1.0;
|
||||
mutable prob = Sin(time) * Sin(time);
|
||||
|
||||
using (qubits = Qubit[4]) {
|
||||
|
||||
using (parityQubit = Qubit[1]) {
|
||||
|
||||
// Create |1100>
|
||||
X(qubits[0]);
|
||||
X(qubits[1]);
|
||||
JWOptimizedApplyTrotterStep(data, time, time, parityQubit[0], qubits);
|
||||
AssertProb([PauliZ], [qubits[2]], One, prob, "PQRSTermTest a probability failed.", 1E-10);
|
||||
AssertProb([PauliZ], [qubits[3]], One, prob, "PQRSTermTest b probability failed.", 1E-10);
|
||||
ResetAll(qubits + parityQubit);
|
||||
}
|
||||
}
|
||||
|
||||
use qubits = Qubit[4];
|
||||
use parityQubit = Qubit();
|
||||
|
||||
// Create |1100>
|
||||
X(qubits[0]);
|
||||
X(qubits[1]);
|
||||
JWOptimizedApplyTrotterStep(data, time, time, parityQubit, qubits);
|
||||
Diag.AssertMeasurementProbability([PauliZ], [qubits[2]], One, prob, "PQRSTermTest a probability failed.", 1E-10);
|
||||
Diag.AssertMeasurementProbability([PauliZ], [qubits[3]], One, prob, "PQRSTermTest b probability failed.", 1E-10);
|
||||
ResetAll(qubits + [parityQubit]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Test phase of PP term.
|
||||
operation PPTermFromLiquidOrbitalTestOp (identity : Double, data : JWOptimizedHTerms) : Unit {
|
||||
|
||||
|
||||
let time = 1.0;
|
||||
|
||||
using (qubits = Qubit[3]) {
|
||||
|
||||
using (parityQubit = Qubit[1]) {
|
||||
|
||||
// Create |00> + |10>
|
||||
let qubitSys = qubits[0 .. Length(qubits) - 2];
|
||||
H(qubits[0]);
|
||||
JWOptimizedApplyTrotterStep(data, time, time, parityQubit[0], qubitSys);
|
||||
AssertPhase(-0.5 * time, qubits[0], 1E-10);
|
||||
ResetAll(qubits + parityQubit);
|
||||
|
||||
// Create |00> + |01>
|
||||
H(qubits[1]);
|
||||
JWOptimizedApplyTrotterStep(data, time, time, parityQubit[0], qubitSys);
|
||||
AssertPhase(-0.5 * time, qubits[1], 1E-10);
|
||||
ResetAll(qubits + parityQubit);
|
||||
let ctrl = qubits[Length(qubits) - 1];
|
||||
H(ctrl);
|
||||
X(qubitSys[0]);
|
||||
(Controlled (Exp([PauliI], time * identity, _)))([ctrl], [qubits[0]]);
|
||||
(Controlled (JWOptimizedApplyTrotterStep(data, time, time, parityQubit[0], _)))([ctrl], qubitSys);
|
||||
AssertPhase(-0.5 * time, ctrl, 1E-10);
|
||||
ResetAll(qubits + parityQubit);
|
||||
}
|
||||
}
|
||||
|
||||
use qubits = Qubit[3];
|
||||
use parityQubit = Qubit();
|
||||
|
||||
// Create |00> + |10>
|
||||
let qubitSys = qubits[0 .. Length(qubits) - 2];
|
||||
H(qubits[0]);
|
||||
JWOptimizedApplyTrotterStep(data, time, time, parityQubit, qubitSys);
|
||||
Diag.AssertPhase(-0.5 * time, qubits[0], 1E-10);
|
||||
ResetAll(qubits + [parityQubit]);
|
||||
|
||||
// Create |00> + |01>
|
||||
H(qubits[1]);
|
||||
JWOptimizedApplyTrotterStep(data, time, time, parityQubit, qubitSys);
|
||||
Diag.AssertPhase(-0.5 * time, qubits[1], 1E-10);
|
||||
ResetAll(qubits + [parityQubit]);
|
||||
let ctrl = qubits[Length(qubits) - 1];
|
||||
H(ctrl);
|
||||
X(qubitSys[0]);
|
||||
(Controlled (Exp([PauliI], time * identity, _)))([ctrl], [qubits[0]]);
|
||||
(Controlled (JWOptimizedApplyTrotterStep(data, time, time, parityQubit, _)))([ctrl], qubitSys);
|
||||
Diag.AssertPhase(-0.5 * time, ctrl, 1E-10);
|
||||
ResetAll(qubits + [parityQubit]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Test hopping from site A to site B.
|
||||
operation PQTermABFromLiquidOrbitalTestOp (data : JWOptimizedHTerms) : Unit {
|
||||
|
||||
|
||||
// Test probability
|
||||
let time = 0.5 * PI();
|
||||
mutable arrPrep = new Int[4];
|
||||
set arrPrep = [0, 1, 2, 3];
|
||||
mutable arrMeasure = new Int[4];
|
||||
set arrMeasure = [1, 0, 3, 2];
|
||||
|
||||
using (parityQubit = Qubit[1]) {
|
||||
|
||||
using (qubits = Qubit[4]) {
|
||||
|
||||
// Create |1000>
|
||||
for (idx in 0 .. 3) {
|
||||
X(qubits[arrPrep[idx]]);
|
||||
JWOptimizedApplyTrotterStep(data, time, time, parityQubit[0], qubits);
|
||||
AssertProb([PauliZ], [qubits[arrMeasure[idx]]], One, 1.0, "PQTermTest probability failed.", 1E-10);
|
||||
ResetAll(qubits + parityQubit);
|
||||
}
|
||||
}
|
||||
|
||||
// Test phase
|
||||
using (qubitsC = Qubit[5]) {
|
||||
|
||||
// Create |1000>(|0>+|1>)
|
||||
let ctrl = qubitsC[4];
|
||||
H(ctrl);
|
||||
X(qubitsC[arrPrep[0]]);
|
||||
|
||||
// Create |1000>|0>+ i|0100>|1>
|
||||
(Controlled (JWOptimizedApplyTrotterStep(data, time, time, parityQubit[0], _)))([ctrl], qubitsC[0 .. 3]);
|
||||
AssertProb([PauliZ], [qubitsC[arrMeasure[0]]], One, 0.5, "PQTermTest probability failed.", 1E-10);
|
||||
|
||||
// Create |1000>|0>+ i|1000>|1>
|
||||
CNOT(ctrl, qubitsC[0]);
|
||||
CNOT(ctrl, qubitsC[1]);
|
||||
AssertProb([PauliZ], [qubitsC[arrMeasure[0]]], One, 0.0, "PQTermTest probability failed.", 1E-10);
|
||||
AssertPhase(-0.25 * PI(), ctrl, 1E-10);
|
||||
ResetAll(qubitsC + parityQubit);
|
||||
|
||||
use parityQubit = Qubit();
|
||||
|
||||
use qubits = Qubit[4] {
|
||||
|
||||
// Create |1000>
|
||||
for idx in 0 .. 3 {
|
||||
X(qubits[arrPrep[idx]]);
|
||||
JWOptimizedApplyTrotterStep(data, time, time, parityQubit, qubits);
|
||||
Diag.AssertMeasurementProbability([PauliZ], [qubits[arrMeasure[idx]]], One, 1.0, "PQTermTest probability failed.", 1E-10);
|
||||
ResetAll(qubits + [parityQubit]);
|
||||
}
|
||||
}
|
||||
|
||||
// Test phase
|
||||
use qubitsC = Qubit[5] {
|
||||
|
||||
// Create |1000>(|0>+|1>)
|
||||
let ctrl = qubitsC[4];
|
||||
H(ctrl);
|
||||
X(qubitsC[arrPrep[0]]);
|
||||
|
||||
// Create |1000>|0>+ i|0100>|1>
|
||||
(Controlled (JWOptimizedApplyTrotterStep(data, time, time, parityQubit, _)))([ctrl], qubitsC[0 .. 3]);
|
||||
Diag.AssertMeasurementProbability([PauliZ], [qubitsC[arrMeasure[0]]], One, 0.5, "PQTermTest probability failed.", 1E-10);
|
||||
|
||||
// Create |1000>|0>+ i|1000>|1>
|
||||
CNOT(ctrl, qubitsC[0]);
|
||||
CNOT(ctrl, qubitsC[1]);
|
||||
Diag.AssertMeasurementProbability([PauliZ], [qubitsC[arrMeasure[0]]], One, 0.0, "PQTermTest probability failed.", 1E-10);
|
||||
Diag.AssertPhase(-0.25 * PI(), ctrl, 1E-10);
|
||||
ResetAll(qubitsC + [parityQubit]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Test hopping from site A to site C
|
||||
operation PQTermACFromLiquidOrbitalTestOp (data : JWOptimizedHTerms) : Unit {
|
||||
|
||||
|
||||
// Test probability
|
||||
let time = 0.5 * PI();
|
||||
mutable arrPrep = new Int[4];
|
||||
set arrPrep = [0, 2, 3, 5];
|
||||
mutable arrMeasure = new Int[4];
|
||||
set arrMeasure = [2, 0, 5, 3];
|
||||
|
||||
using (parityQubit = Qubit[1]) {
|
||||
|
||||
using (qubits = Qubit[6]) {
|
||||
|
||||
// Create |100000>
|
||||
for (idx in 0 .. 3) {
|
||||
X(qubits[arrPrep[idx]]);
|
||||
JWOptimizedApplyTrotterStep(data, time, time, parityQubit[0], qubits);
|
||||
AssertProb([PauliZ], [qubits[arrMeasure[idx]]], One, 1.0, "PQTermTest probability failed.", 1E-10);
|
||||
ResetAll(qubits + parityQubit);
|
||||
}
|
||||
}
|
||||
|
||||
// Test phase
|
||||
using (qubitsC = Qubit[7]) {
|
||||
|
||||
// Create |1000>(|0>+|1>)
|
||||
let ctrl = qubitsC[6];
|
||||
H(ctrl);
|
||||
X(qubitsC[arrPrep[0]]);
|
||||
|
||||
// Create |10000>|0>+ i|00100>|1>
|
||||
(Controlled (JWOptimizedApplyTrotterStep(data, time, time, parityQubit[0], _)))([ctrl], qubitsC[0 .. 5]);
|
||||
AssertProb([PauliZ], [qubitsC[arrMeasure[0]]], One, 0.5, "PQTermTest probability failed.", 1E-10);
|
||||
|
||||
// Create |10000>|0>+ i|10000>|1>
|
||||
CNOT(ctrl, qubitsC[0]);
|
||||
CNOT(ctrl, qubitsC[2]);
|
||||
AssertProb([PauliZ], [qubitsC[arrMeasure[0]]], One, 0.0, "PQTermTest probability failed.", 1E-10);
|
||||
AssertPhase(-0.25 * PI(), ctrl, 1E-10);
|
||||
ResetAll(qubitsC + parityQubit);
|
||||
H(ctrl);
|
||||
X(qubitsC[arrPrep[0]]);
|
||||
X(qubitsC[1]);
|
||||
|
||||
// Create |11000>|0>- i|01100>|1>
|
||||
(Controlled (JWOptimizedApplyTrotterStep(data, time, time, parityQubit[0], _)))([ctrl], qubitsC[0 .. 5]);
|
||||
AssertProb([PauliZ], [qubitsC[arrMeasure[0]]], One, 0.5, "PQTermTest probability failed.", 1E-10);
|
||||
|
||||
// Create |11000>|0>- i|11000>|1>
|
||||
CNOT(ctrl, qubitsC[0]);
|
||||
CNOT(ctrl, qubitsC[2]);
|
||||
AssertProb([PauliZ], [qubitsC[arrMeasure[0]]], One, 0.0, "PQTermTest probability failed.", 1E-10);
|
||||
AssertPhase(0.25 * PI(), ctrl, 1E-10);
|
||||
ResetAll(qubitsC + parityQubit);
|
||||
|
||||
use parityQubit = Qubit();
|
||||
|
||||
use qubits = Qubit[6] {
|
||||
// Create |100000>
|
||||
for idx in 0 .. 3 {
|
||||
X(qubits[arrPrep[idx]]);
|
||||
JWOptimizedApplyTrotterStep(data, time, time, parityQubit, qubits);
|
||||
Diag.AssertMeasurementProbability([PauliZ], [qubits[arrMeasure[idx]]], One, 1.0, "PQTermTest probability failed.", 1E-10);
|
||||
ResetAll(qubits + [parityQubit]);
|
||||
}
|
||||
}
|
||||
|
||||
// Test phase
|
||||
use qubitsC = Qubit[7] {
|
||||
// Create |1000>(|0>+|1>)
|
||||
let ctrl = qubitsC[6];
|
||||
H(ctrl);
|
||||
X(qubitsC[arrPrep[0]]);
|
||||
|
||||
// Create |10000>|0>+ i|00100>|1>
|
||||
(Controlled (JWOptimizedApplyTrotterStep(data, time, time, parityQubit, _)))([ctrl], qubitsC[0 .. 5]);
|
||||
Diag.AssertMeasurementProbability([PauliZ], [qubitsC[arrMeasure[0]]], One, 0.5, "PQTermTest probability failed.", 1E-10);
|
||||
|
||||
// Create |10000>|0>+ i|10000>|1>
|
||||
CNOT(ctrl, qubitsC[0]);
|
||||
CNOT(ctrl, qubitsC[2]);
|
||||
Diag.AssertMeasurementProbability([PauliZ], [qubitsC[arrMeasure[0]]], One, 0.0, "PQTermTest probability failed.", 1E-10);
|
||||
Diag.AssertPhase(-0.25 * PI(), ctrl, 1E-10);
|
||||
ResetAll(qubitsC + [parityQubit]);
|
||||
H(ctrl);
|
||||
X(qubitsC[arrPrep[0]]);
|
||||
X(qubitsC[1]);
|
||||
|
||||
// Create |11000>|0>- i|01100>|1>
|
||||
(Controlled (JWOptimizedApplyTrotterStep(data, time, time, parityQubit, _)))([ctrl], qubitsC[0 .. 5]);
|
||||
Diag.AssertMeasurementProbability([PauliZ], [qubitsC[arrMeasure[0]]], One, 0.5, "PQTermTest probability failed.", 1E-10);
|
||||
|
||||
// Create |11000>|0>- i|11000>|1>
|
||||
CNOT(ctrl, qubitsC[0]);
|
||||
CNOT(ctrl, qubitsC[2]);
|
||||
Diag.AssertMeasurementProbability([PauliZ], [qubitsC[arrMeasure[0]]], One, 0.0, "PQTermTest probability failed.", 1E-10);
|
||||
Diag.AssertPhase(0.25 * PI(), ctrl, 1E-10);
|
||||
ResetAll(qubitsC + [parityQubit]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Test phase of PP term.
|
||||
operation PQQPTermFromLiquidOrbitalTestOp (identity : Double, data : JWOptimizedHTerms) : Unit {
|
||||
|
||||
let time = 1.0;
|
||||
|
||||
using (parityQubit = Qubit[1]) {
|
||||
|
||||
using (qubits = Qubit[5]) {
|
||||
let ctrl = qubits[Length(qubits) - 1];
|
||||
let qubitSys = qubits[0 .. Length(qubits) - 2];
|
||||
|
||||
// Create |1100>(|0>+|1>);
|
||||
H(ctrl);
|
||||
X(qubitSys[0]);
|
||||
X(qubitSys[1]);
|
||||
|
||||
// Create |1100>(|0>+e^{i t / 2}|1>);
|
||||
(Controlled (JWOptimizedApplyTrotterStep(data, time, time, parityQubit[0], _)))([ctrl], qubitSys);
|
||||
(Controlled (Exp([PauliI], time * identity, _)))([ctrl], [qubitSys[0]]);
|
||||
AssertPhase(-0.5 * time, ctrl, 1E-10);
|
||||
ResetAll(qubits);
|
||||
|
||||
// Create |1110>(|0>+|1>);
|
||||
H(ctrl);
|
||||
X(qubitSys[0]);
|
||||
X(qubitSys[1]);
|
||||
X(qubitSys[2]);
|
||||
|
||||
// Create |1100>(|0>+e^{i 2 t}|1>);
|
||||
(Controlled (JWOptimizedApplyTrotterStep(data, time, time, parityQubit[0], _)))([ctrl], qubitSys);
|
||||
(Controlled (Exp([PauliI], time * identity, _)))([ctrl], [qubitSys[0]]);
|
||||
AssertPhase(-1.0 * time, ctrl, 1E-10);
|
||||
ResetAll(qubits);
|
||||
|
||||
// Create |1111>(|0>+|1>);
|
||||
H(ctrl);
|
||||
X(qubitSys[0]);
|
||||
X(qubitSys[1]);
|
||||
X(qubitSys[2]);
|
||||
X(qubitSys[3]);
|
||||
|
||||
// Create |1100>(|0>+e^{i 4 t}|1>);
|
||||
(Controlled (JWOptimizedApplyTrotterStep(data, time, time, parityQubit[0], _)))([ctrl], qubitSys);
|
||||
(Controlled (Exp([PauliI], time * identity, _)))([ctrl], [qubitSys[0]]);
|
||||
AssertPhase(-2.0 * time, ctrl, 1E-10);
|
||||
ResetAll(qubits);
|
||||
}
|
||||
}
|
||||
|
||||
use parityQubit = Qubit();
|
||||
use qubits = Qubit[5];
|
||||
let ctrl = qubits[Length(qubits) - 1];
|
||||
let qubitSys = qubits[0 .. Length(qubits) - 2];
|
||||
|
||||
// Create |1100>(|0>+|1>);
|
||||
H(ctrl);
|
||||
X(qubitSys[0]);
|
||||
X(qubitSys[1]);
|
||||
|
||||
// Create |1100>(|0>+e^{i t / 2}|1>);
|
||||
(Controlled (JWOptimizedApplyTrotterStep(data, time, time, parityQubit, _)))([ctrl], qubitSys);
|
||||
(Controlled (Exp([PauliI], time * identity, _)))([ctrl], [qubitSys[0]]);
|
||||
Diag.AssertPhase(-0.5 * time, ctrl, 1E-10);
|
||||
ResetAll(qubits);
|
||||
|
||||
// Create |1110>(|0>+|1>);
|
||||
H(ctrl);
|
||||
X(qubitSys[0]);
|
||||
X(qubitSys[1]);
|
||||
X(qubitSys[2]);
|
||||
|
||||
// Create |1100>(|0>+e^{i 2 t}|1>);
|
||||
(Controlled (JWOptimizedApplyTrotterStep(data, time, time, parityQubit, _)))([ctrl], qubitSys);
|
||||
(Controlled (Exp([PauliI], time * identity, _)))([ctrl], [qubitSys[0]]);
|
||||
Diag.AssertPhase(-1.0 * time, ctrl, 1E-10);
|
||||
ResetAll(qubits);
|
||||
|
||||
// Create |1111>(|0>+|1>);
|
||||
H(ctrl);
|
||||
X(qubitSys[0]);
|
||||
X(qubitSys[1]);
|
||||
X(qubitSys[2]);
|
||||
X(qubitSys[3]);
|
||||
|
||||
// Create |1100>(|0>+e^{i 4 t}|1>);
|
||||
(Controlled (JWOptimizedApplyTrotterStep(data, time, time, parityQubit, _)))([ctrl], qubitSys);
|
||||
(Controlled (Exp([PauliI], time * identity, _)))([ctrl], [qubitSys[0]]);
|
||||
Diag.AssertPhase(-2.0 * time, ctrl, 1E-10);
|
||||
ResetAll(qubits);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
operation PQQRTermFromLiquidOrbitalTestOp (data : JWOptimizedHTerms) : Unit {
|
||||
|
||||
|
||||
// Test probability
|
||||
mutable time = (4.0 * 0.5) * PI();
|
||||
mutable arrPrep = new Int[4];
|
||||
set arrPrep = [0, 1, 2, 3];
|
||||
mutable arrMeasure = new Int[4];
|
||||
set arrMeasure = [1, 0, 3, 2];
|
||||
|
||||
using (parityQubit = Qubit[1]) {
|
||||
|
||||
using (qubits = Qubit[4]) {
|
||||
|
||||
// Create |1000>
|
||||
for (idx in 0 .. 3) {
|
||||
X(qubits[arrPrep[idx]]);
|
||||
JWOptimizedApplyTrotterStep(data, time, 0.1 * time, parityQubit[0], qubits);
|
||||
AssertProb([PauliZ], [qubits[arrMeasure[idx]]], One, 0.0, "PQQRTermTest a probability failed.", 1E-10);
|
||||
ResetAll(qubits);
|
||||
}
|
||||
|
||||
// Create |1010>
|
||||
set time = (0.5 * PI()) / Sqrt(2.0);
|
||||
X(qubits[arrPrep[0]]);
|
||||
X(qubits[2]);
|
||||
JWOptimizedApplyTrotterStep(data, time, 0.01 * time, parityQubit[0], qubits);
|
||||
AssertProb([PauliZ], [qubits[arrMeasure[0]]], One, 0.5, "PQQRTermTest b probability failed.", 0.01);
|
||||
ResetAll(qubits);
|
||||
|
||||
// Create |1001>
|
||||
set time = (0.5 * PI()) / Sqrt(2.0);
|
||||
X(qubits[arrPrep[0]]);
|
||||
X(qubits[3]);
|
||||
JWOptimizedApplyTrotterStep(data, time, 0.01 * time, parityQubit[0], qubits);
|
||||
AssertProb([PauliZ], [qubits[arrMeasure[0]]], One, 0.25, "PQQRTermTest c probability failed.", 0.01);
|
||||
ResetAll(qubits);
|
||||
}
|
||||
|
||||
use parityQubit = Qubit();
|
||||
use qubits = Qubit[4];
|
||||
|
||||
// Create |1000>
|
||||
for idx in 0 .. 3 {
|
||||
X(qubits[arrPrep[idx]]);
|
||||
JWOptimizedApplyTrotterStep(data, time, 0.1 * time, parityQubit, qubits);
|
||||
Diag.AssertMeasurementProbability([PauliZ], [qubits[arrMeasure[idx]]], One, 0.0, "PQQRTermTest a probability failed.", 1E-10);
|
||||
ResetAll(qubits);
|
||||
}
|
||||
|
||||
// Create |1010>
|
||||
set time = (0.5 * PI()) / Sqrt(2.0);
|
||||
X(qubits[arrPrep[0]]);
|
||||
X(qubits[2]);
|
||||
JWOptimizedApplyTrotterStep(data, time, 0.01 * time, parityQubit, qubits);
|
||||
Diag.AssertMeasurementProbability([PauliZ], [qubits[arrMeasure[0]]], One, 0.5, "PQQRTermTest b probability failed.", 0.01);
|
||||
ResetAll(qubits);
|
||||
|
||||
// Create |1001>
|
||||
set time = (0.5 * PI()) / Sqrt(2.0);
|
||||
X(qubits[arrPrep[0]]);
|
||||
X(qubits[3]);
|
||||
JWOptimizedApplyTrotterStep(data, time, 0.01 * time, parityQubit, qubits);
|
||||
Diag.AssertMeasurementProbability([PauliZ], [qubits[arrMeasure[0]]], One, 0.25, "PQQRTermTest c probability failed.", 0.01);
|
||||
ResetAll(qubits);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
operation PQRSTermFromLiquidOrbitalTestOp (data : JWOptimizedHTerms) : Unit {
|
||||
|
||||
|
||||
// Test probability
|
||||
mutable time = 1.0;
|
||||
mutable prob = Sin(time) * Sin(time);
|
||||
|
||||
using (parityQubit = Qubit[1]) {
|
||||
|
||||
using (qubits = Qubit[4]) {
|
||||
|
||||
// Create |1010>
|
||||
X(qubits[0]);
|
||||
X(qubits[2]);
|
||||
JWOptimizedApplyTrotterStep(data, time, time, parityQubit[0], qubits);
|
||||
AssertProb([PauliZ], [qubits[1]], One, prob, "PQRSTermTest a probability failed.", 1E-10);
|
||||
AssertProb([PauliZ], [qubits[3]], One, prob, "PQRSTermTest b probability failed.", 1E-10);
|
||||
ResetAll(qubits);
|
||||
}
|
||||
}
|
||||
|
||||
use parityQubit = Qubit();
|
||||
use qubits = Qubit[4];
|
||||
|
||||
// Create |1010>
|
||||
X(qubits[0]);
|
||||
X(qubits[2]);
|
||||
JWOptimizedApplyTrotterStep(data, time, time, parityQubit, qubits);
|
||||
Diag.AssertMeasurementProbability([PauliZ], [qubits[1]], One, prob, "PQRSTermTest a probability failed.", 1E-10);
|
||||
Diag.AssertMeasurementProbability([PauliZ], [qubits[3]], One, prob, "PQRSTermTest b probability failed.", 1E-10);
|
||||
ResetAll(qubits);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
operation JWOptimizedApplyTrotterStep (data : JWOptimizedHTerms, time : Double, trotterStepSize : Double, parityQubit : Qubit, qubits : Qubit[])
|
||||
: Unit is Adj + Ctl {
|
||||
let generatorSystem = JWOptimizedGeneratorSystem(data);
|
||||
|
@ -522,7 +493,5 @@ namespace SystemTestJWOptimizedES {
|
|||
let simulationAlgorithm = TrotterSimulationAlgorithm(trotterStepSize, trotterOrder);
|
||||
simulationAlgorithm!(time, evolutionGenerator, qubits);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace Microsoft.Quantum.Research.Tests {
|
|||
|
||||
repeat {
|
||||
mutable actual = 0.0;
|
||||
using (eigenstate = Qubit()) {
|
||||
use eigenstate = Qubit() {
|
||||
X(eigenstate);
|
||||
set actual = RandomWalkPhaseEstimation(0.0, 1.0, 61, 100000, 0, oracle, [eigenstate]);
|
||||
Reset(eigenstate);
|
||||
|
@ -34,7 +34,8 @@ namespace Microsoft.Quantum.Research.Tests {
|
|||
} else {
|
||||
return ();
|
||||
}
|
||||
} until (nAttemptsSoFar >= nAttemptsAllowed);
|
||||
}
|
||||
until nAttemptsSoFar >= nAttemptsAllowed;
|
||||
|
||||
fail $"CheckBayesianPERandomWalk failed {nAttemptsSoFar} times in a row.";
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче