-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbell_state.dart
48 lines (36 loc) · 1.21 KB
/
bell_state.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import 'package:qartvm/qartvm.dart';
import 'utils.dart';
void main() {
// Bell state (superposition + entanglement)
//
// ---
// 0 ----| H |---- X ------
// ---
// -----
// 1 -----------| NOT |----
// -----
final circuit = QCircuit(QGateBuilder.get(2));
circuit.hadamard(0);
circuit.not(1, controls: 0);
describe(circuit);
draw(circuit);
final qmem = QMemorySpace.zero(circuit.size);
print('Initial states');
print(' * amplitudes: ${amplInfo(qmem, fractionDigits: 6)}');
print(' * probabilities: ${probInfo(qmem, fractionDigits: 2)}');
circuit.execute(qmem);
print('Final states');
print(' * amplitudes: ${amplInfo(qmem, fractionDigits: 6)}');
print(' * probabilities: ${probInfo(qmem, fractionDigits: 2)}');
print('');
final a = qmem.read(qubits: [0]);
print('measured qubit 0 = $a');
print(
' * amplitudes after measurement of qubit 0: ${amplInfo(qmem, fractionDigits: 6)}');
print(
' * probabilities after measurement of qubit 0: ${probInfo(qmem, fractionDigits: 6)}');
final b = qmem.read(qubits: [1]);
if (a != b) {
throw Exception('Measurement of qubit 1 yielded unexpected result $b');
}
}