How to make a Bell State using the aws java sdk for Bracket.

1

I'm trying to use the CreateQuantumTaskRequest class to make bell states (a hello world of sorts). But I don't know where in the documentation its listed, for how to create a String that represents a gate. Going through the javadoc it doesn't say how to define a qubit either. [CreateQuantumTaskRequest com.amazonaws.services.braket.model.CreateQuantumTaskRequest.withAction(String action)].

If anyone has any information on how to make a bell state using the java aws sdk for Bracket then that would be greatly appreciated.

profile picture
QWS
asked 10 months ago435 views
1 Answer
5
Accepted Answer

A java snippet for bell circuit on Amazon Braket simulator is below. Please make sure to setup AWS creds with Braket Full Access.

import com.amazonaws.services.braket.AmazonBraket;
import com.amazonaws.services.braket.AmazonBraketClientBuilder;
import com.amazonaws.services.braket.model.CreateQuantumTaskRequest;
import com.amazonaws.services.braket.model.CreateQuantumTaskResult;

import org.json.JSONObject;


class BraketTest{  
    public static void main(String args[]){  
        AmazonBraket braketClient = AmazonBraketClientBuilder.standard().build();
        CreateQuantumTaskRequest request = new CreateQuantumTaskRequest()
                .withDeviceArn("arn:aws:braket:::device/quantum-simulator/amazon/sv1")
                .withDeviceParameters(BraketTest.getDeviceParameters())
                .withOutputS3Bucket("<your s3 bucket name>")
                .withOutputS3KeyPrefix("bellCircuit")
                .withShots(1000L)
                .withAction(getOpenQasmAction());
        CreateQuantumTaskResult result = braketClient.createQuantumTask(request);
        System.out.println(result.getQuantumTaskArn());
    }

    public static String getOpenQasmAction() {
        String program = "OPENQASM 3; qubit[2] q; bit[2] ro; h q[0]; cnot q[0], q[1]; ro[0] = measure q[0]; ro[1] = measure q[1];";
        JSONObject action = new JSONObject();

        JSONObject header = new JSONObject();
        header.put("name", "braket.ir.openqasm.program");
        header.put("version", "1");

        action.put("braketSchemaHeader", header);
        action.put("source", program);
        return action.toString();
    }

    public static String getDeviceParameters() {
       JSONObject deviceParameters = new JSONObject();

       JSONObject header = new JSONObject();
       header.put("name", "braket.device_schema.simulators.gate_model_simulator_device_parameters");
       header.put("version", "1");

       JSONObject deviceSchema = new JSONObject();
       deviceSchema.put("name", "braket.device_schema.gate_model_parameters");
       deviceSchema.put("version", "1");

       JSONObject paradigmParameters = new JSONObject();
       paradigmParameters.put("qubitCount", 2);
       paradigmParameters.put("braketSchemaHeader", deviceSchema);

       deviceParameters.put("paradigmParameters", paradigmParameters);
       deviceParameters.put("braketSchemaHeader", header);
       return deviceParameters.toString();
    }
}  
answered 10 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions