B2QSynthesis

class B2QSynthesis(config=None)

Bases: GenericPass[DAGCircuit, DAGCircuit]

A transpilation pass to map boson-based circuit instructions to qubit-based ones.

This transpilation pass works similarly to Qiskit’s HighLevelSynthesis pass; given an input BosonicDAGCircuit, it iterates the contained instructions and delegates the translation to qubit-based instructions to matching methods. The insertion of the qubit-based circuit instructions into the output DAGCircuit is also left to the plugin method. This pass will merely have prepared the QuantumRegister according to the global transpilation B2QLayout setting.

Usage

There are two ways to configure the plugins used by this transpiler pass. The examples below show the equivalent configuration to the generate_preset_occupation_pass_manager().

  1. Providing a config during initialization:

    >>> from qiskit_bosons.mappers import LevelSpec
    >>> from qiskit_bosons.mappers.library import occupation_encoding
    >>> from qiskit_bosons.transpiler import passes
    >>>
    >>> # The encoding and the truncation are bound here, at transpile time -- the bosonic
    >>> # circuit upstream of this pass is independent of both.
    >>> spec = LevelSpec(2, "unary_projected")
    >>> def mapper_fn(operator, num_qubits):
    ...     return occupation_encoding(operator, spec, num_qubits)
    >>> config = {
    ...     "Evolution": ("MapperFn", (mapper_fn,)),
    ...     "InitializeModes": ("Occupation", (spec,)),
    ... }
    >>> synth = passes.B2QSynthesis(config)
    
  2. Manually populating the methods attribute:

    >>> from qiskit_bosons.transpiler import passes
    >>>
    >>> synth = passes.B2QSynthesis()
    >>> synth.methods["Evolution"] = passes.MapperFnEvolutionSynthesis(mapper_fn)
    >>> synth.methods["InitializeModes"] = (
    ...     passes.OccupationInitializeModesSynthesis(spec)
    ... )
    

    Through this manual approach it is also possible to inject custom B2QSynthesisPlugin implementations without requiring them to be registered through an entry-point.

Initializing this transpiler pass can be done with the arguments listed below.

Parameters:

config (B2QSynthesisConfig | None) – an optional dictionary to pre-populate the methods with plugins provided by the B2QSynthesisPluginManager, or with plugin instances. See B2QSynthesisConfig.

Raises:
  • KeyError – if config names an instruction or a method for which no plugin is installed.

  • TypeError – if config gives a value that is none of the forms of B2QSynthesisConfig.

Attributes

methods: dict[str, B2QSynthesisPlugin]

A dictionary of boson-to-qubit circuit instruction transpilation methods.

For this transpilation pass to have any effect, this dictionary must be populated with instances of the B2QSynthesisPlugin protocol. The keys of this dictionary correspond to the __name__ of a circuit instruction.

All available transpilation plugins are managed by the B2QSynthesisPluginManager.

Note

This dictionary is empty by default! You can pre-populate it with plugins provided by the B2QSynthesisPluginManager by providing a config argument during initialization of this transpiler pass instance.

Methods

run(dag)

Runs this transpilation pass.

Parameters:

dag (DAGCircuit) – the input circuit with boson-based instructions. Only DAGOpNode with BosonicGate instances as their op are supported, plus Barrier, which is mapped onto every qubit of each register it touched.

Returns:

The output circuit with qubit-based instructions.

Raises:
Return type:

DAGCircuit

Inherited Methods

execute(passmanager_ir, state, callback=None)

Execute optimization task for input Qiskit IR.

Parameters:
  • passmanager_ir (IR) – Qiskit IR to optimize.

  • state (PassManagerState) – State associated with workflow execution by the pass manager itself.

  • callback (Callable[[Task, IR_OUT, PropertySet, float, int], None] | None) – A callback function which is called per execution of optimization task.

Returns:

Optimized Qiskit IR and state of the workflow.

Return type:

tuple[IR_OUT, PassManagerState]

name()

Name of the pass.

Return type:

str

update_status(state, run_state)

Update workflow status.

Parameters:
  • state (PassManagerState) – Pass manager state to update.

  • run_state (RunState) – Completion status of current task.

Returns:

Updated pass manager state.

Return type:

PassManagerState