quantum_launcher.base.adapter_structure#

Summary#

Classes:

ProblemFormatter

Converts input problem to a given format (input and output types determined by formatter and adapters in __init__)

Functions:

adapter

Register a function as an adapter from one problem format to another.

default_formatter

formatter

Register a function as a formatter for a given problem type to a given format.

get_formatter

Creates a ProblemFormatter that converts a given Problem subclass into the requested format.

Reference#

class quantum_launcher.base.adapter_structure.ProblemFormatter(formatter: Callable, adapters: list[Callable] | None = None)[source]#

Bases: object

Converts input problem to a given format (input and output types determined by formatter and adapters in __init__)

Probably shouldn’t be constructed directly, call get_formatter()

get_pipeline() str[source]#
Returns:

problem -> formatter -> adapters (if applicable)

Return type:

String representing the conversion process

set_run_param(param: str, value: Any) None[source]#

Sets a parameter to be used during next conversion.

Parameters:
  • param (str) – parameter key

  • value (str) – parameter value

set_run_params(params: dict[str, Any]) None[source]#

Sets multiple parameters to be used during next conversion.

Parameters:

params (dict[str, Any]) – parameters to be set

quantum_launcher.base.adapter_structure.adapter(translates_from: str, translates_to: str, **kwargs) Callable[source]#

Register a function as an adapter from one problem format to another.

Parameters:
  • translates_from (str) – Input format

  • translates_to (str) – Output format

Returns:

Same function

Return type:

Callable

quantum_launcher.base.adapter_structure.formatter(problem: type[Problem] | None, alg_format: str)[source]#

Register a function as a formatter for a given problem type to a given format.

Parameters:
  • problem (type[Problem]) – Input problem type

  • alg_format (str) – Output format

Returns:

Same function

quantum_launcher.base.adapter_structure.get_formatter(problem: type[Problem], alg_format: str) ProblemFormatter[source]#

Creates a ProblemFormatter that converts a given Problem subclass into the requested format.

Parameters:
  • problem (type[Problem]) – Input problem type

  • alg_format (str) – Desired output format

Returns:

ProblemFormatter meeting the desired criteria.

Raises:

ValueError – If no combination of adapters can achieve conversion from problem to desired format.

Return type:

ProblemFormatter

quantum_launcher.base.adapter_structure.default_formatter(problem: Problem)[source]#