Skip to content

AttributeError: 'ArrayLiteral' object has no attribute 'value'. #240

@DanBlackwell

Description

@DanBlackwell

Describe the bug
In general the openQASM parsing errors are well handled in Braket. There are some cases where it is assumed that an object will have a .value and the exception is not caught. These are from auto-generated programs, so might not be an issue in practice; but perhaps the error message could be improved to include context if the exception was caught.

I'm not sure that this is really a bug, so please let me know if not and I will delete the issue. The example I include here is for ArrayLiterals, but there are a whole family of related errors I have triggered.

To reproduce

from braket.circuits import Circuit
from braket.devices import LocalSimulator

device = LocalSimulator()
Circuit.from_ir('''
OPENQASM 3.0;
include "stdgates.inc";
qubit["10"] r1;
''')

Expected behavior
Either return an error message indicating that bitstrings are not allowed for declaring register sizes, or parse the bitstring into a numeric constant (2) and create an array with that size.

Screenshots or logs

Traceback (most recent call last):
  File "/harnesses/./differential_harness.py", line 291, in <module>
    assert run_and_compare_exact_probabilities(qasm_content, 0.01)
  File "/harnesses/./differential_harness.py", line 177, in run_and_compare_exact_probabilities
    braket_circuit = braket_sim.build_circuit(qasm_content)
  File "/harnesses/./differential_harness.py", line 32, in build_circuit
    quantum_circuit = BraketCircuit.from_ir(qasm_content)
  File "/usr/local/lib/python3.10/dist-packages/braket/circuits/circuit.py", line 1167, in from_ir
    return Interpreter(BraketProgramContext()).build_circuit(
  File "/usr/local/lib/python3.10/dist-packages/braket/default_simulator/openqasm/interpreter.py", line 130, in build_circuit
    return self.run(source, inputs, is_file).circuit
  File "/usr/local/lib/python3.10/dist-packages/braket/default_simulator/openqasm/interpreter.py", line 145, in run
    self.visit(program)
  File "/usr/lib/python3.10/functools.py", line 926, in _method
    return method.__get__(obj, cls)(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/braket/default_simulator/openqasm/interpreter.py", line 172, in _
    self.visit(node.statements)
  File "/usr/lib/python3.10/functools.py", line 926, in _method
    return method.__get__(obj, cls)(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/braket/default_simulator/openqasm/interpreter.py", line 168, in _
    return [n for n in [self.visit(node) for node in node_list] if n is not None]
  File "/usr/local/lib/python3.10/dist-packages/braket/default_simulator/openqasm/interpreter.py", line 168, in <listcomp>
    return [n for n in [self.visit(node) for node in node_list] if n is not None]
  File "/usr/lib/python3.10/functools.py", line 926, in _method
    return method.__get__(obj, cls)(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/braket/default_simulator/openqasm/interpreter.py", line 250, in _
    size = self.visit(node.size).value if node.size else 1

System information
A description of your system. Please provide:

  • Amazon Braket Python SDK version: v1.74.0
  • Amazon Braket Python Schemas version:
  • Amazon Braket Python Default Simulator version:
  • Python version: Python 3.10.12

Additional context
N/A

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions