Skip to content
Draft
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
56 changes: 28 additions & 28 deletions source/qdk_package/qdk/qre/_qre.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -924,14 +924,14 @@ class EstimationResult:
"""

def __new__(
cls, *, qubits: int = 0, runtime: int = 0, error: float = 0.0
cls, *, qubits: int = 0, runtime: float = 0.0, error: float = 0.0
) -> EstimationResult:
"""
Create a new estimation result.

Args:
qubits (int): The number of logical qubits.
runtime (int): The runtime in nanoseconds.
runtime (float): The runtime in nanoseconds.
error (float): The error probability of the computation.

Returns:
Expand Down Expand Up @@ -960,22 +960,22 @@ class EstimationResult:
...

@property
def runtime(self) -> int:
def runtime(self) -> float:
"""
The runtime in nanoseconds.

Returns:
int: The runtime in nanoseconds.
float: The runtime in nanoseconds.
"""
...

@runtime.setter
def runtime(self, runtime: int) -> None:
def runtime(self, runtime: float) -> None:
"""
Set the runtime.

Args:
runtime (int): The runtime in nanoseconds to set.
runtime (float): The runtime in nanoseconds to set.
"""
...

Expand Down Expand Up @@ -1113,13 +1113,13 @@ class _EstimationCollection:
...

@property
def all_summaries(self) -> list[tuple[int, int, int, int]]:
def all_summaries(self) -> list[tuple[int, int, int, float]]:
"""
Return lightweight summaries of ALL successful estimates as a list
of (trace_index, isa_index, qubits, runtime) tuples.

Returns:
list[tuple[int, int, int, int]]: List of (trace_index, isa_index,
list[tuple[int, int, int, float]]: List of (trace_index, isa_index,
qubits, runtime) for every successful estimation.
"""
...
Expand All @@ -1140,22 +1140,22 @@ class FactoryResult:
"""

@property
def copies(self) -> int:
def copies(self) -> float:
"""
The number of factory copies.

Returns:
int: The number of factory copies.
float: The number of factory copies.
"""
...

@property
def runs(self) -> int:
def runs(self) -> float:
"""
The number of factory runs.

Returns:
int: The number of factory runs.
float: The number of factory runs.
"""
...

Expand All @@ -1170,12 +1170,12 @@ class FactoryResult:
...

@property
def states(self) -> int:
def states(self) -> float:
"""
The number of states produced by the factory.

Returns:
int: The number of states produced by the factory.
float: The number of states produced by the factory.
"""
...

Expand Down Expand Up @@ -1309,13 +1309,13 @@ class Trace:
"""
...

def increment_resource_state(self, resource_id: int, amount: int) -> None:
def increment_resource_state(self, resource_id: int, amount: float) -> None:
"""
Increments a resource state count.

Args:
resource_id (int): The resource state ID.
amount (int): The amount to increment.
amount (float): The amount to increment.
"""
...

Expand Down Expand Up @@ -1366,34 +1366,34 @@ class Trace:
...

@property
def depth(self) -> int:
def depth(self) -> float:
"""
The trace depth.

Returns:
int: The trace depth.
float: The trace depth.
"""
...

def runtime(self, isa: ISA) -> Optional[int]:
def runtime(self, isa: ISA) -> Optional[float]:
"""
The trace runtime in nanoseconds for a given ISA.

Args:
isa (ISA): The ISA to compute the runtime for.

Returns:
Optional[int]: The trace runtime in nanoseconds, or None if it
Optional[float]: The trace runtime in nanoseconds, or None if it
cannot be computed.
"""

@property
def num_gates(self) -> int:
def num_gates(self) -> float:
"""
The total number of gates in the trace.

Returns:
int: The total number of gates.
float: The total number of gates.
"""
...

Expand Down Expand Up @@ -1425,12 +1425,12 @@ class Trace:
... # The implementation in Rust returns Option<EstimationResult>, so it fits

