Package: aleph-lang
alephThis package provides the Python bindings foraleph.alephdefines a high level programming model that can be embedded into classical languages to develop large scale quantum hybrid applications, without the quantum mechanics.Getting startedTo get started, install the aleph-lang package from PyPI:pipinstallaleph-langProgramming ModelExpressions in Python take a single value, for example in the following program variable $x$ takes value 1:x=1print(x)# prints: 1alephextends this model by allowing registers to take multiple values simultaneously. This is not achieved by defining a list structure that points to multiple values in memory, instead, all the values are in a single quantum register insuperposition. We call this new type of register a Ket.To construct a Ket in Python, create an instance of theKetIntor theKetBoolclass from thealeph_langmodule.KetIntaccepts an optionalwidthargument to control the width (number of qubits) of the register, it defaults to 3. To read a value from a Ket use thesamplemethod.fromaleph_langimportKetInt,samplerandom_number=KetInt(width=10)print(sample(random_number))#  it prints a number between 0 and 1023 (2^10 - 1).You can perform arithmetic and boolean expressions on Kets. Expression are applied simultaneously to all Ket elements on a single step usingquantum parallelism. The result is a new Ket containing all possible outcomes of the evaluation.Input and output Kets of an expression areentangled, that is, when sampled the Ket's values are always correlated with each other. This entanglement is preserved across expressions. For example:x=KetInt()y=x+5z=2*yprint(sample([x,y,z]))# prints [0, 5, 10] or [1, 6, 12] or [2, 7, 14] or ... [7, 12, 24)]# e.g. the value of the second element is the first plus five,# the third element is the second times two.You can filter the elements of a Ket usingwhereexpressions. For example, usewhere_into filter the elements of a Ket to a specific list of items:dice1=KetInt().where_in(range(1,7))dice2=KetInt().where_in(range(1,7))roll=dice1+dice2print(sample([dice1,dice2,roll]))#prints [0,0,0] or [0,1,1] or [0,2,2] or ... [6,6,12]You can also filter the set of elementssamplewill return passing an optionalwhenparameter; when provided,samplewill return only elements that satisfy the given expression:# Solve x + a == b * xdefsolve_equation(a,b):x=KetInt()eq1=x+aeq2=b*xreturnsample(x,when=(eq1==eq2))answer=solve_equation(3,2)print(answer)# prints 3Under the covers,whenandwhereexpressions useamplitude amplification (a.k.a. Grover)to amplify the probability of measuring the correct elements and filter out the rest.samplereturns a single value;alephalso provideshistogramto get the histogram resulting from the outcomes of sampling Kets multiple times; it takes aroundsparameter that indicates how many samples to take:defdice_roll_histogram():dice1=KetInt().where_in(range(1,7))dice2=KetInt().where_in(range(1,7))roll=dice1+dice2returnhistogram([roll],rounds=1000)It is safe to combine Kets with classical expressions, making it possible to create hybrid programs that leverage the host's language features. For example, the following function takes a graph information and the max number of colors to solve a graph coloring problem:# Solve a graph coloring problem, for the given number of nodes and list of edges.defgraph_coloring(max_colors,nodes_count,edges):defcreate_node():w=width_for(max_colors)returnKetInt(width=w).where_less_than_equals(max_colors-1)defcompare(edges):iflen(edges)==1:(left,right)=edges[0]returnleft!=rightelse:head,*tail=edges(left,right)=heada=left!=rightb=compare(tail)returna&bnodes=[create_node()for_inrange(nodes_count)]edges=[(nodes[x],nodes[y])for(x,y)inedges]filter=compare(edges)## Print to the console a graphviz representation## of the quantum graph:## tree(filter)returnsample(nodes,when=filter)max_colors=3total_nodes=4edges=[(0,1),(1,2),(0,2),(1,3)]print("graph coloring:",graph_coloring(max_colors,total_nodes,edges))API serverTo simplify its setupalephitself runs on the cloud. It uses an external service that at runtime keeps track of a program's quantum graph and enables its evaluation. No personal information is collected or accessible by the service. To change this behavior, you can run a local instance of the API server and set theALEPH_BASE_URLenvironment variable to point to your local instance, for example:exportALEPH_BASE_URL=http://localhost:7071/Source code foraleph's API server and instructions on how to build and run locally can be found at:https://github.com/anpaz/aleph/tree/main/src/api.