Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/braket/circuits/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from __future__ import annotations

import warnings
from collections import Counter
from collections.abc import Callable, Iterable, Sequence
from numbers import Number
Expand Down Expand Up @@ -1311,7 +1312,7 @@ def diagram(self, circuit_diagram_class: type = UnicodeCircuitDiagram) -> str:

def to_ir(
self,
ir_type: IRType = IRType.JAQCD,
ir_type: IRType = IRType.OPENQASM,
serialization_properties: SerializationProperties | None = None,
gate_definitions: dict[tuple[Gate, QubitSet], PulseSequence] | None = None,
) -> OpenQasmProgram | JaqcdProgram:
Expand All @@ -1337,6 +1338,10 @@ def to_ir(
"""
gate_definitions = gate_definitions or {}
if ir_type == IRType.JAQCD:
warnings.warn(
"The JAQCD action type is deprecated. Please use OpenQASM 3 programs instead.",
stacklevel=2,
)
return self._to_jaqcd()
if ir_type == IRType.OPENQASM:
if serialization_properties and not isinstance(
Expand Down
3 changes: 0 additions & 3 deletions src/braket/devices/local_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,6 @@ def _(self, circuit: Circuit, inputs: dict[str, float] | None, shots: int):
program = circuit.to_ir(ir_type=IRType.OPENQASM)
program.inputs.update(inputs or {})
return program
if DeviceActionType.JAQCD in simulator.properties.action:
validate_circuit_and_shots(circuit, shots)
return circuit.to_ir(ir_type=IRType.JAQCD)
raise NotImplementedError(f"{type(simulator)} does not support qubit gate-based programs")

@_construct_payload.register
Expand Down
26 changes: 20 additions & 6 deletions test/unit_tests/braket/circuits/test_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1184,9 +1184,9 @@ def h_nested(target):

def test_ir_empty_instructions_result_types():
circ = Circuit()
assert circ.to_ir() == jaqcd.Program(
instructions=[], results=[], basis_rotation_instructions=[]
)
with pytest.warns(UserWarning, match="JAQCD"):
ir = circ.to_ir(IRType.JAQCD)
assert ir == jaqcd.Program(instructions=[], results=[], basis_rotation_instructions=[])


def test_ir_non_empty_instructions_result_types():
Expand All @@ -1196,7 +1196,9 @@ def test_ir_non_empty_instructions_result_types():
results=[jaqcd.Probability(targets=[0, 1])],
basis_rotation_instructions=[],
)
assert circ.to_ir() == expected
with pytest.warns(UserWarning, match="JAQCD"):
ir = circ.to_ir(IRType.JAQCD)
assert ir == expected


def test_ir_non_empty_instructions_result_types_basis_rotation_instructions():
Expand All @@ -1206,7 +1208,16 @@ def test_ir_non_empty_instructions_result_types_basis_rotation_instructions():
results=[jaqcd.Sample(observable=["x"], targets=[0])],
basis_rotation_instructions=[jaqcd.H(target=0)],
)
assert circ.to_ir() == expected
with pytest.warns(UserWarning, match="JAQCD"):
ir = circ.to_ir(IRType.JAQCD)
assert ir == expected


def test_to_ir_default_is_openqasm():
"""Calling Circuit.to_ir() with no ir_type argument should return an
OpenQASM program (after the JAQCD-deprecation default flip)."""
circ = Circuit().h(0).cnot(0, 1)
assert isinstance(circ.to_ir(), OpenQasmProgram)


@pytest.mark.parametrize(
Expand Down Expand Up @@ -3815,5 +3826,8 @@ def test_barrier_openqasm_export_all_qubits():

def test_barrier_jaqcd_export_fails():
circ = Circuit().h(0).barrier([0, 1])
with pytest.raises(NotImplementedError, match="Barrier is not supported in JAQCD"):
with (
pytest.warns(UserWarning, match="JAQCD"),
pytest.raises(NotImplementedError, match="Barrier is not supported in JAQCD"),
):
circ.to_ir(IRType.JAQCD)
8 changes: 3 additions & 5 deletions test/unit_tests/braket/devices/test_local_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,13 +689,11 @@ def test_run_program_model_inputs():
assert task.result() == GateModelQuantumTaskResult.from_object(GATE_MODEL_RESULT)


def test_run_jaqcd_only():
def test_run_jaqcd_only_raises():
dummy = DummyJaqcdSimulator()
sim = LocalSimulator(dummy)
task = sim.run(Circuit().h(0).cnot(0, 1), 10)
dummy.assert_shots(10)
dummy.assert_qubits(None)
assert task.result() == GateModelQuantumTaskResult.from_object(GATE_MODEL_RESULT)
with pytest.raises(NotImplementedError, match="does not support qubit gate-based programs"):
sim.run(Circuit().h(0).cnot(0, 1), 10)


def test_run_program_model():
Expand Down
Loading