@property
def resource_states(self) -> dict[int, int]:
def resource_states(self) -> dict[int, float]:
"""
The resource states used in the trace.

Returns:
dict[int, int]: A dictionary mapping instruction IDs to their counts.
dict[int, float]: A dictionary mapping instruction IDs to their counts.
"""
...

Expand All @@ -1456,12 +1456,12 @@ class Trace:
"""
...

def add_block(self, repetitions: int = 1) -> Block:
def add_block(self, repetitions: float = 1) -> Block:
"""
Add a block to the trace.

Args:
repetitions (int): The number of times the block is repeated.
repetitions (float): The number of times the block is repeated.

Returns:
Block: The block.
Expand Down Expand Up @@ -1579,12 +1579,12 @@ class Block:
"""
...

def add_block(self, repetitions: int = 1) -> Block:
def add_block(self, repetitions: float = 1) -> Block:
"""
Add a nested block to the block.

Args:
repetitions (int): The number of times the block is repeated.
repetitions (float): The number of times the block is repeated.

Returns:
Block: The block.
Expand Down
20 changes: 11 additions & 9 deletions source/qdk_package/qdk/qre/interop/_cirq.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from __future__ import annotations

import random
from dataclasses import dataclass
from enum import Enum
from math import pi
Expand Down Expand Up @@ -163,7 +162,7 @@ def __init__(
)
)

