quantum icon indicating copy to clipboard operation
quantum copied to clipboard

'cirq.sim.simulator' has no attribute 'SimulatesExpectationValues'

Open sassan72 opened this issue 3 years ago • 2 comments

Build the quantum model layer

theta = sympy.Symbol('theta') q_model = cirq.Circuit(cirq.ry(theta)(qubit)) q_data_input = tf.keras.Input( shape=(), dtype=tf.dtypes.string) expectation = tfq.layers.PQC(q_model, cirq.Z(qubit)) expectation_output = expectation(q_data_input)

Attach the classical SoftMax classifier

classifier = tf.keras.layers.Dense(2, activation=tf.keras.activations.softmax) classifier_output = classifier(expectation_output) model = tf.keras.Model(inputs=q_data_input, outputs=classifier_output)

Standard compilation for classification

model.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=0.1), loss=tf.keras.losses.CategoricalCrossentropy()) tf.keras.utils.plot_model(model, show_shapes=True, dpi=70)

AttributeError Traceback (most recent call last) in 4 q_data_input = tf.keras.Input( 5 shape=(), dtype=tf.dtypes.string) ----> 6 expectation = tfq.layers.PQC(q_model, cirq.Z(qubit)) 7 expectation_output = expectation(q_data_input) 8

~/opt/anaconda3/lib/python3.8/site-packages/tensorflow_quantum/python/layers/high_level/pqc.py in init(self, model_circuit, operators, repetitions, backend, differentiator, initializer, regularizer, constraint, **kwargs) 232 233 not_default = backend is not 'noiseless' --> 234 not_default &= backend is not None # legacy backend=None support. 235 if not isinstance( 236 backend,

AttributeError: module 'cirq.sim.simulator' has no attribute 'SimulatesExpectationValues'

sassan72 avatar Jun 17 '21 15:06 sassan72

Hi @sassan72 thanks for opening this issue, could you please provide a working snippet of code I could run to reproduce the problem on my end ? Right now the code mixed in between the bolded text is kind of hard to follow.

MichaelBroughton avatar Jun 24 '21 01:06 MichaelBroughton

I got the same error when import qsimcirq after import cirq

WeileiZeng avatar Aug 20 '21 18:08 WeileiZeng