Skip to content
Snippets Groups Projects

Allow generic subschedule in conditional playback

Merged Robert Sokolewicz requested to merge cond_playback2 into main

Explanation of changes

Example 1

body = Schedule()
body.add(Square_Pulse(duration=50e-9, port=A, clock=B, ...))
body.add(SSBIntegrationComplex(duration=100e-9, port=A, clock=B))

Will compile to q1asm of the form:

set_awg_gain 10000
play 1,0,4
wait 46
acquire 0,0,100

This has a total duration of 150 ns and has 3 real-time instructions.

passing the body to a conditional:

schedule.add(ConditionalOperation(body, "q0"))

will compile it to the following q1asm:

set_cond 1,1,0,4 # set_enable=1, mask=0, operator=OR, else_duration=4
set_awg_gain 10000 
play 1,0,4       # real-time instruction
wait 46          # real-time instruction
acquire 0,0,100  # real-time instruction

set_cond 1,1,1,4 # set_enable=1, mask=0, operator=NOR, else_duration=4
wait 142         # 150 - 3*4 + 4

set_cond 0,0,0,0 # set_enable=0

If the condition is met (unmet), the first set_cond block will have a duration of 150 ns (12 ns), while the second set_cond block will have a duration of 4 ns (142 ns). In both branches the total duration is 154 ns. (adding an additional 4 ns the second set_cond wait time to make both branches the same duration)

Example 2

body = Schedule()
body.add(SquarePulse(duration=50e-9, port=A, clock=B, ...))
body.add(DragPulse(duration=40e-9, port=A, clock=B, ...))

Will compile to q1asm of the form:

set_awg_gain 10000
play 1,0,4      # real-time instruction
wait 46         # real-time instruction
set_awg_gain 10000
play 1,0,4      # real-time instruction
wait 36         # real-time instruction

This has a total duration of 90 ns and has 4 real-time instructions.

passing the body to a conditional:

schedule.add(ConditionalOperation(body, "q0"))

will compile it to the following q1asm:

set_cond 1,1,0,4 # set_enable=1, mask=0, operator=OR, else_duration=4
set_awg_gain 10000
play 1,0,4      # real-time instruction
wait 46         # real-time instruction
set_awg_gain 10000
play 1,0,4      # real-time instruction
wait 36         # real-time instruction

set_cond 1,1,1,4 # set_enable=1, mask=0, operator=NOR, else_duration=4
wait 78 # 90 - 4*4 + 4

set_cond 0,0,0,0 # set_enable=0

If the condition is met (unmet), the first set_cond block will have a duration of 90 ns (16 ns), while the second set_cond block will have a duration of 4 ns (78 ns). In both branches the total duration is 94 ns. (adding an additional 4 ns the second set_cond wait time to make both branches the same duration)


This implementation will ensure that:

  • any subschedule that is passed to conditional playback will run without raising errors.
  • at the expense of an additional 4 ns.
  • with a limitation that the duration of the body needs to be less than 65528 ns + 4 ns *number_of_real_time_instructions

explanation

The else_duration is the wait time per real time instruction in the conditional block. If a trigger happened, the first block runs normally for 50 ns, the second block runs for 4 ns. If there is no trigger, the first block runs for 3*4 = 12 ns, second block for 42 ns. So the duration in both cases is 42 ns. Note that set_cond itself has zero duration.


todos:

  • fix circular import error
  • add tests
  • raise error when duration > 65528 ns + 4 ns *number_of_real_time_instructions
  • update conditional playback documentation

Merge checklist

See also merge request guidelines

  • Merge request has been reviewed (in-depth by a knowledgeable contributor), and is approved by a project maintainer.
  • New code is covered by unit tests (or N/A).
  • New code is documented and docstrings use numpydoc format (or N/A).
  • New functionality: considered making private instead of extending public API (or N/A).
  • Public API changed: added @deprecated and entry in deprecated code suggestions (or N/A).
  • Newly added/adjusted documentation and docstrings render properly (or N/A).
  • Pipeline fix or dependency update: post in #software-for-developers channel to merge main back in or update local packages (or N/A).
  • Tested on hardware (or N/A).
  • CHANGELOG.md for breaking changes and AUTHORS.md have been updated (or N/A).
  • Update Hardware backends documentation if backend interface change or N/A
  • Check whether performance is significantly affected by looking at the Performance metrics results.
  • Windows tests in CI pipeline pass (manually triggered by maintainers before merging).
    • Maintainers do not hit Auto-merge, we need to actively check as manual tests do not block pipeline

