-
Notifications
You must be signed in to change notification settings - Fork 0
/
teleportation.js
66 lines (51 loc) · 1.51 KB
/
teleportation.js
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const logger = require('../src/logger')()
teleport({ state: 'a', from: 1, to: 2})
teleport({ state: 'b', from: 4, to: 1})
function teleport(options) {
circuit(`illustrating state \'${options.state}\' applied to the source qubit ${options.from}`, 5)
.state(options.state, options.from)
.run()
circuit(`illustrating state \'${options.state}\' applied to the destination qubit ${options.to}`, 5)
.state(options.state, options.to)
.run()
circuit(`set state \'${options.state}\' on the source qubit ${options.from} then teleport to the destination qubit ${options.to}`, 5)
.state(options.state, options.from)
.teleport(options.from, options.to)
.measure(options.from, options.to)
.run('trace', 'changed')
}
function circuit(name, size, options) {
let circuit = require('../src/circuit.js')({
name: name,
size: size,
logger: logger,
engine: 'optimized',
order: ['targets', 'controls']
})
return Object.assign(circuit, {
state: function(state, target) {
return this['state_' + state].apply(this, [target])
},
state_a: function(target) {
return this.h(target).r4(target).h(target).r4(target).h(target)
},
state_b: function(target) {
return this.h(target).r8(target).h(target).r4(target).h(target)
},
teleport: function(from, to) {
let transport = 0
return this
.h(from)
.h(to)
.cx(transport, to)
.cx(transport, from)
.h(from)
.cx(to, transport)
.h(to)
.cx(to, from)
},
measure: function(from, to) {
return this.h(from).h(0)
}
})
}