TransWikia.com

How to create a qubit in an arbitrary state in PyQuil

Quantum Computing Asked by SHASHANK RANU on February 6, 2021

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

One Answer

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)

Answered by Victory Omole on February 6, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP