quri_parts.qsub.eval package

class AuxQubitCountEvaluatorHooks

Bases: EvaluatorHooks[int]

reset()
Return type:

None

result()
Return type:

int

enter_sub(sub, qubits, regs, call_stack)
Parameters:
Return type:

bool

exit_sub(sub, enter_sub, call_stack)
Parameters:
  • sub (MachineSub)

  • enter_sub (bool)

  • call_stack (list[qsub.machineinst.SubId])

Return type:

None

primitive(mop, qubits, regs, call_stack)
Parameters:
  • mop (Primitive)

  • qubits (Sequence[Qubit])

  • regs (Sequence[Register])

  • call_stack (list[qsub.machineinst.SubId])

Return type:

None

class CallGraphEvaluatorHooks

Bases: EvaluatorHooks[dict[Ident | None, dict[Ident, int]]]

Report the call graph of a sub.

The result maps each sub to the subs it calls directly. Each callee maps to the number of calls in one invocation of the caller. Callees appear in the order of the first call. A sub that calls no sub maps to an empty dict.

Each sub appears as the Ident of the op it implements, the same value SubwiseProfileEntry reports as source_op. Parametric subs are distinct per parameter: MCX<5> and MCX<6> are two subs. Only the entry sub of compile_sub has no op; its key is None.

reset()
Return type:

None

result()
Return type:

dict[Ident | None, dict[Ident, int]]

enter_sub(sub, qubits, regs, call_stack)
Parameters:
Return type:

bool

primitive(mop, qubits, regs, call_stack)
Parameters:
  • mop (Primitive)

  • qubits (Sequence[Qubit])

  • regs (Sequence[Register])

  • call_stack (list[qsub.machineinst.SubId])

Return type:

None

exit_sub(sub, enter_sub, call_stack)
Parameters:
  • sub (MachineSub)

  • enter_sub (bool)

  • call_stack (list[qsub.machineinst.SubId])

Return type:

None

class TotalQubitCountEvaluatorHooks

Bases: AuxQubitCountEvaluatorHooks

Evaluate the peak total qubit requirement of a machine subroutine.

class GateCountBreakdown(own, descendants, cumulative)

Bases: object

Primitive-gate counts of a sub, split by where the gates come from.

own covers the sub’s own instructions, descendants those contributed transitively by everything it calls, and cumulative their sum.

Parameters:
own: GateCounts
descendants: GateCounts
cumulative: GateCounts
class GateCountEvaluatorHooks(ops=())

Bases: EvaluatorHooks[dict[tuple[NameSpace, str], int]]

Parameters:

ops (Iterable[AbstractOp])

reset()
Return type:

None

result()
Return type:

dict[qsub.op.BaseIdent, int]

enter_sub(sub, qubits, regs, call_stack)
Parameters:
Return type:

bool

exit_sub(sub, enter_sub, call_stack)
Parameters:
  • sub (MachineSub)

  • enter_sub (bool)

  • call_stack (list[qsub.machineinst.SubId])

Return type:

None

primitive(mop, qubits, regs, call_stack)
Parameters:
  • mop (Primitive)

  • qubits (Sequence[Qubit])

  • regs (Sequence[Register])

  • call_stack (list[qsub.machineinst.SubId])

Return type:

None

class GateCounts(per_call, all_calls)

Bases: object

Primitive-gate counts of one scope.

Keys are gate Idents, op parameters included, so RZ<0.1> and RZ<0.2> are counted apart; this is finer than GateCountEvaluatorHooks, which keys by BaseIdent and merges them. per_call is for a single invocation of the sub, all_calls for all call_count of them.

Parameters:
  • per_call (Mapping[Ident, int])

  • all_calls (Mapping[Ident, int])

per_call: Mapping[Ident, int]
all_calls: Mapping[Ident, int]
class QubitCounts(data, auxiliary, total)

Bases: object

Qubits a sub occupies during one invocation.

data are the qubits the caller passes in. auxiliary are the sub’s own ancillas (its aux_qubits) plus the largest auxiliary among the subs it calls: sequential callees reuse the same ancilla space, so they contribute a maximum rather than a sum. The sub’s own ancillas stay live across those calls, so they add to that maximum.

Parameters:
  • data (int)

  • auxiliary (int)

  • total (int)

data: int
auxiliary: int
total: int
class QURIPartsEvaluatorHooks

Bases: EvaluatorHooks[QuantumCircuit]

reset()
Return type:

None

result()
Return type:

QuantumCircuit

enter_sub(sub, qubits, regs, call_stack)
Parameters:
Return type:

bool

exit_sub(sub, enter_sub, call_stack)
Parameters:
  • sub (MachineSub)

  • enter_sub (bool)

  • call_stack (list[qsub.machineinst.SubId])

Return type:

None

primitive(mop, qubits, regs, call_stack)
Parameters:
  • mop (Primitive)

  • qubits (Sequence[Qubit])

  • regs (Sequence[Register])

  • call_stack (list[qsub.machineinst.SubId])

Return type:

None

class SubwiseProfileEntry(source_op, call_count, qubit_counts, gate_counts)

Bases: object

Per-sub profiling row produced by SubwiseProfileEvaluatorHooks.

source_op identifies the op this sub implements, parameters included; use Ident.to_str() for a display name. It is None when the op is unknown (the entry sub of compile_sub, which receives a Sub rather than an Op).

Parameters:
source_op: Ident | None
call_count: int
qubit_counts: QubitCounts
gate_counts: GateCountBreakdown
class SubwiseProfileEvaluatorHooks(gates=())

Bases: EvaluatorHooks[list[SubwiseProfileEntry]]

Report, per distinct sub, how often it is called and the gate/qubit counts attributable to it.

Takes the same arguments as GateCountEvaluatorHooks: pass the ops to break down, or nothing to count every primitive. A row’s source_op carries the op parameters, so parametric subs are reported separately per parameter (MCX<5> and MCX<6> are distinct rows).

Parameters:

gates (Iterable[AbstractOp])

reset()
Return type:

None

result()
Return type:

list[SubwiseProfileEntry]

enter_sub(sub, qubits, regs, call_stack)
Parameters:
Return type:

bool

primitive(mop, qubits, regs, call_stack)
Parameters:
  • mop (Primitive)

  • qubits (Sequence[Qubit])

  • regs (Sequence[Register])

  • call_stack (list[qsub.machineinst.SubId])

Return type:

None

exit_sub(sub, enter_sub, call_stack)
Parameters:
  • sub (MachineSub)

  • enter_sub (bool)

  • call_stack (list[qsub.machineinst.SubId])

Return type:

None

Submodules