1
$\begingroup$

I aim to conduct a Cirq simulation using a custom observable. However, the measure_observables function in Cirq requires an Iterable of cirq.PauliString, making it challenging to directly use a custom observable matrix. Since the observable matrix may vary, hard-coding it with gates becomes impractical. Here's an example of what I'm trying to achieve

import cirq
import numpy as np
from cirq.work.observable_measurement import measure_observables, RepetitionsStoppingCriteria

# Custom observable matrix
obs_matrix = np.array(
    [
        [0.63, 0.5, 1, 1],
        [0.5, 0.82, 1, 1],
        [1, 1, 1, 0.33],
        [1, 1, 0.33, 0.3],
    ],
    dtype=float,
)

# Create a Cirq circuit
circuit = cirq.Circuit()
qubits = cirq.LineQubit.range(2)
circuit.append(cirq.H(0))
circuit.append(cirq.rx(1.76)(1))
circuit.append(cirq.measure(qubits, key='result'))

# Run the simulation with custom observable
simulator = cirq.Simulator()
results = measure_observables(
    circuit,
    obs_matrix,
    simulator,
    stopping_criteria=RepetitionsStoppingCriteria(100)
)
print(results)

Can anyone advise me how to tackle the matrix hard-coding?

$\endgroup$
1
  • 1
    $\begingroup$ maybe you could just get the final_state_vector from the state vector simulator and compute $\langle \psi | A |\psi\rangle$ with numpy? $\endgroup$
    – forky40
    Mar 14 at 21:22

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.