AllowAtMostNCallsCA 작업
네임스페이스: Microsoft.Quantum.Diagnostics
패키지: Microsoft.Quantum.Standard
이 연산과 해당 인접에 대한 호출 사이에 는 지정된 작업이 최대 특정 횟수만큼 호출되는 것을 어설션합니다.
작업 호출은 지정된 변형을 포함하는 경우 고려됩니다. 예를 들어 가 인 Adjoint X
경우 X
op
또는 Controlled X
도 계산되지만 가 이면 op
Controlled X
또는 Controlled Adjoint X
만 Controlled X
계산됩니다.
operation AllowAtMostNCallsCA<'TInput, 'TOutput> (nTimes : Int, op : ('TInput => 'TOutput), message : String) : Unit is Adj
입력
nTimes: Int
호출될 수 있는 op
최대 횟수입니다.
op: 'TInput => 'TOutput
호출을 제한해야 하는 작업입니다.
message: String
실패 시 표시할 메시지입니다.
출력: 단위
형식 매개 변수
'TInput
'TOutput
예제
이 진단을 지원하는 컴퓨터에서 실행할 때 다음 코드 조각이 실패합니다.
within {
AllowAtMostNCallsCA(3, H, "Too many calls to H.");
} apply {
use register = Qubit[4];
// Fails since this calls H four times, rather than the
// allowed maximum of three.
ApplyToEach(H, register);
}
또 다른 예제에서는 제한된 호출이 처리되는 방법을 보여 줍니다.
within {
// Both tests will pass in this case
AllowAtMostNCallsCA(1, Controlled H, "Too many calls to Controlled H.");
AllowAtMostNCallsCA(2, H, "Too many calls to H or Controlled H.");
} apply {
use (a, b) = (Qubit(), Qubit());
H(a);
Controlled H([a], b);
ResetAll([a, b]);
}
설명
이 작업은 지원하지 않는 대상에 대한 no-op으로 대체될 수 있습니다.