-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphase-rotation.js
More file actions
49 lines (38 loc) · 878 Bytes
/
Copy pathphase-rotation.js
File metadata and controls
49 lines (38 loc) · 878 Bytes
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
const logger = require('../src/logger')()
circuit('phase rotation with 1 qubit on', 1)
.x(0)
.repeat(9, function(index) {
this.u1(0, [], { lambda: 'pi / 18' })
})
.run('trace', 'changed')
circuit('phase rotation with 4 qubits in superposition', 4)
.unit('all').h().circuit()
.spread(function(index) {
this.u1(index, [], { lambda: 'pi / 15' })
})
.run()
function circuit(name, size) {
let circuit = require('../src/circuit.js')({
name: name,
size: size,
logger: logger,
engine: 'optimized',
order: ['targets', 'controls']
})
return Object.assign(circuit, {
repeat: function(value, fn) {
for (let i = 0; i < value; i++) {
fn.apply(this, [i])
}
return this
},
spread: function(fn) {
for (var i = 0; i < this.size; i++) {
for (var j = 0; j < 1 << i; j++) {
fn.apply(this, [i])
}
}
return this
}
})
}