Liking cljdoc? Tell your friends :D

org.soulspace.qclojure.domain.qubit-mapping

Qubit mapping utilities for the optimization pipeline.

This namespace provides functions for creating, inverting, and composing qubit mappings throughout the optimization pipeline. These mappings are essential for tracing measurement results back to the original circuit.

Mapping Chain in Pipeline:

  1. Qubit Optimization: original-logical → compacted-logical
  2. Error Correction: compacted-logical → physical+ancillas
  3. Topology Optimization: logical → hardware-physical

Reverse Mapping Chain (for results): hardware-physical → logical → compacted-logical → original-logical

Qubit mapping utilities for the optimization pipeline.

This namespace provides functions for creating, inverting, and composing
qubit mappings throughout the optimization pipeline. These mappings are
essential for tracing measurement results back to the original circuit.

Mapping Chain in Pipeline:
1. Qubit Optimization: original-logical → compacted-logical
2. Error Correction: compacted-logical → physical+ancillas
3. Topology Optimization: logical → hardware-physical

Reverse Mapping Chain (for results):
hardware-physical → logical → compacted-logical → original-logical
raw docstring

compose-mappingsclj

(compose-mappings mapping1 mapping2)

Compose two qubit mappings sequentially.

Given mapping1: A → B and mapping2: B → C, returns composed mapping: A → C

Parameters:

  • mapping1: First mapping {A → B}
  • mapping2: Second mapping {B → C}

Returns: Composed mapping {A → C}

Example: (compose-mappings {0 10, 1 20} {10 100, 20 200}) ;=> {0 100, 1 200}

Compose two qubit mappings sequentially.

Given mapping1: A → B and mapping2: B → C,
returns composed mapping: A → C

Parameters:
- mapping1: First mapping {A → B}
- mapping2: Second mapping {B → C}

Returns:
Composed mapping {A → C}

Example:
(compose-mappings {0 10, 1 20} {10 100, 20 200})
;=> {0 100, 1 200}
sourceraw docstring

create-all-reverse-mappingsclj

(create-all-reverse-mappings ctx)

Create all reverse mappings in the context.

This is a convenience function that creates all reverse mappings from qubit optimization and error correction.

Parameters:

  • ctx: Context from optimization pipeline

Returns: Context with all reverse mappings added

Create all reverse mappings in the context.

This is a convenience function that creates all reverse mappings
from qubit optimization and error correction.

Parameters:
- ctx: Context from optimization pipeline

Returns:
Context with all reverse mappings added
sourceraw docstring

create-reverse-ec-mappingsclj

(create-reverse-ec-mappings ctx)

Create reverse mappings from error correction result.

This inverts the logical-to-physical and logical-to-ancillas mappings created by error correction, allowing tracing from physical qubits back to compacted logical qubits.

Parameters:

  • ctx: Context containing :logical-to-physical and :logical-to-ancillas

Returns: Context with added :physical-to-logical and :ancilla-to-logical

Create reverse mappings from error correction result.

This inverts the logical-to-physical and logical-to-ancillas mappings
created by error correction, allowing tracing from physical qubits back
to compacted logical qubits.

Parameters:
- ctx: Context containing :logical-to-physical and :logical-to-ancillas

Returns:
Context with added :physical-to-logical and :ancilla-to-logical
sourceraw docstring

create-reverse-qubit-mappingclj

(create-reverse-qubit-mapping ctx)

Create reverse mapping from qubit optimization result.

This inverts the qubit-mapping created by qubit optimization, allowing tracing from compacted logical qubits back to original logical qubits.

Parameters:

  • ctx: Context containing :qubit-mapping {original → compacted}

Returns: Context with added :inverse-qubit-mapping {compacted → original}

Create reverse mapping from qubit optimization result.

This inverts the qubit-mapping created by qubit optimization,
allowing tracing from compacted logical qubits back to original logical qubits.

Parameters:
- ctx: Context containing :qubit-mapping {original → compacted}

Returns:
Context with added :inverse-qubit-mapping {compacted → original}
sourceraw docstring

get-ancilla-qubits-for-logicalclj

(get-ancilla-qubits-for-logical logical-qubit ctx)

Get all ancilla qubit indices for an original logical qubit.

Parameters:

  • logical-qubit: Original logical qubit index
  • ctx: Context containing all forward mappings

Returns: Vector of ancilla qubit indices, or empty vector if not found

Get all ancilla qubit indices for an original logical qubit.

Parameters:
- logical-qubit: Original logical qubit index
- ctx: Context containing all forward mappings

Returns:
Vector of ancilla qubit indices, or empty vector if not found
sourceraw docstring

get-physical-qubits-for-logicalclj

(get-physical-qubits-for-logical logical-qubit ctx)

Get all physical qubit indices for an original logical qubit.

This composes forward mappings to find which physical qubits correspond to a logical qubit from the original circuit.

Parameters:

  • logical-qubit: Original logical qubit index
  • ctx: Context containing all forward mappings

Returns: Vector of physical qubit indices, or empty vector if not found

Example: (get-physical-qubits-for-logical 4 ctx) ;=> [6 7 8] ; physical qubits for original logical qubit 4

Get all physical qubit indices for an original logical qubit.

This composes forward mappings to find which physical qubits
correspond to a logical qubit from the original circuit.

Parameters:
- logical-qubit: Original logical qubit index
- ctx: Context containing all forward mappings

Returns:
Vector of physical qubit indices, or empty vector if not found

Example:
(get-physical-qubits-for-logical 4 ctx)
;=> [6 7 8]  ; physical qubits for original logical qubit 4
sourceraw docstring

invert-simple-mappingclj

(invert-simple-mapping mapping)

Invert a simple one-to-one qubit mapping.

Parameters:

  • mapping: Map from source qubits to target qubits {source → target}

Returns: Inverted mapping {target → source}

Example: (invert-simple-mapping {0 0, 2 1, 4 2}) ;=> {0 0, 1 2, 2 4}

Invert a simple one-to-one qubit mapping.

Parameters:
- mapping: Map from source qubits to target qubits {source → target}

Returns:
Inverted mapping {target → source}

Example:
(invert-simple-mapping {0 0, 2 1, 4 2})
;=> {0 0, 1 2, 2 4}
sourceraw docstring

invert-vector-mappingclj

(invert-vector-mapping vector-mapping)

Invert a one-to-many mapping (logical to physical/ancilla).

Parameters:

  • vector-mapping: Map from logical qubits to qubit vectors {log → [phys...]}

Returns: Inverted mapping {phys → log}

Example: (invert-vector-mapping {0 [0 1 2], 1 [3 4 5]}) ;=> {0 0, 1 0, 2 0, 3 1, 4 1, 5 1}

Invert a one-to-many mapping (logical to physical/ancilla).

Parameters:
- vector-mapping: Map from logical qubits to qubit vectors {log → [phys...]}

Returns:
Inverted mapping {phys → log}

Example:
(invert-vector-mapping {0 [0 1 2], 1 [3 4 5]})
;=> {0 0, 1 0, 2 0, 3 1, 4 1, 5 1}
sourceraw docstring

map-measurements-to-originalclj

(map-measurements-to-original measurements ctx)

Map all measurement results back to original logical qubits.

Parameters:

  • measurements: Map of qubit measurements {qubit-id → value}
  • ctx: Context containing all reverse mappings

Returns: Map of measurements mapped to original logical qubits

Example: (map-measurements-to-original {0 1, 1 0, 7 1} ctx) ;=> {0 1, 2 0, 4 1} ; mapped to original qubits

Map all measurement results back to original logical qubits.

Parameters:
- measurements: Map of qubit measurements {qubit-id → value}
- ctx: Context containing all reverse mappings

Returns:
Map of measurements mapped to original logical qubits

Example:
(map-measurements-to-original {0 1, 1 0, 7 1} ctx)
;=> {0 1, 2 0, 4 1}  ; mapped to original qubits
sourceraw docstring

map-qubit-to-originalclj

(map-qubit-to-original qubit-id ctx)

Map a final qubit index back to original logical qubit.

This composes the full reverse mapping chain: final-qubit → logical → compacted → original

Parameters:

  • qubit-id: Final qubit index from optimized circuit
  • ctx: Context containing all reverse mappings

Returns: Original logical qubit index, or nil if not mappable

Example: Given mappings: physical-to-logical {7 2}, inverse-qubit-mapping {2 4} (map-qubit-to-original 7 ctx) ;=> 4

Map a final qubit index back to original logical qubit.

This composes the full reverse mapping chain:
final-qubit → logical → compacted → original

Parameters:
- qubit-id: Final qubit index from optimized circuit
- ctx: Context containing all reverse mappings

Returns:
Original logical qubit index, or nil if not mappable

Example:
Given mappings: physical-to-logical {7 2}, inverse-qubit-mapping {2 4}
(map-qubit-to-original 7 ctx) ;=> 4
sourceraw docstring

summarize-mappingsclj

(summarize-mappings ctx)

Create a human-readable summary of all mappings in the context.

Parameters:

  • ctx: Context from optimization pipeline

Returns: String with formatted mapping information

Create a human-readable summary of all mappings in the context.

Parameters:
- ctx: Context from optimization pipeline

Returns:
String with formatted mapping information
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close