Quantum computing SDK blueqat on amazon lambda serverless.
First
We did installing blueqat quantum computing SDK on ec2 and flask before.
Now we try lambda function to get serverless environment.
lamba?
Lambda is an event driven serverless service provides aws. You don’t have to manage the server resources.
What we do
What we do is to design the input and output of lambda function.
Let’s try first just looking at lambda.
import jsondef lambda_handler(event, context):
# TODO implement
return {
'statusCode': 200,
'body': json.dumps('Hello from Lambda!')
}
This is an example of “Hello from Lambda”. And we now want to input quantum circuit like “h”
{
"circuit": "h"
}Lambda file is changed to get the input of the circuit
import jsondef lambda_handler(event, context):
circ = event['circuit']
return {
'statusCode': 200,
'body': json.dumps(circ)
}
We have a response on
Response:
{
"statusCode": 200,
"body": "\"h\""
}...
We have correct output. And now we change a little bit to response for input quantum circuit.
import jsondef lambda_handler(event, context):
circ = event['circuit']
res = ""
if(circ == "h"):
res = "h"
if(circ =="x"):
res = "x"
return {
'statusCode': 200,
'body': json.dumps(res)
}
and we have correct output now.
Introduce a package for lambda
We need blueqat,numpy and scipy for lambda now. First we prepare the installation on blueqat on the current directory of your computer to have a package.
pip3 install blueqat --target .And let’s put lambda_function.py at the same directory
lambda_function.py
from blueqat import Circuit
import jsondef lambda_handler(event, context):
circ = event['circuit']
a = Circuit()
if(circ == "h"):
a.h[0]
if(circ =="x"):
a.x[0]
return {
'statusCode': 200,
'body': json.dumps(a.m[:].run(shots=100))
}
Lambda layer
Now we need numpy and scipy for blueqat, but these are too large to upload into lambda.
Now we have lambda layer which prepares files usually used in lambda like numpy and scipy.
We select lambda layer. Finally we just need blueqat folder (and we don’t need numpy and scipy anymore for uploading the file from lambda.)
After deleting numpy and scipy from the blueqat installed directory
zip -r lambda.zip *We get the file to upload to the lambda server.
Testing
Let’s do the test.
{
"statusCode": 200,
"body": "{\"0\": 40, \"1\": 60}"
}Now we have correct response from the lambda server. Using this scheme we can make a lot of services through API with serverless quantum computing SDK.

