quairkit.core.test

Common settings and utilities for the unit test

quairkit.core.test.get_test_device_list()

Return the device list for tests.

Policy: - Always test CPU. - By default, do NOT expand to CUDA for the whole suite (many tests rely on CPU-only numpy/scipy paths).

You can opt-in by setting environment variable QUAIRKIT_TEST_ALL_DEVICES=1.

quairkit.core.test.get_state_simulator_test_device_list()

Return the device list for StateSimulator-focused tests.

Policy: - Always test CPU. - Automatically include CUDA when available.

class quairkit.core.test.PerformanceMonitor

Monitor performance metrics (time and memory) for test functions.

property wall_time : float

Wall time in seconds.

property memory_peak : float

Peak memory usage in MB.

property memory_delta : float

Memory delta from start to peak in MB.

to_dict()

Convert to dictionary for JSON serialization.

quairkit.core.test.get_version()

Get the version from quairkit package.

quairkit.core.test.get_commit_hash()

Get the git commit hash of the current repository.

Returns:

Short commit hash (7 characters) if git is available, otherwise “unknown”.

Return type:

str

quairkit.core.test.generate_test_report(test_results, output_dir=None, format='json')

Generate a test performance report.

Parameters:
test_results : Dict[str, Dict[str, Any]]

Dictionary mapping test names to their performance metrics.

output_dir : str | Path | None

Directory to save the report. Defaults to tests/reports/.

format : str

Output format, either “json” or “csv”. Defaults to “json”.

Returns:

Path to the generated report file.

Return type:

Path

quairkit.core.test.generate_system_index_permutations(num_systems, num_acted, max_permutations=None, include_sequential=True, include_shuffled=True, include_partial=True)

Generate various system index permutations for testing.

Parameters:
num_systems : int

Total number of systems.

num_acted : int

Number of systems the operation acts on.

max_permutations : int | None

Maximum number of permutations to generate. If None, generates all.

include_sequential : bool

Include sequential indices like [0, 1, 2].

include_shuffled : bool

Include shuffled indices.

include_partial : bool

Include cases where not all systems are used.

Returns:

List of system index lists.

Return type:

List[List[int]]

quairkit.core.test.generate_batch_dimensions(default_range=(1, 3), special_range=None)

Generate batch dimension combinations for testing.

Parameters:
default_range : Tuple[int, int]

Default range for batch sizes (min, max).

special_range : Tuple[int, int] | None

Special range for cases needing more systems (min, max).

Returns:

List of batch dimension lists, including [], [1], [n], [m, n] combinations.

Return type:

List[List[int]]

quairkit.core.test.generate_system_dim_combinations(num_systems, default_dim_range=(2, 3), qudit_combinations=None)

Generate system dimension combinations for testing.

Parameters:
num_systems : int

Number of systems.

default_dim_range : Tuple[int, int]

Default dimension range (min, max).

qudit_combinations : List[List[int]] | None

Optional predefined qudit combinations.

Returns:

List of system dimension lists.

Return type:

List[List[int]]

quairkit.core.test.track_performance(test_name=None)

Decorator to track performance of a test function.

Usage:

@track_performance("test_name")
def test_xxx():
    ...
quairkit.core.test.get_test_performance_results()

Get all collected test performance results.

quairkit.core.test.clear_test_performance_results()

Clear all collected test performance results.