1

In PyQuil, a qubit is initialised as $|0\rangle$ by default. Suppose, I want to initialise a qubit in an arbitrary state, say $\frac{1}{\sqrt{3}}|0\rangle+\sqrt{\frac{2}{3}}|1\rangle$. How to do this arbitrary qubit initialisation in PyQuil?

glS
  • 27,510
  • 7
  • 37
  • 125

1 Answers1

1

As far as I know, you can only do this with the ReferenceDensitySimulator, which contains a set_initial_state method. This is unfortunate because density matrix simulation is very costly.

In your case:

from pyquil import Program
from pyquil.simulation import ReferenceDensitySimulator
from pyquil.pyqvm import PyQVM
from pyquil.gates import I

state_ket = np.array([1/np.sqrt(3), np.sqrt(2/3)]) state_bra = np.array([[1/np.sqrt(3)], [np.sqrt(2/3)]])

rho1 = state_ket * state_bra

prog = Program(I(0)) qam = PyQVM(n_qubits=1, quantum_simulator_type=ReferenceDensitySimulator)

must call reset() to change the current state of the density matrix

density_matrix = qam.wf_simulator.set_initial_state(rho1).reset() qam.execute(prog) np.testing.assert_array_equal(qam.wf_simulator.density, rho1)

Victory Omole
  • 2,332
  • 1
  • 10
  • 24