cqlib_core/compile/resource/policy.rs
1// This code is part of Cqlib.
2//
3// (C) Copyright China Telecom Quantum Group 2025-2026
4//
5// This code is licensed under the Apache License, Version 2.0.
6// You may obtain a copy of this license in the LICENSE.txt file in
7// the root directory of this source tree or at
8// http://www.apache.org/licenses/LICENSE-2.0.
9//
10// Any modifications or derivative works of this code must retain this
11// copyright notice, and modified files need to carry a notice indicating
12// that they have been altered from the originals.
13
14/// Policy controlling which ancillary resources the compiler may use.
15///
16/// Policy expresses compiler permission rather than device capacity. Use
17/// [`ResourceLimits`] for hard target-derived bounds. The default policy is
18/// conservative: it creates no clean ancillas and does not borrow input qubits.
19#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
20pub struct ResourcePolicy {
21 /// Total number of clean logical ancillary qubits the compiler may create
22 /// before layout. Released qubits remain part of this total and may be
23 /// reused.
24 pub max_pre_layout_clean_ancillas: usize,
25 /// Whether input qubits may be borrowed under the dirty-resource contract.
26 ///
27 /// This permits borrowing only when the consuming algorithm accepts unknown
28 /// input state and restores it exactly. It never makes input qubits eligible
29 /// for clean-zero requests.
30 pub allow_dirty_borrowing: bool,
31}
32
33/// Hard resource limits that may be derived from a target device.
34///
35/// Limits constrain the complete logical circuit, including input qubits and
36/// compiler-allocated clean ancillas.
37#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
38pub struct ResourceLimits {
39 /// Optional maximum total number of logical qubits in the circuit.
40 ///
41 /// `None` means that this manager does not enforce a total-qubit bound.
42 pub max_total_qubits: Option<usize>,
43}