The Quantum Hello World Programme in Quil which is Not 'Hello World'

Quantum computing is not like traditional programming, it is kinda probability measurement programming. Since it's not traditional programming, the 'Hello World' programme is not to print out the sentence 'Hello, World!', the simplest one is possibly call 'Flip Coin' programme.

Install Forest SDK to run qvm (Quil Virtual Machine) and quilc (Quil Compiler), and also install PyQuil using pip.

Source code:

#!/usr/bin/python3
#Core
import pprint;

#Libs
from pyquil       import get\_qc,Program;
from pyquil.gates import \*;
from pyquil.api   import WavefunctionSimulator;

#Global vars
pp = pprint.PrettyPrinter(indent=2);

#PROGRAMME ENTRY POINT
Qvm  = get\_qc("1q-qvm");
Prog = Program(
  H (0)
);

#Run
Shots  = 20;
Result = Qvm.run\_and\_measure(Prog,trials=Shots);
print(Prog);
pp.pprint(Result);
print("Probability:",sum(Result\[0\])/Shots);

#Test
print("");
Wfs = WavefunctionSimulator();
print(Wfs.wavefunction(Prog));

Run the VM and compiler in terminal 1:
qvm -S & quilc -S

Run the programme in terminal 2:
python3 flipcoin.py


You'll only receive email when they publish something new.

More from 19411
All posts