Open Astlaan opened 4 years ago
This is the desired, correct circuit, that I have written in qsoverlay:
RY q[2], -1.57079633, time = 10
RY q[5], -1.57079633, time = 10
CZ q[2], q[5], time = 40
RY q[5], 1.57079633, time = 70
RY q[2], -1.57079633, time = 70
CZ q[5], q[2], time = 100
RY q[2], 1.57079633, time = 130
RY q[0], -1.57079633, time = 130
CZ q[2], q[0], time = 160
RY q[5], -1.57079633, time = 190
CZ q[2], q[5], time = 220
RY q[5], 1.57079633, time = 250
CZ q[2], q[5], time = 280
Y q[0], time = 310
RX q[0], -0.785398163, time = 330
RY q[2], 1.57079633, time = 330
X q[2], time = 350
Y q[0], time = 350
CZ q[2], q[0], time = 380
Y q[5], time = 410
RX q[5], -0.785398163, time = 430
RY q[5], -1.57079633, time = 450
RY q[2], -1.57079633, time = 450
CZ q[5], q[2], time = 480
Y q[2], time = 510
RX q[2], 0.785398163, time = 530
Y q[2], time = 550
CZ q[5], q[2], time = 580
RY q[2], 1.57079633, time = 610
RY q[5], -1.57079633, time = 610
CZ q[2], q[5], time = 640
RY q[5], 1.57079633, time = 670
RY q[2], -1.57079633, time = 670
CZ q[5], q[2], time = 700
Y q[0], time = 730
RX q[0], 0.785398163, time = 750
RY q[2], 1.57079633, time = 770
Y q[0], time = 770
CZ q[2], q[0], time = 800
RY q[5], -1.57079633, time = 830
CZ q[2], q[5], time = 860
CZ q[2], q[5], time = 900
RY q[5], 1.57079633, time = 930
RY q[2], -1.57079633, time = 930
CZ q[5], q[2], time = 960
Y q[0], time = 990
RX q[0], -0.785398163, time = 1010
RY q[2], 1.57079633, time = 1030
Y q[0], time = 1030
CZ q[2], q[0], time = 1060
RY q[5], -1.57079633, time = 1090
CZ q[2], q[5], time = 1120
RY q[2], 1.57079633, time = 1150
RX q[2], -0.785398163, time = 1170
X q[2], time = 1190
CZ q[2], q[5], time = 1220
RY q[5], 1.57079633, time = 1250
RY q[2], -1.57079633, time = 1250
CZ q[5], q[2], time = 1280
Y q[0], time = 1310
RX q[0], 0.785398163, time = 1330
RY q[2], 1.57079633, time = 1350
Y q[0], time = 1350
CZ q[2], q[0], time = 1380
RY q[3], -1.57079633, time = 1410
RY q[6], -1.57079633, time = 1410
CZ q[3], q[6], time = 1440
RY q[5], -1.57079633, time = 1450
CZ q[2], q[5], time = 1480
RY q[3], -1.57079633, time = 1490
RY q[6], 1.57079633, time = 1510
RY q[2], 1.57079633, time = 1510
CZ q[6], q[3], time = 1540
RX q[2], -0.785398163, time = 1530
RY q[2], -1.57079633, time = 1550
CZ q[2], q[5], time = 1580
RY q[3], 1.57079633, time = 1610
RY q[6], -1.57079633, time = 1610
CZ q[3], q[6], time = 1640
RY q[5], 1.57079633, time = 1650
RY q[2], -1.57079633, time = 1650
CZ q[5], q[2], time = 1680
RY q[2], 1.57079633, time = 1710
RY q[6], 1.57079633, time = 1710
CZ q[2], q[6], time = 1740
RY q[5], -1.57079633, time = 1770
CZ q[2], q[5], time = 1800
Y q[0], time = 1830
RX q[0], -0.785398163, time = 1850
RY q[2], 1.57079633, time = 1850
X q[2], time = 1870
Y q[0], time = 1870
CZ q[2], q[0], time = 1900
RY q[5], 1.57079633, time = 1930
RY q[2], -1.57079633, time = 1930
CZ q[5], q[2], time = 1960
Y q[2], time = 1990
RX q[2], 0.785398163, time = 2010
Y q[2], time = 2030
CZ q[5], q[2], time = 2060
Y q[0], time = 2090
RX q[0], 0.785398163, time = 2110
RY q[2], 1.57079633, time = 2130
RY q[0], 1.57079633, time = 2130
CZ q[2], q[0], time = 2160
RY q[0], 1.57079633, time = 2190
RY q[2], -1.57079633, time = 2190
CZ q[0], q[2], time = 2220
RY q[2], 1.57079633, time = 2250
CZ q[5], q[2], time = 2280
RY q[0], -1.57079633, time = 2310
CZ q[2], q[0], time = 2340
Y q[2], time = 2370
RX q[2], -0.785398163, time = 2390
RY q[0], 1.57079633, time = 2410
Y q[2], time = 2410
CZ q[0], q[2], time = 2440
Y q[2], time = 2470
RX q[2], 0.785398163, time = 2490
Y q[2], time = 2510
CZ q[5], q[2], time = 2540
RY q[0], 1.57079633, time = 2570
RX q[0], -0.785398163, time = 2590
X q[0], time = 2610
CZ q[0], q[2], time = 2640
RY q[2], 1.57079633, time = 2670
RY q[5], -1.57079633, time = 2670
CZ q[2], q[5], time = 2700
RY q[5], 1.57079633, time = 2730
RY q[6], 1.57079633, time = 2730
And this is the code qsoverlay outputs:
RY, q[2], -1.57079633, time: 10
RY, q[5], -1.57079633, time: 10
RY, q[0], -3.14159265, time: 10.0
RX, q[2], -3.14159265, time: 10.0
RY, q[5], -3.14159265, time: 10.0
RY, q[0], -3.14159265, time: 30.0
RY, q[2], -3.14159265, time: 30.0
CZ, q[2], q[2], time: 40
RY, q[2], -3.14159265, time: 50.0
RY, q[0], -3.14159265, time: 50.0
RY, q[5], 1.57079633, time: 70
RY, q[2], -1.57079633, time: 70
RY, q[0], -3.14159265, time: 70.0
RX, q[2], -3.14159265, time: 70.0
RY, q[0], -3.14159265, time: 90.0
RX, q[2], -3.14159265, time: 90.0
CZ, q[5], q[5], time: 100
RY, q[0], -3.14159265, time: 110.0
RY, q[2], -3.14159265, time: 110.0
RY, q[2], 1.57079633, time: 130
RY, q[0], -1.57079633, time: 130
RY, q[0], -3.14159265, time: 130.0
RY, q[2], -3.14159265, time: 130.0
RY, q[0], -3.14159265, time: 150.0
RY, q[2], -3.14159265, time: 150.0
CZ, q[2], q[2], time: 160
RY, q[0], -3.14159265, time: 170.0
RY, q[2], -3.14159265, time: 170.0
RY, q[5], -1.57079633, time: 190
RY, q[0], -3.14159265, time: 190.0
RY, q[2], -3.14159265, time: 190.0
RY, q[0], -3.14159265, time: 210.0
RY, q[2], -3.14159265, time: 210.0
CZ, q[2], q[2], time: 220
RX, q[0], -3.14159265, time: 230.0
RY, q[5], 1.57079633, time: 250
CZ, q[2], q[2], time: 280
RX, q[0], -0.785398163, time: 330
RY, q[2], 1.57079633, time: 330
CZ, q[2], q[2], time: 380
RX, q[5], -0.785398163, time: 430
RY, q[5], -1.57079633, time: 450
RY, q[2], -1.57079633, time: 450
CZ, q[5], q[5], time: 480
RX, q[2], 0.785398163, time: 530
CZ, q[5], q[5], time: 580
RY, q[2], 1.57079633, time: 610
RY, q[5], -1.57079633, time: 610
CZ, q[2], q[2], time: 640
RY, q[5], 1.57079633, time: 670
RY, q[2], -1.57079633, time: 670
CZ, q[5], q[5], time: 700
RX, q[0], 0.785398163, time: 750
RY, q[2], 1.57079633, time: 770
CZ, q[2], q[2], time: 800
RY, q[5], -1.57079633, time: 830
CZ, q[2], q[2], time: 860
CZ, q[2], q[2], time: 900
RY, q[5], 1.57079633, time: 930
RY, q[2], -1.57079633, time: 930
CZ, q[5], q[5], time: 960
RX, q[0], -0.785398163, time: 1010
RY, q[2], 1.57079633, time: 1030
CZ, q[2], q[2], time: 1060
RY, q[5], -1.57079633, time: 1090
CZ, q[2], q[2], time: 1120
RY, q[2], 1.57079633, time: 1150
RX, q[2], -0.785398163, time: 1170
CZ, q[2], q[2], time: 1220
RY, q[5], 1.57079633, time: 1250
RY, q[2], -1.57079633, time: 1250
CZ, q[5], q[5], time: 1280
RX, q[0], 0.785398163, time: 1330
RY, q[2], 1.57079633, time: 1350
CZ, q[2], q[2], time: 1380
RY, q[3], -1.57079633, time: 1410
RY, q[6], -1.57079633, time: 1410
CZ, q[3], q[3], time: 1440
RY, q[5], -1.57079633, time: 1450
CZ, q[2], q[2], time: 1480
RY, q[3], -1.57079633, time: 1490
RY, q[6], 1.57079633, time: 1510
RY, q[2], 1.57079633, time: 1510
RX, q[2], -0.785398163, time: 1530
CZ, q[6], q[6], time: 1540
RY, q[2], -1.57079633, time: 1550
CZ, q[2], q[2], time: 1580
RY, q[3], 1.57079633, time: 1610
RY, q[6], -1.57079633, time: 1610
CZ, q[3], q[3], time: 1640
RY, q[5], 1.57079633, time: 1650
RY, q[2], -1.57079633, time: 1650
CZ, q[5], q[5], time: 1680
RY, q[2], 1.57079633, time: 1710
RY, q[6], 1.57079633, time: 1710
CZ, q[2], q[2], time: 1740
RY, q[5], -1.57079633, time: 1770
CZ, q[2], q[2], time: 1800
RX, q[0], -0.785398163, time: 1850
RY, q[2], 1.57079633, time: 1850
CZ, q[2], q[2], time: 1900
RY, q[5], 1.57079633, time: 1930
RY, q[2], -1.57079633, time: 1930
CZ, q[5], q[5], time: 1960
RX, q[2], 0.785398163, time: 2010
CZ, q[5], q[5], time: 2060
RX, q[0], 0.785398163, time: 2110
RY, q[2], 1.57079633, time: 2130
RY, q[0], 1.57079633, time: 2130
CZ, q[2], q[2], time: 2160
RY, q[0], 1.57079633, time: 2190
RY, q[2], -1.57079633, time: 2190
CZ, q[0], q[0], time: 2220
RY, q[2], 1.57079633, time: 2250
CZ, q[5], q[5], time: 2280
RY, q[0], -1.57079633, time: 2310
CZ, q[2], q[2], time: 2340
RX, q[2], -0.785398163, time: 2390
RY, q[0], 1.57079633, time: 2410
CZ, q[0], q[0], time: 2440
RX, q[2], 0.785398163, time: 2490
CZ, q[5], q[5], time: 2540
RY, q[0], 1.57079633, time: 2570
RX, q[0], -0.785398163, time: 2590
CZ, q[0], q[0], time: 2640
RY, q[2], 1.57079633, time: 2670
RY, q[5], -1.57079633, time: 2670
CZ, q[2], q[2], time: 2700
RY, q[5], 1.57079633, time: 2730
RY, q[6], 1.57079633, time: 2730
Notice that qsoverlay somehow decided to ignore the position of my X
and Y
gates. Apparently then, this is another instance of the issue I filed before (#18) , where the prepz gates would suffer from a wrong timestamp issue.
I checked, and the error is already present before b.finalize() is called: the X and Y gates already have an incorrect timing before this.
Ok, I think I found the error. I made some changes and the gates are now introduced with the correct time in builder.py.
The problem was that some gate functions (X_gate
, Y_gate
,Z_gate
, had_from_rot
, CNOT_from_CZ
, CRX_from_CZ
) were incorrectly defined in qsoverlay/gate_functions.py
. These functions receive time as argument, but don't pass it to builder when using the <
(__lt__
) operator.
A fix possibility would be to pass a dictionary (kwargs
) instead of unfolding it (**kwargs
) to these gate_functions. And to only unfold the dictionary in the __lt__
function. However, I think that might require changes in many places in the code, since the <
operator is also used in other parts of qsoverlay...
An easier fix is probably to just modify __lt__
so that it can receive a tuple with an extra parameter, in such a way that it does not conflict with the return_flag
functionality; and add the time parameter to the tuples in the gate_functions.
This will at least fix the time parameter usage when building circuits (though it will not fix the other usages of <
outside of qsoverlay/gate_functions.py
.
The ltoperator is also not prepared to receive such a time argument through the gate_desc list.
Made a pull request #20 in order to solve this.
I created a circuit using overlay. However, qsoverlay generates wrong quantumsim code. I tried simulating both the intented circuit (written in qsoverlay) and the resulting circuit (exported by qsoverlay) and the simulation results do not match. This is supposed to be a deterministic computation, which is not the case on the quantumsim circuit generated by qsoverlay (I set
noise_flag = False
during the function call.)Here's the qsoverlay circuit:
If I run this code, I get the result below:
As can be seen, the probability distribution is concentrated in 2 outputs (with 50% chance each), instead of just in one output, as calculated for the equivalent cQasm circuit in Quantum Inspire.