1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/mirrors-quantum

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
Клонировать/Скачать
RepeatUntilSuccessCircuitsTests.qs 2.9 КБ
Копировать Редактировать Web IDE Исходные данные Просмотреть построчно История
Chris Granade Отправлено 28.01.2021 09:00 7196bf3
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
namespace Microsoft.Quantum.Samples.UnitTesting {
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Math;
open Microsoft.Quantum.Convert;
open Microsoft.Quantum.Diagnostics;
open Microsoft.Quantum.Canon;
///////////////////////////////////////////////////////////////////////////////////////////////
// Unit test to circuits implementing for exp(±i⋅ArcTan(2)⋅Z) with using Repeat-Until-Success
// (RUS) protocols. Note that all test operations names end with `Test`
///////////////////////////////////////////////////////////////////////////////////////////////
/// # Summary
/// Here we check the correctness of Repeat Until Success unitary circuits
/// defined in RepeatUntilSuccessCircuits.qs.
@Test("QuantumSimulator")
operation CheckRepeatUntilSuccessRotatesByCorrectAngle() : Unit {
// List of operations to test (actual,expected)
// we first test ExpIZArcTan2NC and its Adjoint
// next test ExpIZArcTan2PS and its Adjoint
let testList = [
(ExpIZArcTan2NC, Exp([PauliZ], ArcTan(2.0), _)),
(Adjoint ExpIZArcTan2NC, Exp([PauliZ], -ArcTan(2.0), _)),
(ExpIZArcTan2PS, Exp([PauliZ], ArcTan(2.0), _)),
(Adjoint ExpIZArcTan2PS, Exp([PauliZ], -ArcTan(2.0), _))
];
// As the circuits are probabilistic we repeat tests multiple times
for i in 0 .. 400 {
// next go over everything in testList
for (actual, expected) in testList {
// This will log the names and parameters of operations being tested
Message($"Testing {actual} against {expected}. Attempt: {i}");
// Using Referenced testing, as it uses only one call to the operation
// Note that in QCTraceSimulator call graph
// ExpIZArcTan2NC and ExpIZArcTan2PS will be called from ApplyToFirstQubit
AssertOperationsEqualReferenced(1, ApplyToFirstQubit(actual, _), expected);
}
}
}
/// # Summary
/// Here we check the correctness of Repeat Until Success state preparation circuit
/// defined in RepeatUntilSuccessCircuits.qs.
@Test("QuantumSimulator")
operation CheckRepeatUntilSuccessPreparesCorrectState() : Unit {
for i in 0 .. 100 {
use target = Qubit();
// Prepare input in |+⟩ state
H(target);
// Apply function being tested
RepeatUntilSuccessStatePreparation(target);
// Assert that prepared state is (√2/√3,1/√3)
let zeroAmp = Complex(Sqrt(2.0) / Sqrt(3.0), 0.0);
let oneAmp = Complex(1.0 / Sqrt(3.0), 0.0);
AssertQubitIsInStateWithinTolerance((zeroAmp, oneAmp), target, 1E-10);
// Reset target back to |0⟩
Reset(target);
}
}
}

Опубликовать ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://api.gitlife.ru/oschina-mirror/mirrors-quantum.git
git@api.gitlife.ru:oschina-mirror/mirrors-quantum.git
oschina-mirror
mirrors-quantum
mirrors-quantum
main