quil-lang / qvm

The high-performance and featureful Quil simulator.
Other
411 stars 57 forks source link

Density matrix simulator not applying kraus operators #259

Closed max-radin closed 3 years ago

max-radin commented 4 years ago

The latest version of the qvm seems to be not applying Kraus operators during density matrix simulations.

With qvm 1.9.0, the script below gives [0.6222487943248762]. However with qvm 1.17.1 and 1.15.3 it gives [-1.0], which is what you'd expect in the absence of noise.

from pyquil.api import QVMConnection
from pyquil.api._base_connection import post_json

program = """
DEFGATE NOISY-CHANNEL:
    1.0, 0
    0, 1.0

PRAGMA ADD-KRAUS NOISY-CHANNEL 0 "(0.770997925690323 0.0 0.0 0.3350743172676877)"
PRAGMA ADD-KRAUS NOISY-CHANNEL 0 "(0.6368376548078946 0.0 0.0 -0.27676850388936003)"
PRAGMA ADD-KRAUS NOISY-CHANNEL 0 "(0.0 0.6943795815880344 0.0 0.0)"
PRAGMA ADD-KRAUS NOISY-CHANNEL 0 "(0.0 -0.5735515616194105 0.0 0.0)"
PRAGMA ADD-KRAUS NOISY-CHANNEL 1 "(0.770997925690323 0.0 0.0 0.3350743172676877)"
PRAGMA ADD-KRAUS NOISY-CHANNEL 1 "(0.6368376548078946 0.0 0.0 -0.27676850388936003)"
PRAGMA ADD-KRAUS NOISY-CHANNEL 1 "(0.0 0.6943795815880344 0.0 0.0)"
PRAGMA ADD-KRAUS NOISY-CHANNEL 1 "(0.0 -0.5735515616194105 0.0 0.0)"
X 0
NOISY-CHANNEL 0
"""
payload = {'type': "expectation",
           'state-preparation': program,
           'operators': ['Z 0']}

qvm = QVMConnection(endpoint='http://127.0.0.1:5000')
response = post_json(qvm.session, qvm.sync_endpoint+"/qvm", payload)
print(response.json())
stylewarning commented 3 years ago

@kilimanjaro maybe you can take a peek?