ngnrsaa / qflex

Flexible Quantum Circuit Simulator (qFlex) implements an efficient tensor network, CPU-based simulator of large quantum circuits.
Apache License 2.0
97 stars 24 forks source link

Amplitudes for wrong final state are returned #294

Closed deaxlf closed 4 years ago

deaxlf commented 4 years ago

Hi I have run the following code in Jupyter Notebook: import numpy as np import qflexcirq import qflex options = { 'circuit_filename': 'sycamore_53_6_0.txt', 'ordering_filename': 'sycamore_53.txt', 'grid_filename': 'sycamore_53_grid.txt', 'final_state': "10001111001110000101000001011011001111010100000100000" } print(qflex.simulate(options))

plot

What I'm trying to get are the amplitudes corresponding to the final state 10001111001110000101000001011011001111010100000100000 but the amplitudes for 00000011001110000101000001011011001111010100000100000 were returned. I also tried ./src/qflex.x config/circuits/sycamore_53_6_0.txt config/ordering/sycamore_53.txt config/grid/sycamore_53.txt 00000000000000000000000000000000000000000000000000000 10001111001110000101000001011011001111010100000100000 in Terminal and the returned amplitudes were also corresponding to the state 00000011001110000101000001011011001111010100000100000.

95-martin-orion commented 4 years ago

Hi @deaxlf,

Since the two states in question only differ in the first six bits, I suspect what happened here is that qFlex overrode your initial bits with the terminal cut values in the ordering file: https://github.com/ngnrsaa/qflex/blob/21c7ff179df9bd2b90416749bb31b53b2a3210c3/config/ordering/sycamore_53.txt#L79-L85

To get the state you're looking for, you'll need to set these cut values to match the first six bits of your intended final state:

# BEGIN TERMINAL CUTS
cut (1) 5
cut (0) 6
cut (0) 14
cut (0) 15
cut (1) 16
cut (1) 17

Why this behaves this way: in many simulations, the last few qubits (the so-called "final region") can be iterated over to generate multiple amplitudes at once, with a negligible increase in cost. If you change the cut values to (0, 1), qFlex will generate amplitudes for all possible values of the first six bits

deaxlf commented 4 years ago

@95-martin-orion It works! Thank you!