'WaveFunctionTrialResult' object has no attribute 'final_state_vector';'SingleQubitPauliStringGateOperation' object has no attribute 'expectation_from_state_vector';'PauliSum' object has no attribute 'expectation_from_state_vector'
The following error occurs, when I run the "Hello, many worlds" of tutorials locally. The rest code of "Hello, many worlds", however, works fine.
tensorflow version 2.1.0 tensorflow-quantum version 0.3.1 install through anaconda3
import importlib, pkg_resources importlib.reload(pkg_resources) import tensorflow as tf import tensorflow_quantum as tfq import cirq import sympy import numpy as np
%matplotlib inline import matplotlib.pyplot as plt from cirq.contrib.svg import SVGCircuit
a, b = sympy.symbols('a b') q0, q1 = cirq.GridQubit.rect(1, 2) circuit = cirq.Circuit( cirq.rx(a).on(q0), cirq.ry(b).on(q1), cirq.CNOT(control=q0, target=q1))
SVGCircuit(circuit)
resolver = cirq.ParamResolver({a: 0.5, b: -0.5})
output_state_vector = cirq.Simulator().simulate(circuit, resolver).final_state_vector
output_state_vector
AttributeError Traceback (most recent call last)
AttributeError: 'WaveFunctionTrialResult' object has no attribute 'final_state_vector'
z0 = cirq.Z(q0)
qubit_map={q0: 0, q1: 1}
z0.expectation_from_state_vector(output_state_vector, qubit_map).real
AttributeError Traceback (most recent call last)
AttributeError: 'SingleQubitPauliStringGateOperation' object has no attribute 'expectation_from_state_vector'
z0x1 = 0.5 * z0 + cirq.X(q1)
z0x1.expectation_from_state_vector(output_state_vector, qubit_map).real
AttributeError Traceback (most recent call last)
AttributeError: 'PauliSum' object has no attribute 'expectation_from_state_vector'
Likely because TFQ 0.3.1 uses cirq 0.8.0 and that function wasn't implemented yet (there was a expectation_from_wavefunction but no expectation_from_state_vector).
Oh, thanks, but could you tell me how to upgrade TFQ on Anaconda?
pip install -U tensorflow-quantum
Any updates on this or should it be closed?