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
8 changes: 7 additions & 1 deletion source/pip/qsharp/qre/interop/_qsharp.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
from ...estimator import LogicalCounts
from .._qre import Trace
from ..instruction_ids import CCX, MEAS_Z, RZ, T, READ_FROM_MEMORY, WRITE_TO_MEMORY
from ..property_keys import EVALUATION_TIME
from ..property_keys import (
EVALUATION_TIME,
ALGORITHM_COMPUTE_QUBITS,
ALGORITHM_MEMORY_QUBITS,
)


def _bucketize_rotation_counts(
Expand Down Expand Up @@ -103,6 +107,8 @@ def trace_from_entry_expr(entry_expr: str | Callable | LogicalCounts) -> Trace:
block.add_operation(WRITE_TO_MEMORY, [0, compute_qubits])

trace.set_property(EVALUATION_TIME, evaluation_time)
trace.set_property(ALGORITHM_COMPUTE_QUBITS, compute_qubits)
trace.set_property(ALGORITHM_MEMORY_QUBITS, memory_qubits)
return trace


Expand Down
4 changes: 4 additions & 0 deletions source/pip/qsharp/qre/property_keys.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ PHYSICAL_COMPUTE_QUBITS: int
PHYSICAL_FACTORY_QUBITS: int
PHYSICAL_MEMORY_QUBITS: int
MOLECULE: int
LOGICAL_COMPUTE_QUBITS: int
LOGICAL_MEMORY_QUBITS: int
ALGORITHM_COMPUTE_QUBITS: int
ALGORITHM_MEMORY_QUBITS: int
6 changes: 5 additions & 1 deletion source/pip/src/qre.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1522,7 +1522,11 @@ fn add_property_keys(m: &Bound<'_, PyModule>) -> PyResult<()> {
PHYSICAL_COMPUTE_QUBITS,
PHYSICAL_FACTORY_QUBITS,
PHYSICAL_MEMORY_QUBITS,
MOLECULE
MOLECULE,
LOGICAL_COMPUTE_QUBITS,
LOGICAL_MEMORY_QUBITS,
ALGORITHM_COMPUTE_QUBITS,
ALGORITHM_MEMORY_QUBITS,
);

m.add_submodule(&property_keys)?;
Expand Down
15 changes: 14 additions & 1 deletion source/pip/tests/test_qre.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,14 @@
ISARefNode,
)
from qsharp.qre.instruction_ids import CCX, CCZ, LATTICE_SURGERY, T, RZ
from qsharp.qre.property_keys import DISTANCE, NUM_TS_PER_ROTATION
from qsharp.qre.property_keys import (
DISTANCE,
NUM_TS_PER_ROTATION,
ALGORITHM_COMPUTE_QUBITS,
ALGORITHM_MEMORY_QUBITS,
LOGICAL_COMPUTE_QUBITS,
LOGICAL_MEMORY_QUBITS,
)

# NOTE These classes will be generalized as part of the QRE API in the following
# pull requests and then moved out of the tests.
Expand Down Expand Up @@ -842,8 +849,14 @@ def test_qsharp_application():
assert trace2.resource_states == {
T: num_ts + psspc.num_ts_per_rotation * num_rotations + 4 * num_ccx
}
assert trace2.get_property(ALGORITHM_COMPUTE_QUBITS) == 3
assert trace2.get_property(ALGORITHM_MEMORY_QUBITS) == 0
result = trace2.estimate(isa, max_error=float("inf"))
assert result is not None
assert result.properties[ALGORITHM_COMPUTE_QUBITS] == 3
assert result.properties[ALGORITHM_MEMORY_QUBITS] == 0
assert result.properties[LOGICAL_COMPUTE_QUBITS] == 12
assert result.properties[LOGICAL_MEMORY_QUBITS] == 0
_assert_estimation_result(trace2, result, isa)
assert counter == 32

Expand Down
4 changes: 4 additions & 0 deletions source/qre/src/isa/property_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,8 @@ define_properties! {
PHYSICAL_FACTORY_QUBITS,
PHYSICAL_MEMORY_QUBITS,
MOLECULE,
LOGICAL_COMPUTE_QUBITS,
LOGICAL_MEMORY_QUBITS,
ALGORITHM_COMPUTE_QUBITS,
ALGORITHM_MEMORY_QUBITS,
}
15 changes: 14 additions & 1 deletion source/qre/src/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ use serde::{Deserialize, Serialize};
use crate::{
Error, EstimationCollection, EstimationResult, FactoryResult, ISA, Instruction, LockedISA,
ProvenanceGraph, ResultSummary,
property_keys::{PHYSICAL_COMPUTE_QUBITS, PHYSICAL_FACTORY_QUBITS, PHYSICAL_MEMORY_QUBITS},
property_keys::{
LOGICAL_COMPUTE_QUBITS, LOGICAL_MEMORY_QUBITS, PHYSICAL_COMPUTE_QUBITS,
PHYSICAL_FACTORY_QUBITS, PHYSICAL_MEMORY_QUBITS,
},
};

pub mod instruction_ids;
Expand Down Expand Up @@ -335,6 +338,16 @@ impl Trace {
}
}

// Make main trace metrics properties to access them from the result
result.set_property(
LOGICAL_COMPUTE_QUBITS,
Property::Int(self.compute_qubits.cast_signed()),
);
result.set_property(
LOGICAL_MEMORY_QUBITS,
Property::Int(self.memory_qubits.unwrap_or(0).cast_signed()),
);

// Copy properties from the trace to the result
for (key, value) in &self.properties {
result.set_property(*key, value.clone());
Expand Down
Loading