BQSKit / qfast

Quantum Fast Approximate Synthesis Tool
Other
17 stars 2 forks source link

Cannot synthesis qft-3 #4

Closed sunxia0 closed 2 years ago

sunxia0 commented 2 years ago

Hi, qfast maintainers! I met a problem when I tried to synthesis a qft-3 circuit using qfast.

Test Code

from qsearch.unitaries import qft
from qfast.synthesis import synthesize

if __name__ == '__main__':
    qft = qft(2 ** 3)
    qc = synthesize(qft)
    print(qc)

The synthesis process can't be finished correctly and I got the stack trace below.

Traceback (most recent call last):
  File "/Users/xiao/Codes/Quantum/quantum-gate-synthesis/venv/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 3369, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-2-852956924d7d>", line 1, in <cell line: 1>
    runfile('/Users/xiao/Codes/Quantum/quantum-gate-synthesis/test_qfast.py', wdir='/Users/xiao/Codes/Quantum/quantum-gate-synthesis')
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_umd.py", line 198, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/Users/xiao/Codes/Quantum/quantum-gate-synthesis/test_qfast.py", line 7, in <module>
    qc = synthesize(qft)
  File "/Users/xiao/Codes/Quantum/quantum-gate-synthesis/baseline/qfast/synthesis.py", line 80, in synthesize
    qasm_list = instantiater.instantiate( gate_list )
  File "/Users/xiao/Codes/Quantum/quantum-gate-synthesis/baseline/qfast/instantiation/instantiater.py", line 73, in instantiate
    qasm = self.tool.synthesize( g.utry,
  File "/Users/xiao/Codes/Quantum/quantum-gate-synthesis/baseline/qfast/instantiation/native/qs.py", line 103, in synthesize
    output = compiler.compile( opts )
  File "/Users/xiao/Codes/Quantum/quantum-gate-synthesis/baseline/qsearch/leap_compiler.py", line 100, in compile
    best_pair, best_value, best_depth = sc.compile(opts)
  File "/Users/xiao/Codes/Quantum/quantum-gate-synthesis/baseline/qsearch/leap_compiler.py", line 222, in compile
    slope, intercept, _rval, _pval, _stderr = linregress(previous_bests_depths, previous_bests_values)
  File "/Users/xiao/Codes/Quantum/quantum-gate-synthesis/venv/lib/python3.8/site-packages/scipy/stats/_stats_mstats_common.py", line 150, in linregress
    raise ValueError("Cannot calculate a linear regression "
ValueError: Cannot calculate a linear regression if all x values are identical

However, the same code works fine for qft-4, as the example shows. I tried some other input like toffoli and met the same problem. I wonder if there are any limitations for the input unitary of qfast?

edyounis commented 2 years ago

Hello, apologies for the late response. This error is an issue in qsearch that has recently been fixed. However, we are currently in the process of deprecating our standalone qfast, qsearch, qgo, and qfactor repos, since they have all moved to the bqskit repo. You should be able to use this example to run qfast from there. If you need anymore help, please make an issue there. I will close this here.