Commit 2000a264 authored by Kelvin Loh's avatar Kelvin Loh 🖖
Browse files

Merge branch 'feat/zhinst-skip-sequence-compilation' into 'develop'

feat(zhinst): Assert current with new sequence program to skip compilation

See merge request quantify-os/quantify-scheduler!131
parents 21819409 5512b9f0
Loading
Loading
Loading
Loading
Loading
+18 −6
Original line number Diff line number Diff line
@@ -90,7 +90,7 @@ def set_awg_value(
    value: Union[int, str],
) -> None:
    """
    Sets the vector value of a ZI node.
    Sets the value of a AWG module node.

    Parameters
    ----------
@@ -101,7 +101,7 @@ def set_awg_value(
    node :
        The node path.
    value :
        The new node vector value.
        The new node value.
    """
    logger.debug(node)

@@ -129,10 +129,22 @@ def set_and_compile_awg_seqc(
    value :
        The seqc program.
    """
    set_awg_value(instrument, awg_index, node, value)

    current_seqc = get_value(instrument, f"awgs/{awg_index}/sequencer/program")
    awgs = [instrument.awg] if not hasattr(instrument, "awgs") else instrument.awgs
    awg = awgs[awg_index]

    # Assert the current Sequencer program with the new
    if (
        len(current_seqc) == len(value)
        and hash(current_seqc) == hash(value)
        and current_seqc == value
    ):
        print(f'{awg.name}: Compilation status: SKIPPED. reason="identical sequencer"')
        return

    # Set the new 'compiler/sourcestring' value
    set_awg_value(instrument, awg_index, node, value)

    awg_module = awg._awg._module
    status: int = -1
    while status == -1:
@@ -148,7 +160,7 @@ def set_and_compile_awg_seqc(
        raise Warning(f"Compiled with warning: \n{status_str}")

    if status == 0:
        print("Compilation successful")
        print(f"{awg.name}: Compilation successful")

    tik = time.get_time()
    progress: float = awg_module.get_double("progress")
@@ -161,7 +173,7 @@ def set_and_compile_awg_seqc(
        status: int = awg_module.get_int("/elf/status")

    sequencer_status = "ELF file uploaded" if status == 0 else "FAILED!!"
    print(f"{awg.name}: Sequencer status: {sequencer_status}")
    print(f"{awg.name}: Compilation status: {sequencer_status}")


def set_wave_vector(
+29 −0
Original line number Diff line number Diff line
@@ -334,6 +334,7 @@ def test_set_and_compile_awg_seqc_successfully(mocker):

    mocker.patch.object(time, "sleep")
    set_awg_value = mocker.patch.object(zi_helpers, "set_awg_value")
    mocker.patch.object(zi_helpers, "get_value", return_value="")

    awg_index = 0
    node: str = "compiler/sourcestring"
@@ -346,6 +347,31 @@ def test_set_and_compile_awg_seqc_successfully(mocker):
    set_awg_value.assert_called_with(instrument, awg_index, node, value)


def test_set_and_compile_awg_seqc_skip_compilation(mocker):
    # Arrange
    awg_module = mocker.Mock()
    awg_module.get_int.side_effect = [0, 1, 1]
    awg_module.get_double.side_effect = [1.0]
    awg = mocker.Mock()
    awg._awg._module = awg_module
    instrument = mocker.create_autospec(ZIBaseInstrument, instance=True)
    instrument.awg = awg

    awg_index = 0
    node: str = "compiler/sourcestring"
    value: str = "abc"

    mocker.patch.object(time, "sleep")
    set_awg_value = mocker.patch.object(zi_helpers, "set_awg_value")
    mocker.patch.object(zi_helpers, "get_value", return_value=value)

    # Act
    zi_helpers.set_and_compile_awg_seqc(instrument, awg_index, node, value)

    # Assert
    set_awg_value.assert_not_called()


def test_set_and_compile_awg_seqc_upload_failed(mocker):
    # Arrange
    awg_module = mocker.Mock()
@@ -356,6 +382,7 @@ def test_set_and_compile_awg_seqc_upload_failed(mocker):
    instrument = mocker.create_autospec(ZIBaseInstrument, instance=True)
    instrument.awg = awg

    mocker.patch.object(zi_helpers, "get_value", return_value="")
    mocker.patch.object(time, "sleep")

    awg_index = 0
@@ -380,6 +407,7 @@ def test_set_and_compile_awg_seqc_compiled_with_warning(mocker):
    instrument = mocker.create_autospec(ZIBaseInstrument, instance=True)
    instrument.awg = awg

    mocker.patch.object(zi_helpers, "get_value", return_value="")
    mocker.patch.object(time, "sleep")

    awg_index = 0
@@ -404,6 +432,7 @@ def test_set_and_compile_awg_seqc_upload_timeout(mocker):
    instrument = mocker.create_autospec(ZIBaseInstrument, instance=True)
    instrument.awg = awg

    mocker.patch.object(zi_helpers, "get_value", return_value="")
    mocker.patch.object(time, "sleep")

    awg_index = 0