Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update BellStates: allocate qubits inside the loop and remove ResetAll #1447

Merged
merged 1 commit into from
Apr 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions samples/algorithms/BellState.qs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ namespace Sample {

@EntryPoint()
operation BellStates() : (Result, Result)[] {
// Allocate the two qubits that will be used to create a Bell state.
use register = Qubit[2];

// This array contains a label and a preparation operation for each one
// of the four Bell states.
let bellStateTuples = [
Expand All @@ -28,6 +25,8 @@ namespace Sample {
// and measure the Bell state qubits.
mutable measurements = [];
for (label, prepare) in bellStateTuples {
// Allocate the two qubits that will be used to create a Bell state.
use register = Qubit[2];
prepare(register);
Message($"Bell state {label}:");
DumpMachine();
Expand All @@ -37,27 +36,23 @@ namespace Sample {
}

operation PreparePhiPlus(register : Qubit[]) : Unit {
ResetAll(register); // |00〉
H(register[0]); // |+0〉
CNOT(register[0], register[1]); // 1/sqrt(2)(|00〉 + |11〉)
}

operation PreparePhiMinus(register : Qubit[]) : Unit {
ResetAll(register); // |00〉
H(register[0]); // |+0〉
Z(register[0]); // |-0〉
CNOT(register[0], register[1]); // 1/sqrt(2)(|00〉 - |11〉)
}

operation PreparePsiPlus(register : Qubit[]) : Unit {
ResetAll(register); // |00〉
H(register[0]); // |+0〉
X(register[1]); // |+1〉
CNOT(register[0], register[1]); // 1/sqrt(2)(|01〉 + |10〉)
}

operation PreparePsiMinus(register : Qubit[]) : Unit {
ResetAll(register); // |00〉
H(register[0]); // |+0〉
Z(register[0]); // |-0〉
X(register[1]); // |-1〉
Expand Down
Loading