def push_block(self, repetitions: int):
def push_block(self, repetitions: float):
"""Open a new repeated block with the given number of repetitions."""
block = self.block.add_block(repetitions)
self._blocks.append(block)
Expand Down Expand Up @@ -279,7 +278,9 @@ def handle_op(
for sub_op in gate._to_trace(self, op): # type: ignore
self.handle_op(sub_op)
elif hasattr(gate, "_decompose_with_context_"):
for sub_op in gate._decompose_with_context_(op.qubits, self.decomp_context): # type: ignore
for sub_op in gate._decompose_with_context_(
op.qubits, self.decomp_context
): # type: ignore
self.handle_op(sub_op)
elif hasattr(gate, "_decompose_"):
# decompose the gate and handle the resulting operations recursively
Expand All @@ -289,8 +290,9 @@ def handle_op(
for sub_op in op._decompose_with_context_(self.decomp_context): # type: ignore
self.handle_op(sub_op)
elif isinstance(op, ClassicallyControlledOperation):
if random.random() < self.classical_control_probability:
self.handle_op(op.without_classical_controls())
self.push_block(self.classical_control_probability)
self.handle_op(op.without_classical_controls())
self.pop_block()
elif isinstance(op, cirq.CircuitOperation):
if isinstance(op.repetitions, int):
self.push_block(op.repetitions)
Expand Down Expand Up @@ -318,7 +320,7 @@ class PushBlock:
repetitions: Number of times the block is repeated.
"""

repetitions: int
repetitions: float


@dataclass(frozen=True, slots=True)
Expand Down Expand Up @@ -595,9 +597,9 @@ def assert_qubits_type(qs: Sequence[cirq.Qid], qubit_type: QubitType) -> None:

for q in qs:
actual_type = _as_typed_qubit(q).qubit_type
assert (
actual_type == qubit_type
), f"{q} expected to be {qubit_type}, was {actual_type}."
assert actual_type == qubit_type, (
f"{q} expected to be {qubit_type}, was {actual_type}."
)


class _TypedQubitManager(cirq.GreedyQubitManager):
Expand Down
34 changes: 17 additions & 17 deletions source/qdk_package/src/qre.rs
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@ impl EstimationCollection {
/// Returns lightweight summaries of ALL successful estimates as a list
/// of (trace index, isa index, qubits, runtime) tuples.
#[getter]
pub fn all_summaries(&self) -> Vec<(usize, usize, u64, u64)> {
pub fn all_summaries(&self) -> Vec<(usize, usize, u64, f64)> {
self.0
.all_summaries()
.iter()
Expand Down Expand Up @@ -956,8 +956,8 @@ pub struct EstimationResult(qre::EstimationResult);
#[pymethods]
impl EstimationResult {
#[new]
#[pyo3(signature = (*, qubits = 0, runtime = 0, error = 0.0))]
pub fn new(qubits: u64, runtime: u64, error: f64) -> Self {
#[pyo3(signature = (*, qubits = 0, runtime = 0.0, error = 0.0))]
pub fn new(qubits: u64, runtime: f64, error: f64) -> Self {
let mut result = qre::EstimationResult::new();
result.add_qubits(qubits);
result.add_runtime(runtime);
Expand All @@ -977,12 +977,12 @@ impl EstimationResult {
}

#[getter]
pub fn runtime(&self) -> u64 {
pub fn runtime(&self) -> f64 {
self.0.runtime()
}

#[setter]
pub fn set_runtime(&mut self, runtime: u64) {
pub fn set_runtime(&mut self, runtime: f64) {
self.0.set_runtime(runtime);
}

Expand Down Expand Up @@ -1057,17 +1057,17 @@ pub struct FactoryResult(qre::FactoryResult);
#[pymethods]
impl FactoryResult {
#[getter]
pub fn copies(&self) -> u64 {
pub fn copies(&self) -> f64 {
self.0.copies()
}

#[getter]
pub fn runs(&self) -> u64 {
pub fn runs(&self) -> f64 {
self.0.runs()
}

#[getter]
pub fn states(&self) -> u64 {
pub fn states(&self) -> f64 {
self.0.states()
}

Expand Down Expand Up @@ -1174,7 +1174,7 @@ impl Trace {
let dict = PyDict::new(self_.py());
if let Some(resource_states) = self_.0.get_resource_states() {
for (resource_id, count) in resource_states {
if *count != 0 {
if *count != 0.0 {
dict.set_item(resource_id, *count)?;
}
}
Expand All @@ -1188,17 +1188,17 @@ impl Trace {
}

#[getter]
pub fn depth(&self) -> u64 {
pub fn depth(&self) -> f64 {
self.0.depth()
}

pub fn runtime(&self, isa: &ISA) -> Option<u64> {
pub fn runtime(&self, isa: &ISA) -> Option<f64> {
let locked = isa.0.lock();
self.0.runtime(&locked).ok()
}

#[getter]
pub fn num_gates(&self) -> u64 {
pub fn num_gates(&self) -> f64 {
self.0.num_gates()
}

Expand Down Expand Up @@ -1237,8 +1237,8 @@ impl Trace {
}
}

#[pyo3(signature = (repetitions = 1))]
pub fn add_block(mut slf: PyRefMut<'_, Self>, repetitions: u64) -> Block {
#[pyo3(signature = (repetitions = 1.0))]
pub fn add_block(mut slf: PyRefMut<'_, Self>, repetitions: f64) -> Block {
let block = slf.0.add_block(repetitions);
let ptr = NonNull::from(block);
Block {
Expand All @@ -1265,7 +1265,7 @@ impl Trace {
self.0.increment_memory_qubits(amount);
}

pub fn increment_resource_state(&mut self, resource_id: u64, amount: u64) {
pub fn increment_resource_state(&mut self, resource_id: u64, amount: f64) {
self.0.increment_resource_state(resource_id, amount);
}

Expand Down Expand Up @@ -1358,8 +1358,8 @@ impl Block {
unsafe { self.ptr.as_mut() }.add_operation(id, qubits, params);
}

#[pyo3(signature = (repetitions = 1))]
pub fn add_block(&mut self, py: Python<'_>, repetitions: u64) -> PyResult<Block> {
#[pyo3(signature = (repetitions = 1.0))]
pub fn add_block(&mut self, py: Python<'_>, repetitions: f64) -> PyResult<Block> {
let block = unsafe { self.ptr.as_mut() }.add_block(repetitions);
let ptr = NonNull::from(block);
Ok(Block {
Expand Down
Loading
Loading