diff --git a/src/braket/circuits/circuit.py b/src/braket/circuits/circuit.py index 7e3bfcd4d..d3bf2d0e6 100644 --- a/src/braket/circuits/circuit.py +++ b/src/braket/circuits/circuit.py @@ -1212,7 +1212,7 @@ def _to_openqasm( ) for idx, qubit in enumerate(qubits): qubit_target = serialization_properties.format_target(int(qubit)) - ir_instructions.append(f"b[{idx}] = measure {qubit_target};") + ir_instructions.append(f"__bits__[{idx}] = measure {qubit_target};") return OpenQasmProgram.construct(source="\n".join(ir_instructions), inputs={}) @@ -1225,11 +1225,11 @@ def _create_openqasm_header( for parameter in self.parameters: ir_instructions.append(f"input float {parameter};") if not self.result_types: - ir_instructions.append(f"bit[{self.qubit_count}] b;") + ir_instructions.append(f"bit[{self.qubit_count}] __bits__;") if serialization_properties.qubit_reference_type == QubitReferenceType.VIRTUAL: total_qubits = max(self.qubits).real + 1 - ir_instructions.append(f"qubit[{total_qubits}] q;") + ir_instructions.append(f"qubit[{total_qubits}] __qubits__;") elif serialization_properties.qubit_reference_type != QubitReferenceType.PHYSICAL: raise ValueError( f"Invalid qubit_reference_type " diff --git a/src/braket/circuits/serialization.py b/src/braket/circuits/serialization.py index 1e0826e80..596a1f364 100644 --- a/src/braket/circuits/serialization.py +++ b/src/braket/circuits/serialization.py @@ -39,7 +39,7 @@ class OpenQASMSerializationProperties: Properties for serializing a circuit to OpenQASM. qubit_reference_type (QubitReferenceType): determines whether to use - logical qubits or physical qubits (q[i] vs $i). + logical qubits or physical qubits (__qubits__[i] vs $i). """ qubit_reference_type: QubitReferenceType = QubitReferenceType.VIRTUAL @@ -53,7 +53,7 @@ def format_target(self, target: int) -> str: str: The OpenQASM representation of the target qubit. """ qubit_reference_format = ( - "q[{}]" if self.qubit_reference_type == QubitReferenceType.VIRTUAL else "${}" + "__qubits__[{}]" if self.qubit_reference_type == QubitReferenceType.VIRTUAL else "${}" ) return qubit_reference_format.format(target) diff --git a/src/braket/parametric/free_parameter.py b/src/braket/parametric/free_parameter.py index 3eed47efe..27e588d79 100644 --- a/src/braket/parametric/free_parameter.py +++ b/src/braket/parametric/free_parameter.py @@ -44,12 +44,13 @@ def __init__(self, name: str): Args: name (str): Name of the :class:'FreeParameter'. Can be a unicode value. + Must not start with '__'. Examples: >>> param1 = FreeParameter("theta") >>> param1 = FreeParameter("\u03B8") """ - self._name = Symbol(name) + self._set_name(name) super().__init__(expression=self._name) @property @@ -99,6 +100,19 @@ def to_dict(self) -> dict: "name": self.name, } + def _set_name(self, name: str) -> None: + FreeParameter._validate_name(name) + self._name = Symbol(name) + + @staticmethod + def _validate_name(name: str) -> None: + if not name: + raise ValueError("FreeParameter names must be non empty") + if not isinstance(name, str): + raise TypeError("FreeParameter names must be strings") + if name.startswith("__"): + raise ValueError("FreeParameter names must not start with two underscores '__'") + @classmethod def from_dict(cls, parameter: dict) -> FreeParameter: return FreeParameter(parameter["name"]) diff --git a/src/braket/pulse/ast/qasm_transformer.py b/src/braket/pulse/ast/qasm_transformer.py index ae4cccad4..57a9018ea 100644 --- a/src/braket/pulse/ast/qasm_transformer.py +++ b/src/braket/pulse/ast/qasm_transformer.py @@ -43,8 +43,8 @@ def visit_ExpressionStatement(self, expression_statement: ast.ExpressionStatemen ): # For capture_v0 nodes, it replaces it with classical assignment statements # of the form: - # b[0] = capture_v0(...) - # b[1] = capture_v0(...) + # __bits__[0] = capture_v0(...) + # __bits__[1] = capture_v0(...) new_val = ast.ClassicalAssignment( # Ideally should use IndexedIdentifier here, but this works since it is just # for printing. diff --git a/test/integ_tests/test_adjoint_gradient.py b/test/integ_tests/test_adjoint_gradient.py index 99ab7dfe2..0f0b6982f 100644 --- a/test/integ_tests/test_adjoint_gradient.py +++ b/test/integ_tests/test_adjoint_gradient.py @@ -42,10 +42,10 @@ def test_adjoint_gradient_quantum_task_with_nested_targets( expected_openqasm = ( "OPENQASM 3.0;\n" "input float theta;\n" - "qubit[4] q;\n" - "rx(theta) q[0];\n" - "#pragma braket result adjoint_gradient expectation(-6 * y(q[0]) @ i(q[1]) + 0.75 * " - "y(q[2]) @ z(q[3])) theta" + "qubit[4] __qubits__;\n" + "rx(theta) __qubits__[0];\n" + "#pragma braket result adjoint_gradient expectation(-6 * " + "y(__qubits__[0]) @ i(__qubits__[1]) + 0.75 * y(__qubits__[2]) @ z(__qubits__[3])) theta" ) gradient_task = AwsQuantumTask.create( @@ -83,10 +83,10 @@ def test_adjoint_gradient_with_standard_observable_terms( expected_openqasm = ( "OPENQASM 3.0;\n" "input float theta;\n" - "qubit[3] q;\n" - "rx(theta) q[0];\n" - "#pragma braket result adjoint_gradient expectation(2 * x(q[0]) + 3 * y(q[1]) " - "- 1 * z(q[2])) theta" + "qubit[3] __qubits__;\n" + "rx(theta) __qubits__[0];\n" + "#pragma braket result adjoint_gradient expectation(2 * " + "x(__qubits__[0]) + 3 * y(__qubits__[1]) - 1 * z(__qubits__[2])) theta" ) gradient_task = AwsQuantumTask.create( @@ -132,17 +132,19 @@ def test_adjoint_gradient_with_batch_circuits(aws_session, s3_destination_folder ( "OPENQASM 3.0;\n" "input float theta;\n" - "qubit[2] q;\n" - "rx(theta) q[0];\n" - "#pragma braket result adjoint_gradient expectation(6 * y(q[0]) @ i(q[1])) theta" + "qubit[2] __qubits__;\n" + "rx(theta) __qubits__[0];\n" + "#pragma braket result adjoint_gradient expectation(6 *" + " y(__qubits__[0]) @ i(__qubits__[1])) theta" ), ( "OPENQASM 3.0;\n" "input float theta;\n" - "qubit[2] q;\n" - "rx(theta) q[0];\n" - "#pragma braket result adjoint_gradient expectation(-6 * y(q[0]) @ i(q[1]) + 0.75 * " - "y(q[0]) @ z(q[1])) theta" + "qubit[2] __qubits__;\n" + "rx(theta) __qubits__[0];\n" + "#pragma braket result adjoint_gradient expectation(-6 *" + " y(__qubits__[0]) @ i(__qubits__[1]) + 0.75 *" + " y(__qubits__[0]) @ z(__qubits__[1])) theta" ), ] diff --git a/test/unit_tests/braket/aws/test_aws_quantum_task.py b/test/unit_tests/braket/aws/test_aws_quantum_task.py index de8ead78a..0e16a7380 100644 --- a/test/unit_tests/braket/aws/test_aws_quantum_task.py +++ b/test/unit_tests/braket/aws/test_aws_quantum_task.py @@ -573,12 +573,12 @@ def test_create_pulse_gate_circuit( expected_openqasm = "\n".join( ( "OPENQASM 3.0;", - "bit[2] b;", + "bit[2] __bits__;", "cal {", " set_frequency(predefined_frame_1, 6000000.0);", "}", - "b[0] = measure $0;", - "b[1] = measure $1;", + "__bits__[0] = measure $0;", + "__bits__[1] = measure $1;", ) ) diff --git a/test/unit_tests/braket/circuits/test_circuit.py b/test/unit_tests/braket/circuits/test_circuit.py index fd2170a52..21f972b89 100644 --- a/test/unit_tests/braket/circuits/test_circuit.py +++ b/test/unit_tests/braket/circuits/test_circuit.py @@ -736,8 +736,8 @@ def test_ir_non_empty_instructions_result_types_basis_rotation_instructions(): source="\n".join( [ "OPENQASM 3.0;", - "bit[2] b;", - "qubit[2] q;", + "bit[2] __bits__;", + "qubit[2] __qubits__;", "cal {", " waveform drag_gauss_wf = drag_gaussian" + "(3000000.0ns, 400000000.0ns, 0.2, 1, false);", @@ -750,10 +750,10 @@ def test_ir_non_empty_instructions_result_types_basis_rotation_instructions(): " set_frequency(predefined_frame_1, 6000000.0);", " play(predefined_frame_1, drag_gauss_wf);", "}", - "rx(0.15) q[0];", - "rx(0.3) q[1];", - "b[0] = measure q[0];", - "b[1] = measure q[1];", + "rx(0.15) __qubits__[0];", + "rx(0.3) __qubits__[1];", + "__bits__[0] = measure __qubits__[0];", + "__bits__[1] = measure __qubits__[1];", ] ), inputs={}, @@ -766,7 +766,7 @@ def test_ir_non_empty_instructions_result_types_basis_rotation_instructions(): source="\n".join( [ "OPENQASM 3.0;", - "bit[2] b;", + "bit[2] __bits__;", "cal {", " waveform drag_gauss_wf = drag_gaussian" + "(3000000.0ns, 400000000.0ns, 0.2, 1, false);", @@ -781,8 +781,8 @@ def test_ir_non_empty_instructions_result_types_basis_rotation_instructions(): "}", "rx(0.15) $0;", "rx(0.3) $4;", - "b[0] = measure $0;", - "b[1] = measure $4;", + "__bits__[0] = measure $0;", + "__bits__[1] = measure $4;", ] ), inputs={}, @@ -832,7 +832,7 @@ def test_ir_non_empty_instructions_result_types_basis_rotation_instructions(): source="\n".join( [ "OPENQASM 3.0;", - "qubit[5] q;", + "qubit[5] __qubits__;", "cal {", " waveform drag_gauss_wf = drag_gaussian" + "(3000000.0ns, 400000000.0ns, 0.2, 1, false);", @@ -845,10 +845,10 @@ def test_ir_non_empty_instructions_result_types_basis_rotation_instructions(): " set_frequency(predefined_frame_1, 6000000.0);", " play(predefined_frame_1, drag_gauss_wf);", "}", - "rx(0.15) q[0];", - "rx(0.3) q[4];", - "#pragma braket noise bit_flip(0.2) q[3]", - "#pragma braket result expectation i(q[0])", + "rx(0.15) __qubits__[0];", + "rx(0.3) __qubits__[4];", + "#pragma braket noise bit_flip(0.2) __qubits__[3]", + "#pragma braket result expectation i(__qubits__[0])", ] ), inputs={}, @@ -862,8 +862,8 @@ def test_ir_non_empty_instructions_result_types_basis_rotation_instructions(): [ "OPENQASM 3.0;", "input float theta;", - "bit[2] b;", - "qubit[2] q;", + "bit[2] __bits__;", + "qubit[2] __qubits__;", "cal {", " waveform drag_gauss_wf = drag_gaussian" + "(3000000.0ns, 400000000.0ns, 0.2, 1, false);", @@ -876,10 +876,10 @@ def test_ir_non_empty_instructions_result_types_basis_rotation_instructions(): " set_frequency(predefined_frame_1, 6000000.0);", " play(predefined_frame_1, drag_gauss_wf);", "}", - "rx(0.15) q[0];", - "rx(theta) q[1];", - "b[0] = measure q[0];", - "b[1] = measure q[1];", + "rx(0.15) __qubits__[0];", + "rx(theta) __qubits__[1];", + "__bits__[0] = measure __qubits__[0];", + "__bits__[1] = measure __qubits__[1];", ] ), inputs={}, @@ -895,8 +895,8 @@ def test_ir_non_empty_instructions_result_types_basis_rotation_instructions(): source="\n".join( [ "OPENQASM 3.0;", - "bit[5] b;", - "qubit[5] q;", + "bit[5] __bits__;", + "qubit[5] __qubits__;", "cal {", " waveform drag_gauss_wf = drag_gaussian" + "(3000000.0ns, 400000000.0ns, 0.2, 1, false);", @@ -909,14 +909,14 @@ def test_ir_non_empty_instructions_result_types_basis_rotation_instructions(): " set_frequency(predefined_frame_1, 6000000.0);", " play(predefined_frame_1, drag_gauss_wf);", "}", - "negctrl @ rx(0.15) q[2], q[0];", - "ctrl(2) @ rx(0.3) q[2], q[3], q[1];", - "ctrl(2) @ cnot q[2], q[3], q[4], q[0];", - "b[0] = measure q[0];", - "b[1] = measure q[1];", - "b[2] = measure q[2];", - "b[3] = measure q[3];", - "b[4] = measure q[4];", + "negctrl @ rx(0.15) __qubits__[2], __qubits__[0];", + "ctrl(2) @ rx(0.3) __qubits__[2], __qubits__[3], __qubits__[1];", + "ctrl(2) @ cnot __qubits__[2], __qubits__[3], __qubits__[4], __qubits__[0];", # noqa + "__bits__[0] = measure __qubits__[0];", + "__bits__[1] = measure __qubits__[1];", + "__bits__[2] = measure __qubits__[2];", + "__bits__[3] = measure __qubits__[3];", + "__bits__[4] = measure __qubits__[4];", ] ), inputs={}, @@ -929,8 +929,8 @@ def test_ir_non_empty_instructions_result_types_basis_rotation_instructions(): source="\n".join( [ "OPENQASM 3.0;", - "bit[7] b;", - "qubit[7] q;", + "bit[7] __bits__;", + "qubit[7] __qubits__;", "cal {", " waveform drag_gauss_wf = drag_gaussian" + "(3000000.0ns, 400000000.0ns, 0.2, 1, false);", @@ -939,16 +939,16 @@ def test_ir_non_empty_instructions_result_types_basis_rotation_instructions(): " set_frequency(predefined_frame_1, 6000000.0);", " play(predefined_frame_1, drag_gauss_wf);", "}", - "cnot q[0], q[1];", - "cnot q[3], q[2];", - "ctrl @ cnot q[5], q[6], q[4];", - "b[0] = measure q[0];", - "b[1] = measure q[1];", - "b[2] = measure q[2];", - "b[3] = measure q[3];", - "b[4] = measure q[4];", - "b[5] = measure q[5];", - "b[6] = measure q[6];", + "cnot __qubits__[0], __qubits__[1];", + "cnot __qubits__[3], __qubits__[2];", + "ctrl @ cnot __qubits__[5], __qubits__[6], __qubits__[4];", + "__bits__[0] = measure __qubits__[0];", + "__bits__[1] = measure __qubits__[1];", + "__bits__[2] = measure __qubits__[2];", + "__bits__[3] = measure __qubits__[3];", + "__bits__[4] = measure __qubits__[4];", + "__bits__[5] = measure __qubits__[5];", + "__bits__[6] = measure __qubits__[6];", ] ), inputs={}, @@ -961,8 +961,8 @@ def test_ir_non_empty_instructions_result_types_basis_rotation_instructions(): source="\n".join( [ "OPENQASM 3.0;", - "bit[2] b;", - "qubit[2] q;", + "bit[2] __bits__;", + "qubit[2] __qubits__;", "cal {", " waveform drag_gauss_wf = drag_gaussian" + "(3000000.0ns, 400000000.0ns, 0.2, 1, false);", @@ -977,11 +977,11 @@ def test_ir_non_empty_instructions_result_types_basis_rotation_instructions(): " shift_phase(predefined_frame_1, -0.2);", " play(predefined_frame_1, drag_gauss_wf);", "}", - "inv @ pow(2.5) @ h q[0];", - "pow(0) @ h q[0];", - "ms(-0.1, -0.2, -0.3) q[0], q[1];", - "b[0] = measure q[0];", - "b[1] = measure q[1];", + "inv @ pow(2.5) @ h __qubits__[0];", + "pow(0) @ h __qubits__[0];", + "ms(-0.1, -0.2, -0.3) __qubits__[0], __qubits__[1];", + "__bits__[0] = measure __qubits__[0];", + "__bits__[1] = measure __qubits__[1];", ] ), inputs={}, @@ -1030,8 +1030,8 @@ def test_parametric_circuit_with_fixed_argument_defcal(pulse_sequence): [ "OPENQASM 3.0;", "input float theta;", - "bit[1] b;", - "qubit[1] q;", + "bit[1] __bits__;", + "qubit[1] __qubits__;", "cal {", " waveform drag_gauss_wf = drag_gaussian" + "(3000000.0ns, 400000000.0ns, 0.2, 1, false);", @@ -1044,10 +1044,10 @@ def test_parametric_circuit_with_fixed_argument_defcal(pulse_sequence): " set_frequency(predefined_frame_1, 6000000.0);", " play(predefined_frame_1, drag_gauss_wf);", "}", - "inv @ pow(2.5) @ h q[0];", - "pow(0) @ h q[0];", - "rx(theta) q[0];", - "b[0] = measure q[0];", + "inv @ pow(2.5) @ h __qubits__[0];", + "pow(0) @ h __qubits__[0];", + "rx(theta) __qubits__[0];", + "__bits__[0] = measure __qubits__[0];", ] ), inputs={}, @@ -1128,8 +1128,8 @@ def foo( source="\n".join( [ "OPENQASM 3.0;", - "bit[1] b;", - "qubit[1] q;", + "bit[1] __bits__;", + "qubit[1] __qubits__;", "cal {", " waveform drag_gauss_wf = drag_gaussian" + "(3000000.0ns, 400000000.0ns, 0.2, 1, false);", @@ -1140,8 +1140,8 @@ def foo( " shift_phase(predefined_frame_1, -0.2);", " play(predefined_frame_1, drag_gauss_wf);", "}", - "foo(-0.2) q[0];", - "b[0] = measure q[0];", + "foo(-0.2) __qubits__[0];", + "__bits__[0] = measure __qubits__[0];", ] ), inputs={}, @@ -1166,11 +1166,11 @@ def foo( source="\n".join( [ "OPENQASM 3.0;", - "bit[2] b;", - "qubit[2] q;", - "negctrl @ h q[1], q[0];", - "b[0] = measure q[0];", - "b[1] = measure q[1];", + "bit[2] __bits__;", + "qubit[2] __qubits__;", + "negctrl @ h __qubits__[1], __qubits__[0];", + "__bits__[0] = measure __qubits__[0];", + "__bits__[1] = measure __qubits__[1];", ] ), inputs={}, @@ -1182,11 +1182,11 @@ def foo( source="\n".join( [ "OPENQASM 3.0;", - "bit[2] b;", - "qubit[2] q;", - "cnot q[1], q[0];", - "b[0] = measure q[0];", - "b[1] = measure q[1];", + "bit[2] __bits__;", + "qubit[2] __qubits__;", + "cnot __qubits__[1], __qubits__[0];", + "__bits__[0] = measure __qubits__[0];", + "__bits__[1] = measure __qubits__[1];", ] ), inputs={}, @@ -1198,11 +1198,11 @@ def foo( source="\n".join( [ "OPENQASM 3.0;", - "bit[2] b;", - "qubit[2] q;", - "negctrl @ x q[1], q[0];", - "b[0] = measure q[0];", - "b[1] = measure q[1];", + "bit[2] __bits__;", + "qubit[2] __qubits__;", + "negctrl @ x __qubits__[1], __qubits__[0];", + "__bits__[0] = measure __qubits__[0];", + "__bits__[1] = measure __qubits__[1];", ] ), inputs={}, @@ -1214,11 +1214,11 @@ def foo( source="\n".join( [ "OPENQASM 3.0;", - "bit[2] b;", - "qubit[2] q;", - "ctrl @ rx(0.15) q[1], q[0];", - "b[0] = measure q[0];", - "b[1] = measure q[1];", + "bit[2] __bits__;", + "qubit[2] __qubits__;", + "ctrl @ rx(0.15) __qubits__[1], __qubits__[0];", + "__bits__[0] = measure __qubits__[0];", + "__bits__[1] = measure __qubits__[1];", ] ), inputs={}, @@ -1230,11 +1230,11 @@ def foo( source="\n".join( [ "OPENQASM 3.0;", - "bit[2] b;", - "qubit[2] q;", - "ctrl @ ry(0.2) q[1], q[0];", - "b[0] = measure q[0];", - "b[1] = measure q[1];", + "bit[2] __bits__;", + "qubit[2] __qubits__;", + "ctrl @ ry(0.2) __qubits__[1], __qubits__[0];", + "__bits__[0] = measure __qubits__[0];", + "__bits__[1] = measure __qubits__[1];", ] ), inputs={}, @@ -1246,11 +1246,11 @@ def foo( source="\n".join( [ "OPENQASM 3.0;", - "bit[2] b;", - "qubit[2] q;", - "negctrl @ rz(0.25) q[1], q[0];", - "b[0] = measure q[0];", - "b[1] = measure q[1];", + "bit[2] __bits__;", + "qubit[2] __qubits__;", + "negctrl @ rz(0.25) __qubits__[1], __qubits__[0];", + "__bits__[0] = measure __qubits__[0];", + "__bits__[1] = measure __qubits__[1];", ] ), inputs={}, @@ -1262,11 +1262,11 @@ def foo( source="\n".join( [ "OPENQASM 3.0;", - "bit[2] b;", - "qubit[2] q;", - "negctrl @ s q[1], q[0];", - "b[0] = measure q[0];", - "b[1] = measure q[1];", + "bit[2] __bits__;", + "qubit[2] __qubits__;", + "negctrl @ s __qubits__[1], __qubits__[0];", + "__bits__[0] = measure __qubits__[0];", + "__bits__[1] = measure __qubits__[1];", ] ), inputs={}, @@ -1278,11 +1278,11 @@ def foo( source="\n".join( [ "OPENQASM 3.0;", - "bit[2] b;", - "qubit[2] q;", - "negctrl @ t q[0], q[1];", - "b[0] = measure q[0];", - "b[1] = measure q[1];", + "bit[2] __bits__;", + "qubit[2] __qubits__;", + "negctrl @ t __qubits__[0], __qubits__[1];", + "__bits__[0] = measure __qubits__[0];", + "__bits__[1] = measure __qubits__[1];", ] ), inputs={}, @@ -1294,11 +1294,11 @@ def foo( source="\n".join( [ "OPENQASM 3.0;", - "bit[2] b;", - "qubit[2] q;", - "cphaseshift(0.15) q[1], q[0];", - "b[0] = measure q[0];", - "b[1] = measure q[1];", + "bit[2] __bits__;", + "qubit[2] __qubits__;", + "cphaseshift(0.15) __qubits__[1], __qubits__[0];", + "__bits__[0] = measure __qubits__[0];", + "__bits__[1] = measure __qubits__[1];", ] ), inputs={}, @@ -1310,12 +1310,12 @@ def foo( source="\n".join( [ "OPENQASM 3.0;", - "bit[3] b;", - "qubit[3] q;", - "ccnot q[0], q[1], q[2];", - "b[0] = measure q[0];", - "b[1] = measure q[1];", - "b[2] = measure q[2];", + "bit[3] __bits__;", + "qubit[3] __qubits__;", + "ccnot __qubits__[0], __qubits__[1], __qubits__[2];", + "__bits__[0] = measure __qubits__[0];", + "__bits__[1] = measure __qubits__[1];", + "__bits__[2] = measure __qubits__[2];", ] ), inputs={}, @@ -1327,8 +1327,8 @@ def foo( source="\n".join( [ "OPENQASM 3.0;", - "qubit[1] q;", - "h q[0];", + "qubit[1] __qubits__;", + "h __qubits__[0];", "#pragma braket result state_vector", ] ), @@ -1341,9 +1341,9 @@ def foo( source="\n".join( [ "OPENQASM 3.0;", - "qubit[1] q;", - "h q[0];", - "#pragma braket result expectation x(q[0])", + "qubit[1] __qubits__;", + "h __qubits__[0];", + "#pragma braket result expectation x(__qubits__[0])", ] ), inputs={}, @@ -1355,9 +1355,9 @@ def foo( source="\n".join( [ "OPENQASM 3.0;", - "qubit[2] q;", - "h q[0];", - "#pragma braket result expectation h(q[0]) @ x(q[1])", + "qubit[2] __qubits__;", + "h __qubits__[0];", + "#pragma braket result expectation h(__qubits__[0]) @ x(__qubits__[1])", ] ), inputs={}, @@ -1369,9 +1369,9 @@ def foo( source="\n".join( [ "OPENQASM 3.0;", - "qubit[2] q;", - "h q[0];", - "#pragma braket result variance h(q[0]) @ x(q[1])", + "qubit[2] __qubits__;", + "h __qubits__[0];", + "#pragma braket result variance h(__qubits__[0]) @ x(__qubits__[1])", ] ), inputs={}, @@ -1383,9 +1383,9 @@ def foo( source="\n".join( [ "OPENQASM 3.0;", - "qubit[1] q;", - "h q[0];", - "#pragma braket result probability q[0]", + "qubit[1] __qubits__;", + "h __qubits__[0];", + "#pragma braket result probability __qubits__[0]", ] ), inputs={}, @@ -1397,10 +1397,10 @@ def foo( source="\n".join( [ "OPENQASM 3.0;", - "bit[1] b;", - "qubit[1] q;", - "#pragma braket noise bit_flip(0.1) q[0]", - "b[0] = measure q[0];", + "bit[1] __bits__;", + "qubit[1] __qubits__;", + "#pragma braket noise bit_flip(0.1) __qubits__[0]", + "__bits__[0] = measure __qubits__[0];", ] ), inputs={}, @@ -1412,10 +1412,10 @@ def foo( source="\n".join( [ "OPENQASM 3.0;", - "bit[1] b;", - "qubit[1] q;", - "#pragma braket noise generalized_amplitude_damping(0.1, 0.1) q[0]", - "b[0] = measure q[0];", + "bit[1] __bits__;", + "qubit[1] __qubits__;", + "#pragma braket noise generalized_amplitude_damping(0.1, 0.1) __qubits__[0]", # noqa + "__bits__[0] = measure __qubits__[0];", ] ), inputs={}, @@ -1427,10 +1427,10 @@ def foo( source="\n".join( [ "OPENQASM 3.0;", - "bit[1] b;", - "qubit[1] q;", - "#pragma braket noise phase_flip(0.2) q[0]", - "b[0] = measure q[0];", + "bit[1] __bits__;", + "qubit[1] __qubits__;", + "#pragma braket noise phase_flip(0.2) __qubits__[0]", + "__bits__[0] = measure __qubits__[0];", ] ), inputs={}, @@ -1442,10 +1442,10 @@ def foo( source="\n".join( [ "OPENQASM 3.0;", - "bit[1] b;", - "qubit[1] q;", - "#pragma braket noise depolarizing(0.5) q[0]", - "b[0] = measure q[0];", + "bit[1] __bits__;", + "qubit[1] __qubits__;", + "#pragma braket noise depolarizing(0.5) __qubits__[0]", + "__bits__[0] = measure __qubits__[0];", ] ), inputs={}, @@ -1457,10 +1457,10 @@ def foo( source="\n".join( [ "OPENQASM 3.0;", - "bit[1] b;", - "qubit[1] q;", - "#pragma braket noise amplitude_damping(0.8) q[0]", - "b[0] = measure q[0];", + "bit[1] __bits__;", + "qubit[1] __qubits__;", + "#pragma braket noise amplitude_damping(0.8) __qubits__[0]", + "__bits__[0] = measure __qubits__[0];", ] ), inputs={}, @@ -1472,10 +1472,10 @@ def foo( source="\n".join( [ "OPENQASM 3.0;", - "bit[1] b;", - "qubit[1] q;", - "#pragma braket noise phase_damping(0.1) q[0]", - "b[0] = measure q[0];", + "bit[1] __bits__;", + "qubit[1] __qubits__;", + "#pragma braket noise phase_damping(0.1) __qubits__[0]", + "__bits__[0] = measure __qubits__[0];", ] ), inputs={}, @@ -1487,8 +1487,8 @@ def foo( source="\n".join( [ "OPENQASM 3.0;", - "qubit[1] q;", - "h q[0];", + "qubit[1] __qubits__;", + "h __qubits__[0];", '#pragma braket result amplitude "0", "1"', ] ), @@ -1504,16 +1504,16 @@ def foo( source="\n".join( [ "OPENQASM 3.0;", - "bit[5] b;", - "qubit[5] q;", - "negctrl @ rx(0.15) q[2], q[0];", - "ctrl(2) @ rx(0.3) q[2], q[3], q[1];", - "ctrl(2) @ cnot q[2], q[3], q[4], q[0];", - "b[0] = measure q[0];", - "b[1] = measure q[1];", - "b[2] = measure q[2];", - "b[3] = measure q[3];", - "b[4] = measure q[4];", + "bit[5] __bits__;", + "qubit[5] __qubits__;", + "negctrl @ rx(0.15) __qubits__[2], __qubits__[0];", + "ctrl(2) @ rx(0.3) __qubits__[2], __qubits__[3], __qubits__[1];", + "ctrl(2) @ cnot __qubits__[2], __qubits__[3], __qubits__[4], __qubits__[0];", # noqa + "__bits__[0] = measure __qubits__[0];", + "__bits__[1] = measure __qubits__[1];", + "__bits__[2] = measure __qubits__[2];", + "__bits__[3] = measure __qubits__[3];", + "__bits__[4] = measure __qubits__[4];", ] ), inputs={}, @@ -1525,18 +1525,18 @@ def foo( source="\n".join( [ "OPENQASM 3.0;", - "bit[7] b;", - "qubit[7] q;", - "cnot q[0], q[1];", - "cnot q[3], q[2];", - "ctrl @ cnot q[5], q[6], q[4];", - "b[0] = measure q[0];", - "b[1] = measure q[1];", - "b[2] = measure q[2];", - "b[3] = measure q[3];", - "b[4] = measure q[4];", - "b[5] = measure q[5];", - "b[6] = measure q[6];", + "bit[7] __bits__;", + "qubit[7] __qubits__;", + "cnot __qubits__[0], __qubits__[1];", + "cnot __qubits__[3], __qubits__[2];", + "ctrl @ cnot __qubits__[5], __qubits__[6], __qubits__[4];", + "__bits__[0] = measure __qubits__[0];", + "__bits__[1] = measure __qubits__[1];", + "__bits__[2] = measure __qubits__[2];", + "__bits__[3] = measure __qubits__[3];", + "__bits__[4] = measure __qubits__[4];", + "__bits__[5] = measure __qubits__[5];", + "__bits__[6] = measure __qubits__[6];", ] ), inputs={}, @@ -1548,11 +1548,11 @@ def foo( source="\n".join( [ "OPENQASM 3.0;", - "bit[1] b;", - "qubit[1] q;", - "inv @ pow(2.5) @ h q[0];", - "pow(0) @ h q[0];", - "b[0] = measure q[0];", + "bit[1] __bits__;", + "qubit[1] __qubits__;", + "inv @ pow(2.5) @ h __qubits__[0];", + "pow(0) @ h __qubits__[0];", + "__bits__[0] = measure __qubits__[0];", ] ), inputs={}, @@ -1564,10 +1564,10 @@ def foo( source="\n".join( [ "OPENQASM 3.0;", - "bit[1] b;", - "qubit[1] q;", - "#pragma braket unitary([[0, 1.0], [1.0, 0]]) q[0]", - "b[0] = measure q[0];", + "bit[1] __bits__;", + "qubit[1] __qubits__;", + "#pragma braket unitary([[0, 1.0], [1.0, 0]]) __qubits__[0]", + "__bits__[0] = measure __qubits__[0];", ] ), inputs={}, @@ -1579,10 +1579,10 @@ def foo( source="\n".join( [ "OPENQASM 3.0;", - "bit[1] b;", - "qubit[1] q;", - "#pragma braket noise pauli_channel(0.1, 0.2, 0.3) q[0]", - "b[0] = measure q[0];", + "bit[1] __bits__;", + "qubit[1] __qubits__;", + "#pragma braket noise pauli_channel(0.1, 0.2, 0.3) __qubits__[0]", + "__bits__[0] = measure __qubits__[0];", ] ), inputs={}, @@ -1594,11 +1594,11 @@ def foo( source="\n".join( [ "OPENQASM 3.0;", - "bit[2] b;", - "qubit[2] q;", - "#pragma braket noise two_qubit_depolarizing(0.1) q[0], q[1]", - "b[0] = measure q[0];", - "b[1] = measure q[1];", + "bit[2] __bits__;", + "qubit[2] __qubits__;", + "#pragma braket noise two_qubit_depolarizing(0.1) __qubits__[0], __qubits__[1]", # noqa + "__bits__[0] = measure __qubits__[0];", + "__bits__[1] = measure __qubits__[1];", ] ), inputs={}, @@ -1610,11 +1610,11 @@ def foo( source="\n".join( [ "OPENQASM 3.0;", - "bit[2] b;", - "qubit[2] q;", - "#pragma braket noise two_qubit_dephasing(0.1) q[0], q[1]", - "b[0] = measure q[0];", - "b[1] = measure q[1];", + "bit[2] __bits__;", + "qubit[2] __qubits__;", + "#pragma braket noise two_qubit_dephasing(0.1) __qubits__[0], __qubits__[1]", # noqa + "__bits__[0] = measure __qubits__[0];", + "__bits__[1] = measure __qubits__[1];", ] ), inputs={}, @@ -1626,11 +1626,11 @@ def foo( source="\n".join( [ "OPENQASM 3.0;", - "bit[2] b;", - "qubit[2] q;", - "#pragma braket noise two_qubit_dephasing(0.1) q[0], q[1]", - "b[0] = measure q[0];", - "b[1] = measure q[1];", + "bit[2] __bits__;", + "qubit[2] __qubits__;", + "#pragma braket noise two_qubit_dephasing(0.1) __qubits__[0], __qubits__[1]", # noqa + "__bits__[0] = measure __qubits__[0];", + "__bits__[1] = measure __qubits__[1];", ] ), inputs={}, @@ -1642,9 +1642,9 @@ def foo( source="\n".join( [ "OPENQASM 3.0;", - "qubit[1] q;", - "h q[0];", - "#pragma braket result sample z(q[0])", + "qubit[1] __qubits__;", + "h __qubits__[0];", + "#pragma braket result sample z(__qubits__[0])", ] ), inputs={}, @@ -1656,9 +1656,9 @@ def foo( source="\n".join( [ "OPENQASM 3.0;", - "qubit[1] q;", - "h q[0];", - "#pragma braket result sample z(q[0])", + "qubit[1] __qubits__;", + "h __qubits__[0];", + "#pragma braket result sample z(__qubits__[0])", ] ), inputs={}, @@ -1670,10 +1670,10 @@ def foo( source="\n".join( [ "OPENQASM 3.0;", - "qubit[2] q;", - "h q[0];", - "x q[1];", - "#pragma braket result density_matrix q[0], q[1]", + "qubit[2] __qubits__;", + "h __qubits__[0];", + "x __qubits__[1];", + "#pragma braket result density_matrix __qubits__[0], __qubits__[1]", ] ), inputs={}, @@ -1691,12 +1691,12 @@ def foo( source="\n".join( [ "OPENQASM 3.0;", - "bit[1] b;", - "qubit[1] q;", + "bit[1] __bits__;", + "qubit[1] __qubits__;", "#pragma braket noise " "kraus([[0.9486833im, 0], [0, 0.9486833im]], [[0, 0.31622777], " - "[0.31622777, 0]]) q[0]", - "b[0] = measure q[0];", + "[0.31622777, 0]]) __qubits__[0]", + "__bits__[0] = measure __qubits__[0];", ] ), inputs={}, @@ -1709,10 +1709,10 @@ def foo( [ "OPENQASM 3.0;", "input float theta;", - "bit[1] b;", - "qubit[1] q;", - "rx(theta) q[0];", - "b[0] = measure q[0];", + "bit[1] __bits__;", + "qubit[1] __qubits__;", + "rx(theta) __qubits__[0];", + "__bits__[0] = measure __qubits__[0];", ] ), inputs={}, @@ -1733,11 +1733,11 @@ def test_from_ir_inputs_updated(): "OPENQASM 3.0;", "input float theta;", "input float phi;", - "bit[1] b;", - "qubit[1] q;", - "rx(theta) q[0];", - "ry(phi) q[0];", - "b[0] = measure q[0];", + "bit[1] __bits__;", + "qubit[1] __qubits__;", + "rx(theta) __qubits__[0];", + "ry(phi) __qubits__[0];", + "__bits__[0] = measure __qubits__[0];", ] ), inputs={"theta": 0.2, "phi": 0.3}, @@ -1754,15 +1754,15 @@ def test_from_ir_inputs_updated(): source="\n".join( [ "OPENQASM 3.0;", - "bit[2] b;", - "qubit[2] q;", + "bit[2] __bits__;", + "qubit[2] __qubits__;", "gate my_gate a,b {", "h a;", - "cnot a,b;", + "cnot a, b;", "}", - "my_gate q[0], q[1];", - "b[0] = measure q[0];", - "b[1] = measure q[1];", + "my_gate __qubits__[0], __qubits__[1];", + "__bits__[0] = measure __qubits__[0];", + "__bits__[1] = measure __qubits__[1];", ] ), inputs={}, @@ -1774,15 +1774,15 @@ def test_from_ir_inputs_updated(): source="\n".join( [ "OPENQASM 3.0;", - "bit[2] b;", - "qubit[2] q;", + "bit[2] __bits__;", + "qubit[2] __qubits__;", "def my_sub(qubit q) {", "h q;", "}", - "h q[0];", - "my_sub(q[1]);", - "b[0] = measure q[0];", - "b[1] = measure q[1];", + "h __qubits__[0];", + "my_sub(__qubits__[1]);", + "__bits__[0] = measure __qubits__[0];", + "__bits__[1] = measure __qubits__[1];", ] ), inputs={}, @@ -1794,14 +1794,14 @@ def test_from_ir_inputs_updated(): source="\n".join( [ "OPENQASM 3.0;", - "bit[2] b;", - "qubit[2] q;", + "bit[2] __bits__;", + "qubit[2] __qubits__;", "for uint i in [0:1] {", - "h q[i];", + "h __qubits__[i];", "}", - "cnot q[0], q[1];", - "b[0] = measure q[0];", - "b[1] = measure q[1];", + "cnot __qubits__[0], __qubits__[1];", + "__bits__[0] = measure __qubits__[0];", + "__bits__[1] = measure __qubits__[1];", ] ), inputs={}, @@ -1813,14 +1813,14 @@ def test_from_ir_inputs_updated(): source="\n".join( [ "OPENQASM 3.0;", - "bit[2] b;", - "qubit[2] q;", + "bit[2] __bits__;", + "qubit[2] __qubits__;", "for uint i in [0:1] {", - "h q[i];", + "h __qubits__[i];", "}", - "cnot q[0], q[1];", - "b[0] = measure q[0];", - "b[1] = measure q[1];", + "cnot __qubits__[0], __qubits__[1];", + "__bits__[0] = measure __qubits__[0];", + "__bits__[1] = measure __qubits__[1];", ] ), inputs={}, @@ -1832,13 +1832,13 @@ def test_from_ir_inputs_updated(): source="\n".join( [ "OPENQASM 3.0;", - "bit[1] b;", - "qubit[1] q;", + "bit[1] __bits__;", + "qubit[1] __qubits__;", "bit c = 0;", "if (c ==0){", - "x q[0];", + "x __qubits__[0];", "}", - "b[0] = measure q[0];", + "__bits__[0] = measure __qubits__[0];", ] ), inputs={}, @@ -1850,11 +1850,11 @@ def test_from_ir_inputs_updated(): source="\n".join( [ "OPENQASM 3.0;", - "input float theta;" "bit[1] b;", - "qubit[1] q;", - "rx(theta) q[0];", - "rx(2*theta) q[0];", - "b[0] = measure q[0];", + "input float theta;" "bit[1] __bits__;", + "qubit[1] __qubits__;", + "rx(theta) __qubits__[0];", + "rx(2*theta) __qubits__[0];", + "__bits__[0] = measure __qubits__[0];", ] ), inputs={}, @@ -3357,7 +3357,7 @@ def test_pulse_circuit_to_openqasm(predefined_frame_1, user_defined_frame): ).source == "\n".join( [ "OPENQASM 3.0;", - "bit[2] b;", + "bit[2] __bits__;", "cal {", " frame user_defined_frame_0 = newframe(device_port_x0, 10000000.0, 3.14);", " waveform gauss_wf = gaussian(1000000.0ns, 700000000.0ns, 1, false);", @@ -3379,8 +3379,8 @@ def test_pulse_circuit_to_openqasm(predefined_frame_1, user_defined_frame): " play(predefined_frame_1, drag_gauss_wf_2);", "}", "h $1;", - "b[0] = measure $0;", - "b[1] = measure $1;", + "__bits__[0] = measure $0;", + "__bits__[1] = measure $1;", ] ) @@ -3474,7 +3474,7 @@ def test_parametrized_pulse_circuit(user_defined_frame): [ "OPENQASM 3.0;", "input float frequency;", - "bit[2] b;", + "bit[2] __bits__;", "cal {", " frame user_defined_frame_0 = newframe(device_port_x0, 10000000.0, 3.14);", " waveform gauss_wf = gaussian(10000.0ns, 700000000.0ns, 1, false);", @@ -3484,8 +3484,8 @@ def test_parametrized_pulse_circuit(user_defined_frame): " set_frequency(user_defined_frame_0, frequency);", " play(user_defined_frame_0, gauss_wf);", "}", - "b[0] = measure $0;", - "b[1] = measure $1;", + "__bits__[0] = measure $0;", + "__bits__[1] = measure $1;", ] ) @@ -3499,7 +3499,7 @@ def test_parametrized_pulse_circuit(user_defined_frame): ).source == "\n".join( [ "OPENQASM 3.0;", - "bit[2] b;", + "bit[2] __bits__;", "cal {", " frame user_defined_frame_0 = newframe(device_port_x0, 10000000.0, 3.14);", " waveform gauss_wf = gaussian(10000.0ns, 700000000.0ns, 1, false);", @@ -3509,8 +3509,8 @@ def test_parametrized_pulse_circuit(user_defined_frame): " set_frequency(user_defined_frame_0, 10000000.0);", " play(user_defined_frame_0, gauss_wf);", "}", - "b[0] = measure $0;", - "b[1] = measure $1;", + "__bits__[0] = measure $0;", + "__bits__[1] = measure $1;", ] ) diff --git a/test/unit_tests/braket/circuits/test_gates.py b/test/unit_tests/braket/circuits/test_gates.py index 05b98ade4..9d5dd5580 100644 --- a/test/unit_tests/braket/circuits/test_gates.py +++ b/test/unit_tests/braket/circuits/test_gates.py @@ -306,7 +306,7 @@ def test_ir_gate_level(testclass, subroutine_name, irclass, irsubclasses, kwargs Gate.Rx(angle=0.17), [4], OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), - "rx(0.17) q[4];", + "rx(0.17) __qubits__[4];", ), ( Gate.Rx(angle=0.17), @@ -318,7 +318,7 @@ def test_ir_gate_level(testclass, subroutine_name, irclass, irsubclasses, kwargs Gate.X(), [4], OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), - "x q[4];", + "x __qubits__[4];", ), ( Gate.X(), @@ -330,7 +330,7 @@ def test_ir_gate_level(testclass, subroutine_name, irclass, irsubclasses, kwargs Gate.Z(), [4], OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), - "z q[4];", + "z __qubits__[4];", ), ( Gate.Z(), @@ -342,7 +342,7 @@ def test_ir_gate_level(testclass, subroutine_name, irclass, irsubclasses, kwargs Gate.Y(), [4], OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), - "y q[4];", + "y __qubits__[4];", ), ( Gate.Y(), @@ -354,7 +354,7 @@ def test_ir_gate_level(testclass, subroutine_name, irclass, irsubclasses, kwargs Gate.H(), [4], OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), - "h q[4];", + "h __qubits__[4];", ), ( Gate.H(), @@ -366,7 +366,7 @@ def test_ir_gate_level(testclass, subroutine_name, irclass, irsubclasses, kwargs Gate.Ry(angle=0.17), [4], OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), - "ry(0.17) q[4];", + "ry(0.17) __qubits__[4];", ), ( Gate.Ry(angle=0.17), @@ -378,7 +378,7 @@ def test_ir_gate_level(testclass, subroutine_name, irclass, irsubclasses, kwargs Gate.ZZ(angle=0.17), [4, 5], OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), - "zz(0.17) q[4], q[5];", + "zz(0.17) __qubits__[4], __qubits__[5];", ), ( Gate.ZZ(angle=0.17), @@ -390,7 +390,7 @@ def test_ir_gate_level(testclass, subroutine_name, irclass, irsubclasses, kwargs Gate.I(), [4], OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), - "i q[4];", + "i __qubits__[4];", ), ( Gate.I(), @@ -402,7 +402,7 @@ def test_ir_gate_level(testclass, subroutine_name, irclass, irsubclasses, kwargs Gate.V(), [4], OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), - "v q[4];", + "v __qubits__[4];", ), ( Gate.V(), @@ -414,7 +414,7 @@ def test_ir_gate_level(testclass, subroutine_name, irclass, irsubclasses, kwargs Gate.CY(), [0, 1], OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), - "cy q[0], q[1];", + "cy __qubits__[0], __qubits__[1];", ), ( Gate.CY(), @@ -426,7 +426,7 @@ def test_ir_gate_level(testclass, subroutine_name, irclass, irsubclasses, kwargs Gate.Rz(angle=0.17), [4], OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), - "rz(0.17) q[4];", + "rz(0.17) __qubits__[4];", ), ( Gate.Rz(angle=0.17), @@ -438,7 +438,7 @@ def test_ir_gate_level(testclass, subroutine_name, irclass, irsubclasses, kwargs Gate.XX(angle=0.17), [4, 5], OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), - "xx(0.17) q[4], q[5];", + "xx(0.17) __qubits__[4], __qubits__[5];", ), ( Gate.XX(angle=0.17), @@ -450,7 +450,7 @@ def test_ir_gate_level(testclass, subroutine_name, irclass, irsubclasses, kwargs Gate.T(), [4], OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), - "t q[4];", + "t __qubits__[4];", ), ( Gate.T(), @@ -468,13 +468,13 @@ def test_ir_gate_level(testclass, subroutine_name, irclass, irsubclasses, kwargs Gate.CZ(), [0, 1], OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), - "cz q[0], q[1];", + "cz __qubits__[0], __qubits__[1];", ), ( Gate.YY(angle=0.17), [4, 5], OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), - "yy(0.17) q[4], q[5];", + "yy(0.17) __qubits__[4], __qubits__[5];", ), ( Gate.YY(angle=0.17), @@ -486,7 +486,7 @@ def test_ir_gate_level(testclass, subroutine_name, irclass, irsubclasses, kwargs Gate.XY(angle=0.17), [4, 5], OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), - "xy(0.17) q[4], q[5];", + "xy(0.17) __qubits__[4], __qubits__[5];", ), ( Gate.XY(angle=0.17), @@ -504,7 +504,7 @@ def test_ir_gate_level(testclass, subroutine_name, irclass, irsubclasses, kwargs Gate.ISwap(), [0, 1], OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), - "iswap q[0], q[1];", + "iswap __qubits__[0], __qubits__[1];", ), ( Gate.Swap(), @@ -516,7 +516,7 @@ def test_ir_gate_level(testclass, subroutine_name, irclass, irsubclasses, kwargs Gate.Swap(), [0, 1], OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), - "swap q[0], q[1];", + "swap __qubits__[0], __qubits__[1];", ), ( Gate.ECR(), @@ -528,7 +528,7 @@ def test_ir_gate_level(testclass, subroutine_name, irclass, irsubclasses, kwargs Gate.ECR(), [0, 1], OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), - "ecr q[0], q[1];", + "ecr __qubits__[0], __qubits__[1];", ), ( Gate.CV(), @@ -540,13 +540,13 @@ def test_ir_gate_level(testclass, subroutine_name, irclass, irsubclasses, kwargs Gate.CV(), [0, 1], OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), - "cv q[0], q[1];", + "cv __qubits__[0], __qubits__[1];", ), ( Gate.Vi(), [4], OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), - "vi q[4];", + "vi __qubits__[4];", ), ( Gate.Vi(), @@ -558,7 +558,7 @@ def test_ir_gate_level(testclass, subroutine_name, irclass, irsubclasses, kwargs Gate.CSwap(), [0, 1, 2], OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), - "cswap q[0], q[1], q[2];", + "cswap __qubits__[0], __qubits__[1], __qubits__[2];", ), ( Gate.CSwap(), @@ -570,7 +570,7 @@ def test_ir_gate_level(testclass, subroutine_name, irclass, irsubclasses, kwargs Gate.CPhaseShift01(angle=0.17), [4, 5], OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), - "cphaseshift01(0.17) q[4], q[5];", + "cphaseshift01(0.17) __qubits__[4], __qubits__[5];", ), ( Gate.CPhaseShift01(angle=0.17), @@ -582,7 +582,7 @@ def test_ir_gate_level(testclass, subroutine_name, irclass, irsubclasses, kwargs Gate.CPhaseShift00(angle=0.17), [4, 5], OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), - "cphaseshift00(0.17) q[4], q[5];", + "cphaseshift00(0.17) __qubits__[4], __qubits__[5];", ), ( Gate.CPhaseShift00(angle=0.17), @@ -594,7 +594,7 @@ def test_ir_gate_level(testclass, subroutine_name, irclass, irsubclasses, kwargs Gate.CPhaseShift(angle=0.17), [4, 5], OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), - "cphaseshift(0.17) q[4], q[5];", + "cphaseshift(0.17) __qubits__[4], __qubits__[5];", ), ( Gate.CPhaseShift(angle=0.17), @@ -606,7 +606,7 @@ def test_ir_gate_level(testclass, subroutine_name, irclass, irsubclasses, kwargs Gate.S(), [4], OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), - "s q[4];", + "s __qubits__[4];", ), ( Gate.S(), @@ -618,7 +618,7 @@ def test_ir_gate_level(testclass, subroutine_name, irclass, irsubclasses, kwargs Gate.Si(), [4], OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), - "si q[4];", + "si __qubits__[4];", ), ( Gate.Si(), @@ -630,7 +630,7 @@ def test_ir_gate_level(testclass, subroutine_name, irclass, irsubclasses, kwargs Gate.Ti(), [4], OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), - "ti q[4];", + "ti __qubits__[4];", ), ( Gate.Ti(), @@ -642,7 +642,7 @@ def test_ir_gate_level(testclass, subroutine_name, irclass, irsubclasses, kwargs Gate.PhaseShift(angle=0.17), [4], OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), - "phaseshift(0.17) q[4];", + "phaseshift(0.17) __qubits__[4];", ), ( Gate.PhaseShift(angle=0.17), @@ -654,7 +654,7 @@ def test_ir_gate_level(testclass, subroutine_name, irclass, irsubclasses, kwargs Gate.CNot(), [4, 5], OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), - "cnot q[4], q[5];", + "cnot __qubits__[4], __qubits__[5];", ), ( Gate.CNot(), @@ -666,7 +666,7 @@ def test_ir_gate_level(testclass, subroutine_name, irclass, irsubclasses, kwargs Gate.PSwap(angle=0.17), [4, 5], OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), - "pswap(0.17) q[4], q[5];", + "pswap(0.17) __qubits__[4], __qubits__[5];", ), ( Gate.PSwap(angle=0.17), @@ -678,7 +678,7 @@ def test_ir_gate_level(testclass, subroutine_name, irclass, irsubclasses, kwargs Gate.CPhaseShift10(angle=0.17), [4, 5], OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), - "cphaseshift10(0.17) q[4], q[5];", + "cphaseshift10(0.17) __qubits__[4], __qubits__[5];", ), ( Gate.CPhaseShift10(angle=0.17), @@ -690,7 +690,7 @@ def test_ir_gate_level(testclass, subroutine_name, irclass, irsubclasses, kwargs Gate.CCNot(), [4, 5, 6], OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), - "ccnot q[4], q[5], q[6];", + "ccnot __qubits__[4], __qubits__[5], __qubits__[6];", ), ( Gate.CCNot(), @@ -711,7 +711,7 @@ def test_ir_gate_level(testclass, subroutine_name, irclass, irsubclasses, kwargs "[0, 0, 0, 0, 0, 1.0, 0, 0], " "[0, 0, 0, 0, 0, 0, 0, 1.0], " "[0, 0, 0, 0, 0, 0, 1.0, 0]" - "]) q[4], q[5], q[6]", + "]) __qubits__[4], __qubits__[5], __qubits__[6]", ), ( Gate.Unitary(Gate.CCNot().to_matrix()), @@ -737,7 +737,7 @@ def test_ir_gate_level(testclass, subroutine_name, irclass, irsubclasses, kwargs "[0, 0, 0.70710678im, 0.70710678], " "[0.70710678, -0.70710678im, 0, 0], " "[-0.70710678im, 0.70710678, 0, 0]" - "]) q[4], q[5]", + "]) __qubits__[4], __qubits__[5]", ), ( Gate.Unitary(np.round(Gate.ECR().to_matrix(), 8)), @@ -754,7 +754,7 @@ def test_ir_gate_level(testclass, subroutine_name, irclass, irsubclasses, kwargs Gate.Unitary(np.round(Gate.T().to_matrix(), 8)), [4], OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), - "#pragma braket unitary([[1.0, 0], [0, 0.70710678 + 0.70710678im]]) q[4]", + "#pragma braket unitary([[1.0, 0], [0, 0.70710678 + 0.70710678im]]) __qubits__[4]", ), ( Gate.Unitary(np.round(Gate.T().to_matrix(), 8)), @@ -766,7 +766,7 @@ def test_ir_gate_level(testclass, subroutine_name, irclass, irsubclasses, kwargs Gate.Unitary(np.array([[1.0, 0], [0, 0.70710678 - 0.70710678j]])), [4], OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), - "#pragma braket unitary([[1.0, 0], [0, 0.70710678 - 0.70710678im]]) q[4]", + "#pragma braket unitary([[1.0, 0], [0, 0.70710678 - 0.70710678im]]) __qubits__[4]", ), ( Gate.PulseGate( @@ -784,7 +784,7 @@ def test_ir_gate_level(testclass, subroutine_name, irclass, irsubclasses, kwargs Gate.GPi(angle=0.17), [4], OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), - "gpi(0.17) q[4];", + "gpi(0.17) __qubits__[4];", ), ( Gate.GPi(angle=0.17), @@ -796,7 +796,7 @@ def test_ir_gate_level(testclass, subroutine_name, irclass, irsubclasses, kwargs Gate.GPi2(angle=0.17), [4], OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), - "gpi2(0.17) q[4];", + "gpi2(0.17) __qubits__[4];", ), ( Gate.GPi2(angle=0.17), @@ -808,7 +808,7 @@ def test_ir_gate_level(testclass, subroutine_name, irclass, irsubclasses, kwargs Gate.MS(angle_1=0.17, angle_2=3.45), [4, 5], OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), - f"ms(0.17, 3.45, {np.pi / 2}) q[4], q[5];", + f"ms(0.17, 3.45, {np.pi / 2}) __qubits__[4], __qubits__[5];", ), ( Gate.MS(angle_1=0.17, angle_2=3.45), @@ -1015,22 +1015,34 @@ def test_pulse_gate_to_matrix(): @pytest.mark.parametrize( "gate, target, control, control_state, expected_ir", ( - (Gate.H(), QubitSet(0), QubitSet(1), None, "ctrl @ h q[1], q[0];"), - (Gate.H(), QubitSet(0), QubitSet([1, 2]), None, "ctrl(2) @ h q[1], q[2], q[0];"), - (Gate.Ry(angle=1.23), QubitSet(0), QubitSet([2]), None, "ctrl @ ry(1.23) q[2], q[0];"), + (Gate.H(), QubitSet(0), QubitSet(1), None, "ctrl @ h __qubits__[1], __qubits__[0];"), + ( + Gate.H(), + QubitSet(0), + QubitSet([1, 2]), + None, + "ctrl(2) @ h __qubits__[1], __qubits__[2], __qubits__[0];", + ), + ( + Gate.Ry(angle=1.23), + QubitSet(0), + QubitSet([2]), + None, + "ctrl @ ry(1.23) __qubits__[2], __qubits__[0];", + ), ( Gate.MS(angle_1=0.17, angle_2=3.45), QubitSet(0), QubitSet([1, 2]), None, - f"ctrl(2) @ ms(0.17, 3.45, {np.pi / 2}) q[1], q[2], q[0];", + f"ctrl(2) @ ms(0.17, 3.45, {np.pi / 2}) __qubits__[1], __qubits__[2], __qubits__[0];", ), ( Gate.CCNot(), QubitSet([0, 1, 2]), QubitSet([3, 4]), None, - "ctrl(2) @ ccnot q[3], q[4], q[0], q[1], q[2];", + "ctrl(2) @ ccnot __qubits__[3], __qubits__[4], __qubits__[0], __qubits__[1], __qubits__[2];", # noqa ), ( Gate.Z(), @@ -1038,7 +1050,7 @@ def test_pulse_gate_to_matrix(): QubitSet([1, 2, 3, 4, 5, 6, 7]), [1, 1, 1, 0, 0, 1, 0], "ctrl(3) @ negctrl(2) @ ctrl @ negctrl @ " - "z q[1], q[2], q[3], q[4], q[5], q[6], q[7], q[0];", + "z __qubits__[1], __qubits__[2], __qubits__[3], __qubits__[4], __qubits__[5], __qubits__[6], __qubits__[7], __qubits__[0];", # noqa ), ( Gate.Z(), @@ -1046,7 +1058,7 @@ def test_pulse_gate_to_matrix(): QubitSet([1, 2, 3, 4, 5, 6, 7]), "1110010", "ctrl(3) @ negctrl(2) @ ctrl @ negctrl @ " - "z q[1], q[2], q[3], q[4], q[5], q[6], q[7], q[0];", + "z __qubits__[1], __qubits__[2], __qubits__[3], __qubits__[4], __qubits__[5], __qubits__[6], __qubits__[7], __qubits__[0];", # noqa ), ( Gate.Z(), @@ -1054,21 +1066,21 @@ def test_pulse_gate_to_matrix(): QubitSet([1, 2, 3, 4, 5, 6, 7]), 114, "ctrl(3) @ negctrl(2) @ ctrl @ negctrl @ " - "z q[1], q[2], q[3], q[4], q[5], q[6], q[7], q[0];", + "z __qubits__[1], __qubits__[2], __qubits__[3], __qubits__[4], __qubits__[5], __qubits__[6], __qubits__[7], __qubits__[0];", # noqa ), ( Gate.Z(), QubitSet([0]), QubitSet([1, 2, 3]), [1, 0], - "negctrl @ ctrl @ negctrl @ z q[1], q[2], q[3], q[0];", + "negctrl @ ctrl @ negctrl @ z __qubits__[1], __qubits__[2], __qubits__[3], __qubits__[0];", # noqa ), ( Gate.Z(), QubitSet([0]), QubitSet([1, 2, 3]), "10", - "negctrl @ ctrl @ negctrl @ z q[1], q[2], q[3], q[0];", + "negctrl @ ctrl @ negctrl @ z __qubits__[1], __qubits__[2], __qubits__[3], __qubits__[0];", # noqa ), ), ) @@ -1127,13 +1139,13 @@ def test_gate_control_invalid_state(control, control_state, error_string): @pytest.mark.parametrize( "gate, target, power, expected_ir", ( - (Gate.H(), QubitSet(0), 2, "pow(2) @ h q[0];"), - (Gate.H(), QubitSet(0), 2.0, "pow(2.0) @ h q[0];"), - (Gate.H(), QubitSet(0), 2.5, "pow(2.5) @ h q[0];"), - (Gate.H(), QubitSet(0), 0, "pow(0) @ h q[0];"), - (Gate.H(), QubitSet(0), -2, "inv @ pow(2) @ h q[0];"), - (Gate.H(), QubitSet(0), -2.0, "inv @ pow(2.0) @ h q[0];"), - (Gate.H(), QubitSet(0), -2.5, "inv @ pow(2.5) @ h q[0];"), + (Gate.H(), QubitSet(0), 2, "pow(2) @ h __qubits__[0];"), + (Gate.H(), QubitSet(0), 2.0, "pow(2.0) @ h __qubits__[0];"), + (Gate.H(), QubitSet(0), 2.5, "pow(2.5) @ h __qubits__[0];"), + (Gate.H(), QubitSet(0), 0, "pow(0) @ h __qubits__[0];"), + (Gate.H(), QubitSet(0), -2, "inv @ pow(2) @ h __qubits__[0];"), + (Gate.H(), QubitSet(0), -2.0, "inv @ pow(2.0) @ h __qubits__[0];"), + (Gate.H(), QubitSet(0), -2.5, "inv @ pow(2.5) @ h __qubits__[0];"), ), ) def test_gate_power(gate, target, power, expected_ir): diff --git a/test/unit_tests/braket/circuits/test_noises.py b/test/unit_tests/braket/circuits/test_noises.py index 2b55dfa4f..64710c8fd 100644 --- a/test/unit_tests/braket/circuits/test_noises.py +++ b/test/unit_tests/braket/circuits/test_noises.py @@ -547,7 +547,7 @@ def test_valid_values_pauli_channel_two_qubit(probs): Noise.BitFlip(0.5), OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), [3], - "#pragma braket noise bit_flip(0.5) q[3]", + "#pragma braket noise bit_flip(0.5) __qubits__[3]", ), ( Noise.BitFlip(0.5), @@ -559,7 +559,7 @@ def test_valid_values_pauli_channel_two_qubit(probs): Noise.PhaseFlip(0.5), OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), [3], - "#pragma braket noise phase_flip(0.5) q[3]", + "#pragma braket noise phase_flip(0.5) __qubits__[3]", ), ( Noise.PhaseFlip(0.5), @@ -571,7 +571,7 @@ def test_valid_values_pauli_channel_two_qubit(probs): Noise.PauliChannel(0.1, 0.2, 0.3), OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), [3], - "#pragma braket noise pauli_channel(0.1, 0.2, 0.3) q[3]", + "#pragma braket noise pauli_channel(0.1, 0.2, 0.3) __qubits__[3]", ), ( Noise.PauliChannel(0.1, 0.2, 0.3), @@ -583,7 +583,7 @@ def test_valid_values_pauli_channel_two_qubit(probs): Noise.Depolarizing(0.5), OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), [3], - "#pragma braket noise depolarizing(0.5) q[3]", + "#pragma braket noise depolarizing(0.5) __qubits__[3]", ), ( Noise.Depolarizing(0.5), @@ -595,7 +595,7 @@ def test_valid_values_pauli_channel_two_qubit(probs): Noise.TwoQubitDepolarizing(0.5), OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), [3, 5], - "#pragma braket noise two_qubit_depolarizing(0.5) q[3], q[5]", + "#pragma braket noise two_qubit_depolarizing(0.5) __qubits__[3], __qubits__[5]", ), ( Noise.TwoQubitDepolarizing(0.5), @@ -607,7 +607,7 @@ def test_valid_values_pauli_channel_two_qubit(probs): Noise.TwoQubitDephasing(0.5), OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), [3, 5], - "#pragma braket noise two_qubit_dephasing(0.5) q[3], q[5]", + "#pragma braket noise two_qubit_dephasing(0.5) __qubits__[3], __qubits__[5]", ), ( Noise.TwoQubitDephasing(0.5), @@ -619,7 +619,7 @@ def test_valid_values_pauli_channel_two_qubit(probs): Noise.AmplitudeDamping(0.5), OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), [3], - "#pragma braket noise amplitude_damping(0.5) q[3]", + "#pragma braket noise amplitude_damping(0.5) __qubits__[3]", ), ( Noise.AmplitudeDamping(0.5), @@ -631,7 +631,7 @@ def test_valid_values_pauli_channel_two_qubit(probs): Noise.GeneralizedAmplitudeDamping(0.5, 0.1), OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), [3], - "#pragma braket noise generalized_amplitude_damping(0.5, 0.1) q[3]", + "#pragma braket noise generalized_amplitude_damping(0.5, 0.1) __qubits__[3]", ), ( Noise.GeneralizedAmplitudeDamping(0.5, 0.1), @@ -643,7 +643,7 @@ def test_valid_values_pauli_channel_two_qubit(probs): Noise.PhaseDamping(0.5), OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), [3], - "#pragma braket noise phase_damping(0.5) q[3]", + "#pragma braket noise phase_damping(0.5) __qubits__[3]", ), ( Noise.PhaseDamping(0.5), @@ -668,7 +668,7 @@ def test_valid_values_pauli_channel_two_qubit(probs): "[0, 0.31622776601683794, 0, 0], " "[0.31622776601683794, 0, 0, 0], " "[0, 0, 0, 0.31622776601683794], " - "[0, 0, 0.31622776601683794, 0]]) q[3], q[5]", + "[0, 0, 0.31622776601683794, 0]]) __qubits__[3], __qubits__[5]", ), ( Noise.Kraus( @@ -700,7 +700,7 @@ def test_valid_values_pauli_channel_two_qubit(probs): [3], "#pragma braket noise kraus([" "[0.9486833im, 0], [0, 0.9486833im]], [" - "[0, 0.31622777], [0.31622777, 0]]) q[3]", + "[0, 0.31622777], [0.31622777, 0]]) __qubits__[3]", ), ( Noise.Kraus( diff --git a/test/unit_tests/braket/circuits/test_observables.py b/test/unit_tests/braket/circuits/test_observables.py index 79f917af9..415786375 100644 --- a/test/unit_tests/braket/circuits/test_observables.py +++ b/test/unit_tests/braket/circuits/test_observables.py @@ -67,7 +67,7 @@ def test_to_ir(testobject, gateobject, expected_ir, basis_rotation_gates, eigenv Observable.I(), OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), [3], - "i(q[3])", + "i(__qubits__[3])", ), ( Observable.I(), @@ -85,7 +85,7 @@ def test_to_ir(testobject, gateobject, expected_ir, basis_rotation_gates, eigenv Observable.X(), OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), [3], - "x(q[3])", + "x(__qubits__[3])", ), ( Observable.X(), @@ -103,7 +103,7 @@ def test_to_ir(testobject, gateobject, expected_ir, basis_rotation_gates, eigenv Observable.Y(), OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), [3], - "y(q[3])", + "y(__qubits__[3])", ), ( Observable.Y(), @@ -121,7 +121,7 @@ def test_to_ir(testobject, gateobject, expected_ir, basis_rotation_gates, eigenv Observable.Z(), OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), [3], - "z(q[3])", + "z(__qubits__[3])", ), ( Observable.Z(), @@ -139,7 +139,7 @@ def test_to_ir(testobject, gateobject, expected_ir, basis_rotation_gates, eigenv Observable.H(), OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), [3], - "h(q[3])", + "h(__qubits__[3])", ), ( Observable.H(), @@ -158,7 +158,7 @@ def test_to_ir(testobject, gateobject, expected_ir, basis_rotation_gates, eigenv OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), [1, 2], "hermitian([[1+0im, 0im, 0im, 0im], [0im, 1+0im, 0im, 0im], " - "[0im, 0im, 1+0im, 0im], [0im, 0im, 0im, 1+0im]]) q[1], q[2]", + "[0im, 0im, 1+0im, 0im], [0im, 0im, 0im, 1+0im]]) __qubits__[1], __qubits__[2]", ), ( Observable.Hermitian(np.eye(4)), @@ -177,7 +177,7 @@ def test_to_ir(testobject, gateobject, expected_ir, basis_rotation_gates, eigenv Observable.H() @ Observable.Z(), OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), [3, 0], - "h(q[3]) @ z(q[0])", + "h(__qubits__[3]) @ z(__qubits__[0])", ), ( Observable.H() @ Observable.Z(), @@ -189,7 +189,7 @@ def test_to_ir(testobject, gateobject, expected_ir, basis_rotation_gates, eigenv Observable.H() @ Observable.Z() @ Observable.I(), OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), [3, 0, 1], - "h(q[3]) @ z(q[0]) @ i(q[1])", + "h(__qubits__[3]) @ z(__qubits__[0]) @ i(__qubits__[1])", ), ( Observable.H() @ Observable.Z() @ Observable.I(), @@ -202,8 +202,8 @@ def test_to_ir(testobject, gateobject, expected_ir, basis_rotation_gates, eigenv OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), [3, 0, 1], "hermitian([[1+0im, 0im, 0im, 0im], [0im, 1+0im, 0im, 0im], " - "[0im, 0im, 1+0im, 0im], [0im, 0im, 0im, 1+0im]]) q[3], q[0]" - " @ i(q[1])", + "[0im, 0im, 1+0im, 0im], [0im, 0im, 0im, 1+0im]]) __qubits__[3], __qubits__[0]" + " @ i(__qubits__[1])", ), ( Observable.I() @ Observable.Hermitian(np.eye(4)), diff --git a/test/unit_tests/braket/circuits/test_result_types.py b/test/unit_tests/braket/circuits/test_result_types.py index 5f76eeaf9..8b3b9cd00 100644 --- a/test/unit_tests/braket/circuits/test_result_types.py +++ b/test/unit_tests/braket/circuits/test_result_types.py @@ -155,7 +155,7 @@ def test_ir_result_level(testclass, subroutine_name, irclass, input, ir_input): ( ResultType.Expectation(Observable.I(), target=0), OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), - "#pragma braket result expectation i(q[0])", + "#pragma braket result expectation i(__qubits__[0])", ), ( ResultType.Expectation(Observable.I()), @@ -175,7 +175,7 @@ def test_ir_result_level(testclass, subroutine_name, irclass, input, ir_input): ( ResultType.DensityMatrix([0, 2]), OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), - "#pragma braket result density_matrix q[0], q[2]", + "#pragma braket result density_matrix __qubits__[0], __qubits__[2]", ), ( ResultType.DensityMatrix(0), @@ -195,7 +195,7 @@ def test_ir_result_level(testclass, subroutine_name, irclass, input, ir_input): ( ResultType.Probability([0, 2]), OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), - "#pragma braket result probability q[0], q[2]", + "#pragma braket result probability __qubits__[0], __qubits__[2]", ), ( ResultType.Probability(0), @@ -205,7 +205,7 @@ def test_ir_result_level(testclass, subroutine_name, irclass, input, ir_input): ( ResultType.Sample(Observable.I(), target=0), OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), - "#pragma braket result sample i(q[0])", + "#pragma braket result sample i(__qubits__[0])", ), ( ResultType.Sample(Observable.I()), @@ -215,7 +215,7 @@ def test_ir_result_level(testclass, subroutine_name, irclass, input, ir_input): ( ResultType.Variance(Observable.I(), target=0), OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), - "#pragma braket result variance i(q[0])", + "#pragma braket result variance i(__qubits__[0])", ), ( ResultType.Variance(Observable.I()), @@ -225,12 +225,12 @@ def test_ir_result_level(testclass, subroutine_name, irclass, input, ir_input): ( ResultType.AdjointGradient(Observable.I(), target=0, parameters=["alpha", "beta"]), OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), - "#pragma braket result adjoint_gradient expectation(i(q[0])) alpha, beta", + "#pragma braket result adjoint_gradient expectation(i(__qubits__[0])) alpha, beta", ), ( ResultType.AdjointGradient(Observable.I(), target=0, parameters=["alpha"]), OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), - "#pragma braket result adjoint_gradient expectation(i(q[0])) alpha", + "#pragma braket result adjoint_gradient expectation(i(__qubits__[0])) alpha", ), ( ResultType.AdjointGradient( @@ -239,7 +239,7 @@ def test_ir_result_level(testclass, subroutine_name, irclass, input, ir_input): parameters=[FreeParameter("alpha"), "beta", FreeParameter("gamma")], ), OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), - "#pragma braket result adjoint_gradient expectation(h(q[0]) @ i(q[1])) " + "#pragma braket result adjoint_gradient expectation(h(__qubits__[0]) @ i(__qubits__[1])) " # noqa "alpha, beta, gamma", ), ( @@ -249,20 +249,20 @@ def test_ir_result_level(testclass, subroutine_name, irclass, input, ir_input): parameters=[FreeParameter("alpha"), "beta", FreeParameter("gamma")], ), OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), - "#pragma braket result adjoint_gradient expectation(h(q[0]) @ i(q[1]) + 2 * z(q[2])) " + "#pragma braket result adjoint_gradient expectation(h(__qubits__[0]) @ i(__qubits__[1]) + 2 * z(__qubits__[2])) " # noqa "alpha, beta, gamma", ), ( ResultType.AdjointGradient(Observable.I(), target=0, parameters=[]), OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), - "#pragma braket result adjoint_gradient expectation(i(q[0])) all", + "#pragma braket result adjoint_gradient expectation(i(__qubits__[0])) all", ), ( ResultType.AdjointGradient( Observable.X() @ Observable.Y(), target=[0, 1], parameters=[] ), OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), - "#pragma braket result adjoint_gradient expectation(x(q[0]) @ y(q[1])) all", + "#pragma braket result adjoint_gradient expectation(x(__qubits__[0]) @ y(__qubits__[1])) all", # noqa ), ( ResultType.AdjointGradient( @@ -270,7 +270,7 @@ def test_ir_result_level(testclass, subroutine_name, irclass, input, ir_input): ), OpenQASMSerializationProperties(qubit_reference_type=QubitReferenceType.VIRTUAL), "#pragma braket result adjoint_gradient expectation(hermitian([[1+0im, 0im], " - "[0im, 1+0im]]) q[0]) all", + "[0im, 1+0im]]) __qubits__[0]) all", ), ], ) diff --git a/test/unit_tests/braket/devices/test_local_simulator.py b/test/unit_tests/braket/devices/test_local_simulator.py index 08f2a19c5..736c510ab 100644 --- a/test/unit_tests/braket/devices/test_local_simulator.py +++ b/test/unit_tests/braket/devices/test_local_simulator.py @@ -404,10 +404,10 @@ def test_run_gate_model_inputs(): ( "OPENQASM 3.0;", "input float theta;", - "bit[1] b;", - "qubit[1] q;", - "rx(theta) q[0];", - "b[0] = measure q[0];", + "bit[1] __bits__;", + "qubit[1] __qubits__;", + "rx(theta) __qubits__[0];", + "__bits__[0] = measure __qubits__[0];", ) ), inputs={"theta": 2}, diff --git a/test/unit_tests/braket/parametric/test_free_parameter.py b/test/unit_tests/braket/parametric/test_free_parameter.py index 816bc0cee..b3b391a8e 100644 --- a/test/unit_tests/braket/parametric/test_free_parameter.py +++ b/test/unit_tests/braket/parametric/test_free_parameter.py @@ -61,3 +61,36 @@ def test_sub_successful(free_parameter): def test_sub_wrong_param(free_parameter): assert free_parameter.subs({"alpha": 1}) == FreeParameter("theta") + + +@pytest.mark.parametrize( + "name", + ( + "a", + "b", + "q", + "bit", + "qubit", + "_a", + "\u03B8", + "a\u03B8", + "a123", + "z123", + "\u03B8\u03B8", + "\u03B8a1", + ), +) +def test_valid_names(name): + FreeParameter(name) + + +@pytest.mark.parametrize( + "name", + ( + "", + "__a", + ), +) +def test_invalid_names(name): + with pytest.raises(ValueError): + FreeParameter(name)