grove icon indicating copy to clipboard operation
grove copied to clipboard

fixed indentation in VQE expectation

Open rsln-s opened this issue 6 years ago • 2 comments

Fixed incorrect indentation introduced in eb476e22237dd45c23d731d9f3c59457ac2cfcaa

rsln-s avatar May 21 '18 20:05 rsln-s

@rsln-s Why does the indentation need fixing? This commit is not building due to

CMake Error at CMakeLists.txt:2 (cmake_minimum_required):
      CMake 3.2 or higher is required.  You are running version 2.8.12.2
    
    
    -- Configuring incomplete, errors occurred!
    Error: could find generator in Cache
    error: [Errno 2] No such file or directory: 'osqp_sources/build/out/libosqpstatic.a'

vtomole avatar May 22 '18 03:05 vtomole

@vtomole Two reasons:

  1. Performance. With current indentation the line
meas_outcome = expectation_from_sampling(pyquil_prog + meas_basis_change,
                                                      qubits_to_measure,
                                                      qvm,
                                                      samples)

is called more times than needed, with some results being thrown out, which means more calls to qvm. For example, for term (0.5+0j)*Z0*Z1, expectation_from_sampling(..) is called twice (first for qubits_to_measure = [0], second for qubits_to_measure = [0,1]), and first meas_outcome is thrown out. Calls to QVM being one of the most costly parts of QAOA and VQE, this is wasteful.

  1. Understandability. Incorrect indentation obfuscates the logic of computing expectation by term and makes the code hard to understand and extend.

Regarding building problem: not sure what's wrong with that. Running tests with tox doesn't work on my machine either, even for master:

...
Command "/home/ruslan/dev/grove-fork/.tox/py36/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-r872urds/osqp/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-q0i38ry7/install-record.txt --single-version-externally-managed --compile --install-headers /home/ruslan/dev/grove-fork/.tox/py36/include/site/python3.6/osqp" failed with error code 1 in /tmp/pip-install-r872urds/osqp/
ERROR: InvocationError for command '/home/ruslan/dev/grove-fork/.tox/py36/bin/pip install cvxpy' (exited with code 1)
___________________________________________________________________________________________________________________________________ summary ____________________________________________________________________________________________________________________________________
ERROR:   py27: InvocationError for command /home/ruslan/dev/grove-fork/.tox/py27/bin/pip install /home/ruslan/dev/grove-fork/.tox/dist/quantum-grove-1.6.0.zip (see /home/ruslan/dev/grove-fork/.tox/py27/log/py27-2.log) (exited with code 1)
ERROR:   py36: commands failed

rsln-s avatar May 22 '18 15:05 rsln-s