For reference, the issues workflow is described in the contribution guidelines.

Summary by CodeRabbit

  • New Features

    • Introduced ConditionalOperation for executing operations based on conditional logic.
    • Enhanced conditional method in QASMProgram for improved instruction timing.
  • Bug Fixes

    • Improved error handling in various tests related to conditional operations and pulse compensation.
  • Tests

    • Added comprehensive unit tests for conditional operations and control flow.
    • Expanded existing tests to cover edge cases and improve validation accuracy.
  • Documentation

    • Enhanced docstrings and comments for better clarity on functionality and usage.
Edited by CodeRabbit

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Gábor Oszkár Dénes
  • Robert Sokolewicz changed the description

    changed the description

  • Robert Sokolewicz marked the checklist item fix circular import error as completed

    marked the checklist item fix circular import error as completed

  • Robert Sokolewicz marked the checklist item add tests as completed

    marked the checklist item add tests as completed

  • added 1 commit

    • fad85926 - Apply 3 suggestion(s) to 1 file(s)

    Compare with previous version

  • Gábor Oszkár Dénes resolved all threads

    resolved all threads

  • Gábor Oszkár Dénes approved this merge request

    approved this merge request

  • Gábor Oszkár Dénes marked the checklist item New code is covered by unit tests (or N/A). as completed

    marked the checklist item New code is covered by unit tests (or N/A). as completed

  • Gábor Oszkár Dénes marked the checklist item New functionality: considered making private instead of extending public API (or N/A). as completed

    marked the checklist item New functionality: considered making private instead of extending public API (or N/A). as completed

  • Gábor Oszkár Dénes marked the checklist item Public API changed: added @deprecated and entry in deprecated code suggestions (or N/A). as completed

    marked the checklist item Public API changed: added @deprecated and entry in deprecated code suggestions (or N/A). as completed

  • Gábor Oszkár Dénes marked the checklist item Newly added/adjusted documentation and docstrings render properly (or N/A). as completed

    marked the checklist item Newly added/adjusted documentation and docstrings render properly (or N/A). as completed

  • Gábor Oszkár Dénes marked the checklist item Pipeline fix or dependency update: post in #software-for-developers channel to merge main back in or update local packages (or N/A). as completed

    marked the checklist item Pipeline fix or dependency update: post in #software-for-developers channel to merge main back in or update local packages (or N/A). as completed

  • Gábor Oszkár Dénes marked the checklist item Tested on hardware (or N/A). as completed

    marked the checklist item Tested on hardware (or N/A). as completed

  • Gábor Oszkár Dénes marked the checklist item Update Hardware backends documentation if backend interface change or N/A as completed

    marked the checklist item Update Hardware backends documentation if backend interface change or N/A as completed

  • Gábor Oszkár Dénes marked the checklist item Check whether performance is significantly affected by looking at the Performance metrics results. as completed

    marked the checklist item Check whether performance is significantly affected by looking at the Performance metrics results. as completed

  • CodeRabbit changed the description

    changed the description

  • Walkthrough

    The pull request introduces significant modifications to the ConditionalManager and FeedbackTriggerOperator classes in the quantify_scheduler/backends/qblox/conditional.py module, streamlining their functionality. The duration attribute is now a method, and several methods have been removed or simplified. Additionally, a new ConditionalOperation class is introduced in control_flow_library.py, enhancing conditional operation capabilities. The changes also include updates to test suites across various files, adding new tests and modifying existing ones to improve coverage and validation of the scheduling framework.

    Changes

    File Change Summary
    quantify_scheduler/backends/qblox/conditional.py - ConditionalManager: Changed duration to a method, removed replace_enable_conditional, simplified reset, and integrated logic from wait_per_real_time_instruction into duration.
    - FeedbackTriggerOperator: Added __invert__ method.
    - Clarified __post_init__ docstring in FeedbackTriggerCondition.
    quantify_scheduler/backends/qblox/operations/__init__.py - Added ConditionalOperation to __all__ for public API export.
    quantify_scheduler/backends/qblox/operations/control_flow_library.py - Introduced ConditionalOperation class with a constructor and updated duration property.
    quantify_scheduler/backends/qblox/operations/gate_library.py - Updated import path for ConditionalOperation.
    quantify_scheduler/backends/qblox/qasm_program.py - Enhanced conditional and loop method signatures and documentation.
    tests/scheduler/backends/qblox/operations/test_control_flow_library.py - Added unit tests for ConditionalOperation and a helper function for complex schedules.
    tests/scheduler/backends/test_qblox_backend.py - Added multiple new test cases and utility functions for Qblox backend testing.
    tests/scheduler/schedules/test_control_flow.py - Introduced new tests for loop operations and error handling in control flow.
    tests/scheduler/test_gate_library.py - Enhanced existing tests and added new test cases for conditional resets.
    tests/scheduler/test_pulse_compensation.py - Updated error messages and added tests for pulse compensation validation.

    Possibly related PRs

    • #1023: Modifies the ConditionalManager class, related to timing and conditions in quantum operations.
    • #1037: Introduces TimetagTrace, closely related to changes in FeedbackTriggerOperator and ConditionalManager.
    • #1070: Focuses on ConditionalManager and timing logic, aligning with enhancements to operational logic in the scheduling framework.

    Suggested labels

    MR State::2. Review me!


    Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

    :heart: Share
    🪧 Tips

    Chat

    There are 3 ways to chat with CodeRabbit:

    • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
      • I pushed a fix in commit <commit_id>, please review it.
      • Generate unit testing code for this file.
    • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
      • @coderabbitai generate unit testing code for this file.
      • @coderabbitai modularize this function.
    • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
      • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
      • @coderabbitai read src/utils.ts and generate unit testing code.
      • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
      • @coderabbitai help me debug CodeRabbit configuration file.

    Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

    CodeRabbit Commands (Invoked using PR comments)

    • @coderabbitai pause to pause the reviews on a PR.
    • @coderabbitai resume to resume the paused reviews.
    • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
    • @coderabbitai full review to do a full review from scratch and review all the files again.
    • @coderabbitai summary to regenerate the summary of the PR.
    • @coderabbitai resolve resolve all the CodeRabbit review comments.
    • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
    • @coderabbitai help to get help.

    Other keywords and placeholders

    • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
    • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
    • Add @coderabbitai anywhere in the PR title to generate the title automatically.

    CodeRabbit Configuration File (.coderabbit.yaml)

    • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
    • Please see the configuration documentation for more information.
    • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

    Documentation and Community

    • Visit our Documentation for detailed information on how to use CodeRabbit.
    • Join our Discord Community to get help, request features, and share feedback.
    • Follow us on X/Twitter for updates and announcements.
    Edited by CodeRabbit
  • Actionable comments posted: 17

    🧹 Outside diff range comments (13)
    quantify_scheduler/backends/qblox/operations/gate_library.py (2)

    Line range hint 14-103: LGTM! Consider updating the docstring.

    The ConditionalReset class implementation looks good and is consistent with the updated import. The functionality aligns with the PR objectives.

    Consider updating the docstring to reflect any changes in the total duration calculation, especially if the 65528 ns limit mentioned in the PR objectives is relevant to this class.


    Remaining references to old import paths found.

    The following files still contain references to the old import paths and need to be updated accordingly:

    • quantify_scheduler/backends/qblox/operations/control_flow_library.py
    • quantify_scheduler/backends/qblox/operations/__init__.py
    :link: Analysis chain

    Line range hint 1-103: Summary: Import path updated, functionality preserved.

    The changes in this file are minimal and focused on updating the import path for ConditionalOperation. The ConditionalReset class implementation remains unchanged, preserving its functionality. These changes align with the PR objectives to enhance conditional playback functionality.

    To ensure consistency across the codebase, please run the following verification script:

    This will help identify any other files that may need similar updates to their import statements.

    :checkered_flag: Scripts executed

    The following scripts were executed for the analysis:

    Script:

    #!/bin/bash
    # Description: Check for any remaining references to the old import path
    
    # Test: Search for any remaining imports from the old path
    rg --type python 'from quantify_scheduler.operations.control_flow_library import ConditionalOperation'
    
    # Test: Search for any imports of ConditionalOperation to ensure consistency
    rg --type python 'import.*ConditionalOperation'
    

    Length of output: 216


    Script:

    #!/bin/bash
    # Description: Check for any remaining references to the old import path
    
    # Test: Search for any remaining imports from the old path
    rg --type py 'from quantify_scheduler.operations.control_flow_library import ConditionalOperation'
    
    # Test: Search for any imports of ConditionalOperation to ensure consistency
    rg --type py 'import.*ConditionalOperation'
    

    Length of output: 417

    tests/scheduler/schedules/test_control_flow.py (3)

    Line range hint 64-108: LGTM: Updated error message for ConditionalOperation

    The modification to include hardware_buffer_time=0.0 in the error message is appropriate and reflects the current implementation of ConditionalOperation. This test ensures that adding multiple conditional operations without a preceding acquisition raises the correct error.

    Consider using a constant for the error message to improve maintainability. For example:

    CONDITIONAL_ERROR_MSG = (
        "Conditional control flow, "
        "``ConditionalOperation"
        '(body=Schedule "" containing (1) 1  (unique) operations.'
        ",qubit_name='q0',t0=0.0,hardware_buffer_time=0.0)``,  "
        "found without a preceding Conditional acquisition. "
    )
    
    # Then in the test:
    with pytest.raises(RuntimeError, match=CONDITIONAL_ERROR_MSG):
        ...

    This approach would make it easier to update the error message in the future if needed.


    Line range hint 111-163: LGTM: Comprehensive test for nested conditional playback

    This new test function effectively verifies that nested conditional playback raises the appropriate RuntimeError. The setup is thorough, using mocks to isolate the test case, which is a good practice.

    Consider extracting the error message to a constant at the top of the file or in a separate constants file. This would make it easier to update if the error message changes in the future. For example:

    NESTED_CONDITIONAL_ERROR_MSG = (
        "Nested conditional playback inside schedules "
        "is not supported by the Qblox backend."
    )
    
    # Then in the test:
    with pytest.raises(RuntimeError, match=NESTED_CONDITIONAL_ERROR_MSG):
        ...

    This approach improves maintainability and ensures consistency if the error message is used elsewhere in the codebase.


    Line range hint 176-183: LGTM: Consistent test for deprecated control_flow with Conditional

    This test function effectively checks that using the deprecated control_flow argument with Conditional raises the appropriate FutureWarning. It maintains consistency with the previous test for Loop.

    For both this test and the previous one (test_deprecated_control_flow_loop_warns), consider extracting the common warning message to a constant. This would improve maintainability and ensure consistency. For example:

    DEPRECATED_CONTROL_FLOW_WARNING = (
        "Using the `control_flow` argument in `Schedule.add` is deprecated, "
        "and will be removed from the public interface"
    )
    
    # Then in both tests:
    with pytest.warns(FutureWarning, match=DEPRECATED_CONTROL_FLOW_WARNING):
        ...

    This approach would make it easier to update the warning message in the future if needed, and ensure it's consistent across all related tests.

    tests/scheduler/test_pulse_compensation.py (1)

    Line range hint 264-352: Great addition of new tests! Consider parameterizing the test_pulse_compensation_inconsistent_parameters function.

    The new test functions test_pulse_compensation_invalid_operation and test_pulse_compensation_inconsistent_parameters significantly improve the robustness of the test suite by covering edge cases and potential errors in pulse compensation. These additions are in line with the PR objectives of adding tests.

    The error messages in these tests provide clear explanations of the issues, which is excellent for debugging and maintaining the code.

    Consider parameterizing the test_pulse_compensation_inconsistent_parameters function to test different combinations of inconsistent parameters. This could make the test more comprehensive and easier to extend in the future. For example:

    @pytest.mark.parametrize("param, q0_value, q1_value, expected_error", [
        ("time_grid", 1e-9, 4e-9, "'time_grid' must be the same for every device element..."),
        ("sampling_rate", 2e9, 1e9, "'sampling_rate' must be the same for every device element...")
    ])
    def test_pulse_compensation_inconsistent_parameters(
        param, q0_value, q1_value, expected_error, mock_setup_basic_transmon_with_standard_params
    ):
        # Test setup...
        
        q0.pulse_compensation.max_compensation_amp(0.6)
        q1.pulse_compensation.max_compensation_amp(0.7)
        
        setattr(q0.pulse_compensation, param, q0_value)
        setattr(q1.pulse_compensation, param, q1_value)
        
        with pytest.raises(ValueError) as exception:
            compiler.compile(...)
        
        assert exception.value.args[0] == expected_error

    This approach would make it easier to add more test cases for different inconsistent parameters in the future.

    tests/scheduler/backends/test_qblox_backend.py (7)

    Line range hint 5524-5552: Use keyword arguments in method calls for clarity

    In the test function test_stitched_pulse_compilation_smoke_test, consider using keyword arguments when calling methods like add_voltage_offset to improve readability and reduce the chance of errors due to incorrect parameter ordering.

    Apply this diff to enhance clarity:

     builder = StitchedPulseBuilder(port=port, clock=clock)
     stitched_pulse = (
         builder.add_pulse(SquarePulse(amp=0.16, duration=5e-6, port=port, clock=clock))
    -    .add_voltage_offset(0.4, 0.0, duration=5e-6)
    +    .add_voltage_offset(path_I=0.4, path_Q=0.0, duration=5e-6)
         .build()
     )

    Line range hint 5589-5591: Handle the case where 'set_awg_offs' is not found

    In the loop searching for the 'set_awg_offs' instruction, if the instruction is not found, the variable i remains undefined, leading to a NameError. To prevent unexpected exceptions, add an else clause or use next with a default value.

    Apply this diff to handle the potential exception:

    -    for i, string in enumerate(program_with_long_square):
    +    for i, string in enumerate(program_with_long_square):
             if "set_awg_offs" in string:
                 break
    +    else:
    +        raise AssertionError("'set_awg_offs' instruction not found in the program")

    Line range hint 5643-5652: Use textwrap.dedent for multi-line strings in assertions

    When asserting multi-line strings, leading indentation can cause comparisons to fail. Use textwrap.dedent to normalize the string indentation and ensure the assert statement functions as intended.

    Apply this diff to improve robustness:

    +        import textwrap
             assert (
    -            """ set_awg_offs 16384,0 # setting offset for long_square_pulse
    +            textwrap.dedent(
    +                """ set_awg_offs 16384,0 # setting offset for long_square_pulse
         upd_param 4 
         wait 3992 # auto generated wait (3992 ns)
         set_awg_offs 0,0 # setting offset for long_square_pulse
         set_awg_gain 16384,0 # setting gain for long_square_pulse
         play 0,0,4 # play long_square_pulse (4 ns)
    +                """
                 )
             ) in compiled_sched.compiled_instructions["cluster0"]["cluster0_module4"][
                 "sequencers"
             ]["seq0"]["sequence"]["program"]

    Line range hint 5691-5710: Avoid modifying the original operation in test_auto_compile_long_square_pulses

    In the test test_auto_compile_long_square_pulses, you compare the compiled schedule's operation with the original long_square_pulse. To ensure the original operation remains unaltered, consider using deepcopy when saving square_pulse.

    Apply this diff to prevent side effects:

         square_pulse = SquarePulse(
             amp=0.2,
             duration=2.5e-6,
             port=port,
             clock=clock,
             t0=1e-6,
         )
    -    saved_pulse = copy.deepcopy(square_pulse)
    +    saved_pulse = deepcopy(square_pulse)
         sched.add(square_pulse)

    Line range hint 5760-5794: Consolidate repeated code in test_too_long_waveform_raises2

    The test function contains repeated code for adding pulses with similar parameters. Refactor to use a helper function or loop to reduce duplication and improve maintainability.

    Apply this diff to refactor the code:

    +    def add_pulse(duration_offset):
    +        return DRAGPulse(
    +            G_amp=0.5,
    +            D_amp=-0.2,
    +            phase=90,
    +            port="q0:res",
    +            duration=(constants.MAX_SAMPLE_SIZE_WAVEFORMS // 4 + duration_offset) * 1e-9,
    +            clock="q0.ro",
    +            t0=4e-9,
    +        )
    +
         sched.add(
    -        DRAGPulse(
    -            G_amp=0.5,
    -            D_amp=-0.2,
    -            phase=90,
    -            port="q0:res",
    -            duration=constants.MAX_SAMPLE_SIZE_WAVEFORMS // 4 * 1e-9,
    -            clock="q0.ro",
    -            t0=4e-9,
    -        )
    +        add_pulse(duration_offset=0)
         )
         sched.add(
    -        SoftSquarePulse(
    -            amp=0.5,
    -            duration=constants.MAX_SAMPLE_SIZE_WAVEFORMS // 4 * 1e-9,
    -            port="q0:res",
    -            clock="q0.ro",
    -        )
    +        add_pulse(duration_offset=0)
         )
         sched.add(
    -        RampPulse(
    -            amp=0.5,
    -            duration=(constants.MAX_SAMPLE_SIZE_WAVEFORMS // 4 + 4) * 1e-9,
    -            port="q0:res",
    -            clock="q0.ro",
    -        )
    +        add_pulse(duration_offset=4)
         )

    Line range hint 5832-5878: Use pytest.warns to catch expected warnings

    In test_overlapping_operations_warn, you check for expected warnings using pytest.warns. Ensure that the warning message matches exactly, or use a more general pattern to avoid brittle tests that may fail with minor message changes.

    Apply this diff to make the test more robust:

    -        with pytest.warns(RuntimeWarning, match=expected):
    +        with pytest.warns(RuntimeWarning, match=re.escape(expected)):
                 compiler.compile(sched, compile_config_basic_transmon_qblox_hardware)

    Line range hint 6017-6159: Add docstrings to TestControlFlow methods

    The methods within the TestControlFlow class lack docstrings, which are helpful for understanding test purposes and improving code readability. Consider adding descriptive docstrings to each method.

    Apply this diff to include docstrings:

     class TestControlFlow:
         @staticmethod
         def _replace_multiple_spaces(s: str) -> str:
    +        """Helper function to normalize whitespace in a string."""
             s = re.sub(r" *\n *", "\n", s)
             return re.sub(r" {2,}", " ", s)
     
         def _compare_sequence(self, compiled, reference, module):
    +        """Compares the compiled sequence with the reference sequence."""
             if module == "qcm":
                 mod = "cluster0_module2"
             elif module == "qrm":
                 mod = "cluster0_module4"
             program = self._replace_multiple_spaces(
                 compiled.compiled_instructions["cluster0"][mod]["sequencers"]["seq0"][
                     "sequence"
                 ]["program"]
             )
             reference = self._replace_multiple_spaces(reference)
             assert reference == program
     
         def test_subschedule(self, compile_config_basic_transmon_qblox_hardware):
    +        """Tests subschedule integration and compilation."""
             # (rest of the method)
    :scroll: Review details

    Configuration used: CodeRabbit UI Review profile: ASSERTIVE

    :inbox_tray: Commits

    Files that changed from the base of the PR and between f3e88a51 and fad85926.

    :ledger: Files selected for processing (11)
    • quantify_scheduler/backends/qblox/conditional.py (2 hunks)
    • quantify_scheduler/backends/qblox/operations/init.py (2 hunks)
    • quantify_scheduler/backends/qblox/operations/control_flow_library.py (1 hunks)
    • quantify_scheduler/backends/qblox/operations/gate_library.py (1 hunks)
    • quantify_scheduler/backends/qblox/qasm_program.py (3 hunks)
    • quantify_scheduler/operations/control_flow_library.py (4 hunks)
    • tests/scheduler/backends/qblox/operations/test_control_flow_library.py (1 hunks)
    • tests/scheduler/backends/test_qblox_backend.py (1 hunks)
    • tests/scheduler/schedules/test_control_flow.py (1 hunks)
    • tests/scheduler/test_gate_library.py (1 hunks)
    • tests/scheduler/test_pulse_compensation.py (1 hunks)
    🧰 Additional context used
    :mute: Additional comments (17)
    quantify_scheduler/backends/qblox/operations/__init__.py (3)

    3-3: LGTM: Import statement is correctly placed and formatted.

    The import statement for ConditionalOperation is properly placed at the top of the file, consistent with the other import statements. This follows Python's PEP 8 style guide for imports.


    12-12: LGTM: ConditionalOperation correctly added to __all__.

    The addition of "ConditionalOperation" to the __all__ list is correct and consistent with the other entries. This explicitly makes ConditionalOperation part of the public API of the module.


    Line range hint 1-13: Verify the impact of adding ConditionalOperation to the public API.

    While the changes look good, it's important to ensure that exposing ConditionalOperation in the public API is intentional and doesn't have unintended consequences for existing users of the package.

    Run the following script to check for any existing usage of ConditionalOperation in the codebase:

    This will help verify if ConditionalOperation is already being used elsewhere in the codebase and if it's properly documented.

    :white_check_mark: Verification successful

    Verified: Adding ConditionalOperation to the public API is intentional and does not introduce unintended consequences. It is actively used and properly documented within the codebase.

    :checkered_flag: Scripts executed

    The following scripts were executed for the analysis:

    Script:

    #!/bin/bash
    # Description: Check for existing usage of ConditionalOperation
    
    # Test: Search for imports or usage of ConditionalOperation
    rg --type python -e 'from .+import ConditionalOperation' -e 'ConditionalOperation'
    
    # Test: Check if ConditionalOperation is documented
    rg --type rst -e 'ConditionalOperation'
    

    Length of output: 153


    Script:

    #!/bin/bash
    # Description: Check for existing usage of ConditionalOperation without specifying file types
    
    # Test: Search for imports or usage of ConditionalOperation in all files
    rg 'from .+import ConditionalOperation' .
    rg 'ConditionalOperation' .
    
    # Test: Check if ConditionalOperation is documented in all files
    rg 'ConditionalOperation' .
    

    Length of output: 12356

    quantify_scheduler/backends/qblox/operations/gate_library.py (1)

    7-9: LGTM! Verify the new import path.

    The update to the import path for ConditionalOperation looks good. This change aligns with the PR objectives to enhance the conditional playback functionality.

    To ensure the new import path is correct, please run the following verification script:

    tests/scheduler/backends/qblox/operations/test_control_flow_library.py (1)

    1-15: LGTM: Import statements are well-organized and appropriate.

    The import statements are logically organized and include all necessary modules for the test file. Standard libraries are imported first, followed by third-party libraries (pytest), and then local imports from quantify_scheduler.

    tests/scheduler/schedules/test_control_flow.py (2)

    Line range hint 42-61: LGTM: Well-structured test class for LoopOperation

    The TestLoops class is a well-structured addition that tests the behavior of nested loops using LoopOperation. The test case correctly verifies that the outer schedule's repetitions remain 1 despite the inner loop having 10 repetitions. This is crucial for ensuring that nested loops behave as expected within the scheduler.


    Line range hint 166-173: LGTM: Good test for deprecated control_flow with Loop

    This test function effectively checks that using the deprecated control_flow argument with Loop raises the appropriate FutureWarning. It's crucial for ensuring that users are properly notified about deprecated features.

    The warning message is clear and informative, which will help users understand why they're seeing the warning and what action they need to take.

    quantify_scheduler/backends/qblox/qasm_program.py (5)

    482-487: Improved documentation for the conditional method.

    The updated comment provides a clearer explanation of the context manager's behavior, specifically mentioning the insertion of additional set_cond QASM instructions. This enhancement improves the overall clarity of the code and its functionality.


    490-502: Excellent addition of an illustrative example for conditional blocks.

    The newly added example greatly enhances the understanding of how conditional blocks work in the QASM program. It provides concrete QASM instructions and clear explanations of timing calculations, which is invaluable for both users and maintainers of the code. This addition effectively addresses the previous review comment about including an explanation of conditional operations.


    527-532: Updated FEEDBACK_SET_COND instruction to ensure minimum time between operations.

    The emit method call for the initial FEEDBACK_SET_COND instruction has been updated to use constants.MIN_TIME_BETWEEN_OPERATIONS for the else_duration parameter. This change ensures a minimum time between operations, likely addressing a hardware requirement. The modification aligns well with the example provided earlier in the comments, maintaining consistency in the implementation.


    Line range hint 539-568: Improved handling of 'else' branch and conditional playback timing.

    The updates to the 'else' branch handling and conditional playback stopping logic are significant improvements:

    1. The new duration calculation takes into account the number of real-time instructions and the minimum time between operations, providing more accurate timing.
    2. The elapsed time is now updated after stopping conditional playback, ensuring precise timing tracking in the program.

    These changes result in a more robust and accurate implementation of conditional playback in the QASM program.


    Line range hint 590-590: Enhanced documentation in the loop method.

    A helpful comment has been added to explain the purpose of the register variable as "iterator for loop with label {label}". This minor change improves code readability and contributes to better overall documentation of the loop method.

    quantify_scheduler/backends/qblox/operations/control_flow_library.py (1)

    61-72: Constructor implementation is correct and clear.

    The __init__ method correctly initializes the ConditionalOperation with all necessary parameters and sets the hardware_buffer_time. The conversion of MIN_TIME_BETWEEN_OPERATIONS to seconds is appropriately handled.

    quantify_scheduler/backends/qblox/conditional.py (1)

    71-82: Addition of __invert__ method enhances enum usability and readability.

    The implementation of the __invert__ method allows for logical negation of FeedbackTriggerOperator instances using the ~ operator. This enhances code readability and aligns with Python's operator overloading conventions.

    quantify_scheduler/operations/control_flow_library.py (1)

    187-190: Ensure duration calculation accounts for all timing components

    The duration property adds hardware_buffer_time to the body's duration. Verify that any additional hardware-specific delays or requirements are accounted for elsewhere, or consider documenting them here.

    Double-check that there are no other timing components that should be included in the duration calculation. If there are, update the calculation accordingly.

    tests/scheduler/test_gate_library.py (1)

    379-379: Verify the correctness of expected_mask calculation

    The calculation of expected_mask using expected_mask = str(2**expected_address - 1) assumes that the mask is a bitmask with bits set up to expected_address. Ensure that expected_address is within a valid range and that this calculation aligns with the intended behavior of the mask.

    To confirm that expected_address does not exceed the allowable bit width, you can run the following script:

    tests/scheduler/backends/test_qblox_backend.py (1)

    6301-6305: :warning: Potential issue

    Ensure correct indentation for ConditionalOperation

    The ConditionalOperation block appears to be misaligned. Proper indentation is crucial for code readability and maintaining the logical structure.

    Apply this diff to correct the indentation:

             schedule.add(
    -            ConditionalOperation(
    -                body=X("q0"),
    -                qubit_name="q0",
    -                hardware_buffer_time=4e-9,
    -            ),
    +        ConditionalOperation(
    +            body=X("q0"),
    +            qubit_name="q0",
    +            hardware_buffer_time=4e-9,
    +        ),
                 rel_time=364e-9,
             )

    Likely invalid or redundant comment.

  • CodeRabbit
  • CodeRabbit
  • CodeRabbit
  • CodeRabbit
  • CodeRabbit
  • CodeRabbit
  • CodeRabbit
  • CodeRabbit
  • CodeRabbit
  • CodeRabbit
  • CodeRabbit
  • CodeRabbit
  • CodeRabbit
  • CodeRabbit
  • CodeRabbit
  • CodeRabbit
  • Robert Sokolewicz resolved all threads

    resolved all threads

  • Robert Sokolewicz marked this merge request as ready

    marked this merge request as ready

  • added 18 commits

    Compare with previous version

  • added 1 commit

    Compare with previous version

  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Please register or sign in to reply
    Loading