Skip to content
8 changes: 4 additions & 4 deletions source/pip/benchmarks/bench_qre.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from dataclasses import dataclass, KW_ONLY, field
from qsharp.qre import linear_function, generic_function
from qsharp.qre._architecture import _make_instruction
from qsharp.qre.models import AQREGateBased, SurfaceCode
from qsharp.qre.models import GateBased, SurfaceCode
from qsharp.qre._enumeration import _enumerate_instances


Expand Down Expand Up @@ -37,10 +37,10 @@ def bench_enumerate_isas():

# Add the tests directory to sys.path to import test_qre
# TODO: Remove this once the models in test_qre are moved to a proper module
sys.path.append(os.path.join(os.path.dirname(__file__), "../tests"))
from test_qre import ExampleLogicalFactory, ExampleFactory # type: ignore
sys.path.append(os.path.join(os.path.dirname(__file__), "../tests/qre/"))
from conftest import ExampleLogicalFactory, ExampleFactory # type: ignore

ctx = AQREGateBased(gate_time=50, measurement_time=100).context()
ctx = GateBased(gate_time=50, measurement_time=100).context()

# Hierarchical factory using from_components
query = SurfaceCode.q() * ExampleLogicalFactory.q(
Expand Down
14 changes: 7 additions & 7 deletions source/pip/qsharp/qre/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@

from ._application import Application
from ._architecture import Architecture
from ._estimation import (
estimate,
EstimationTable,
EstimationTableColumn,
EstimationTableEntry,
plot_estimates,
)
from ._estimation import estimate
from ._instruction import (
LOGICAL,
PHYSICAL,
Expand Down Expand Up @@ -37,6 +31,12 @@
property_name,
property_name_to_key,
)
from ._results import (
EstimationTable,
EstimationTableColumn,
EstimationTableEntry,
plot_estimates,
)
from ._trace import LatticeSurgery, PSSPC, TraceQuery, TraceTransform

# Extend Rust Python types with additional Python-side functionality
Expand Down
46 changes: 23 additions & 23 deletions source/pip/qsharp/qre/_architecture.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from ._qre import (
ISA,
_ProvenanceGraph,
_Instruction,
Instruction,
_IntFunction,
_FloatFunction,
constant_function,
Expand All @@ -25,7 +25,7 @@

class Architecture(ABC):
@abstractmethod
def provided_isa(self, ctx: _Context) -> ISA:
def provided_isa(self, ctx: ISAContext) -> ISA:
"""
Creates the ISA provided by this architecture, adding instructions
directly to the context's provenance graph.
Expand All @@ -39,12 +39,12 @@ def provided_isa(self, ctx: _Context) -> ISA:
"""
...

def context(self) -> _Context:
def context(self) -> ISAContext:
"""Create a new enumeration context for this architecture."""
return _Context(self)
return ISAContext(self)


class _Context:
class ISAContext:
"""
Context passed through enumeration, holding shared state.
"""
Expand All @@ -58,7 +58,7 @@ def __init__(self, arch: Architecture):
self._bindings: dict[str, ISA] = {}
self._transforms: dict[int, Architecture | ISATransform] = {0: arch}

def _with_binding(self, name: str, isa: ISA) -> _Context:
def _with_binding(self, name: str, isa: ISA) -> ISAContext:
"""Return a new context with an additional binding (internal use)."""
ctx = copy.copy(self)
ctx._bindings = {**self._bindings, name: isa}
Expand All @@ -71,7 +71,7 @@ def isa(self) -> ISA:

def add_instruction(
self,
id_or_instruction: int | _Instruction,
id_or_instruction: int | Instruction,
encoding: Encoding = 0, # type: ignore
*,
arity: Optional[int] = 1,
Expand All @@ -80,7 +80,7 @@ def add_instruction(
length: Optional[int | _IntFunction] = None,
error_rate: float | _FloatFunction = 0.0,
transform: ISATransform | None = None,
source: list[_Instruction] | None = None,
source: list[Instruction] | None = None,
**kwargs: int,
) -> int:
"""
Expand All @@ -93,7 +93,7 @@ def add_instruction(
ctx.add_instruction(T, encoding=LOGICAL, time=1000,
error_rate=1e-8)

2. With a pre-existing ``_Instruction`` object (e.g. from
2. With a pre-existing ``Instruction`` object (e.g. from
``with_id()``)::

ctx.add_instruction(existing_instruction)
Expand All @@ -107,26 +107,26 @@ def add_instruction(

Args:
id_or_instruction: Either an instruction ID (int) for creating
a new instruction, or an existing ``_Instruction`` object.
a new instruction, or an existing ``Instruction`` object.
encoding: The instruction encoding (0 = Physical, 1 = Logical).
Ignored when passing an existing ``_Instruction``.
Ignored when passing an existing ``Instruction``.
arity: The instruction arity. ``None`` for variable arity.
Ignored when passing an existing ``_Instruction``.
Ignored when passing an existing ``Instruction``.
time: Instruction time in ns (or ``_IntFunction`` for variable
arity). Ignored when passing an existing ``_Instruction``.
arity). Ignored when passing an existing ``Instruction``.
space: Instruction space in physical qubits (or ``_IntFunction``
for variable arity). Ignored when passing an existing
``_Instruction``.
``Instruction``.
length: Arity including ancilla qubits. Ignored when passing an
existing ``_Instruction``.
existing ``Instruction``.
error_rate: Instruction error rate (or ``_FloatFunction`` for
variable arity). Ignored when passing an existing
``_Instruction``.
``Instruction``.
transform: The ``ISATransform`` that produced the instruction.
source: List of source ``_Instruction`` objects consumed by the
source: List of source ``Instruction`` objects consumed by the
transform.
**kwargs: Additional properties (e.g. ``distance=9``). Ignored
when passing an existing ``_Instruction``.
when passing an existing ``Instruction``.

Returns:
The node index in the provenance graph.
Expand All @@ -146,7 +146,7 @@ def add_instruction(
**kwargs,
)

if isinstance(id_or_instruction, _Instruction):
if isinstance(id_or_instruction, Instruction):
instr = id_or_instruction
else:
instr = _make_instruction(
Expand Down Expand Up @@ -193,10 +193,10 @@ def _make_instruction(
length: int | _IntFunction | None,
error_rate: float | _FloatFunction,
properties: dict[str, int],
) -> _Instruction:
"""Build an ``_Instruction`` from keyword arguments."""
) -> Instruction:
"""Build an ``Instruction`` from keyword arguments."""
if arity is not None:
instr = _Instruction.fixed_arity(
instr = Instruction.fixed_arity(
id,
encoding,
arity,
Expand All @@ -215,7 +215,7 @@ def _make_instruction(
if isinstance(error_rate, (int, float)):
error_rate = constant_function(float(error_rate))

instr = _Instruction.variable_arity(
instr = Instruction.variable_arity(
id,
encoding,
time,
Expand Down
Loading
Loading