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


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 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
asked a year ago457 views
1 Answer
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 org.json.JSONObject;

class BraketTest{  
    public static void main(String args[]){  
        AmazonBraket braketClient = AmazonBraketClientBuilder.standard().build();
        CreateQuantumTaskRequest request = new CreateQuantumTaskRequest()
                .withOutputS3Bucket("<your s3 bucket name>")
        CreateQuantumTaskResult result = braketClient.createQuantumTask(request);

    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", "");
        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 a year 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