qcp.cli package

Submodules

qcp.cli.constants module

qcp.cli.constants.ALGORITHM_LONG = '--algorithm'

The long flag for the algorithm choice

qcp.cli.constants.ALGORITHM_SHORT = '-a'

The short flag for the algorithm choice

qcp.cli.constants.DEFAULT_ALGORITHM = 'g'

The default algorithm type to simulate

qcp.cli.constants.DEFAULT_EIGENVECTOR_IDX = 0

The index of the default eigenvector to use:

qcp.cli.constants.DEFAULT_PHASE = 0.25

The default phase to use in the unitary matrix, if required

qcp.cli.constants.DEFAULT_TARGET = 0

The default target state the Oracle will search for

qcp.cli.constants.DEFAULT_UNITARY = 'hadamard'

The default unitary matrix type to use.

qcp.cli.constants.EIGENVECTOR_LONG = '--eigen'

The long flag for the eigenvector choice

qcp.cli.constants.EIGENVECTOR_SHORT = '-e'

The short flag for the eigenvector choice

qcp.cli.constants.FLAG_MAPPING = {'-a': '--algorithm', '-e': '--eigen', '-g': '--gui', '-h': '--help', '-p': '--phase', '-t': '--target', '-u': '--unitary'}

All the flags accepted by the CLI, mapping their short name to the more verbose one

qcp.cli.constants.GUI_LONG = '--gui'

The long flag for the GUI initialiser

qcp.cli.constants.GUI_SHORT = '-g'

The short flag the GUI initialiser

qcp.cli.constants.HELP_LONG = '--help'

The long flag for the help message

qcp.cli.constants.HELP_SHORT = '-h'

The short flag for the help message

qcp.cli.constants.PHASE_LONG = '--phase'

The long flag for the phase value

qcp.cli.constants.PHASE_SHORT = '-p'

The short flag for the phase value

qcp.cli.constants.TARGET_LONG = '--target'

The long flag for the target

qcp.cli.constants.TARGET_SHORT = '-t'

The short flag for the target

qcp.cli.constants.UNITARY_LONG = '--unitary'

The long flag for the unitary matrix choice

qcp.cli.constants.UNITARY_SHORT = '-u'

The short flag for the unitary matrix choice

qcp.cli.interpret module

Convert the given CLI arguments and flags into usable input for the algorithms

qcp.cli.interpret._determine_qbits(args: List[str]) int[source]

Read the number of qbits to simulate from the CLI arguments list

Parameters

args (List[str]) – The CLI arguments

Returns

The number of qbits

Return type

int

qcp.cli.interpret.determine_grover(args: List[str], flags: Dict[str, str]) Tuple[int, int][source]

Read the given flags dictionary and arguments map and convert to usable input for the Grover’s algorithm.

The Grover’s Algorithm needs two input. The first is the number of qbits to simulate, and the second is the target state to search for.

Parameters
  • args (List[str]) – The CLI arguments

  • flags (Dict[str,str]) – The CLI flags

Returns

Tuple of the parameters for the constructor, the

first is the number of qbits, the second the target bit.

Return type

Tuple[int, int]

qcp.cli.interpret.determine_phase_estimation(args: List[str], flags: Dict[str, str]) Tuple[int, qcp.matrices.matrix.Matrix, qcp.matrices.matrix.Matrix][source]

Read the given flags dictionary and arguments map and convert to usable input for the PhaseEstimation algorithm.

The PhaseEstimation algorithm needs the number of qbits to simulate, and two matrices. The first to use as the unitary matrix in the algorithm and the second to use as the eigenvector.

Parameters
  • args (List[str]) – The CLI arguments

  • flags (Dict[str,str]) – The CLI flags

Returns

Tuple of the parameters for the

constructor, the first is the number of qbits to simulate, the second the Unitary Matrix to use, and the third the eigenvector.

Return type

Tuple[int, Matrix, Matrix]

qcp.cli.interpret.determine_sudoku(args: List[str], flags: Dict[str, str])[source]

Read the given flags dictionary and arguments map and convert to usable input for the Sudoku algorithm.

The sudoku algorithm takes no input…

Parameters
  • args (List[str]) – The CLI arguments

  • flags (Dict[str,str]) – The CLI flags

qcp.cli.interpret.interpret_arguments(opt: qcp.cli.options.AlgorithmOption, args: List[str], flags: Dict[str, str])[source]

Parse the CLI arguments/flags based off of the algorithm type to simulate

Parameters
  • opt (AlgorithmOption) – The algorithm chosen

  • List[str] – The CLI arguments provided

  • str] (Dict[str,) – The CLI flags provided

qcp.cli.options module

Defines the enums that encode the CLI option values

class qcp.cli.options.AlgorithmOption(value)[source]

Bases: enum.Enum

Enum of the different algorithms to simulate

Grovers = 'g'
PhaseEstimation = 'pe'
Sudoku = 's'
get_constructor()[source]

Return the constructor that matches the enum

get_name()[source]

Return a string name of the Algorithm

Returns

The Algorithm display name.

Return type

str

classmethod list() List[str][source]

Return all the enum options’ values

Returns

All the strings the enums correspond to

Return type

List[str]

qcp.cli.parser module

Code to parse CLI options for the Algorithm, to determing the flags and arguments given

qcp.cli.parser.parse_input(args: List[str]) Tuple[Dict[str, str], List[str]][source]

Convert the given list of cli arguments into a mapping between the CLI flags and their value, and a list or CLI arguments

Parameters

args (List[str]) – The CLI arguments

Returns

A tuple of the flags dictionary

and the arguments list.

Return type

Tuple[Dict[str, str], List[str]]

qcp.cli.parser.read_cli(args: List[str])[source]

Parses the sys.argv CLI options to read the value for the optional flags (if provided), and the required CLI arguments.

Parameters

args (List[str]) – The list of CLI inputs from sys.argv

Returns

py:obj:qcp.cli.constants.AlgorithmOptions, Any…]: The CLI

values, firstly the algorithm chosen to run, and then a tuple of the parameters required to run that algorithm.

Return type

Tuple[~

qcp.cli.progress_bar module

File containing the code to add an animated progress bar

qcp.cli.progress_bar._ticks = ['-', '\\', '|', '/']

List of the ASCII art tickers

qcp.cli.progress_bar.ticker(tick_rate=0.2, prefix='', file=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>)[source]

Shows a swirling ticker on the terminal to indicate that an operation is in progress.

Parameters
  • tick_rate (float) – The interval to sleep between refreshes in seconds.

  • file (TextIO) – Override for the default I/O printed to.

Parma str prefix

An optional prefix to show before the ticker.

qcp.cli.usage module

CLI help messages live here

qcp.cli.usage.USAGE_STR = "USAGE:\n/opt/hostedtoolcache/Python/3.10.2/x64/bin/sphinx-build [FLAGS] nqbits\nFLAGS:\n    -a/--algorithm  The quantum algorithm to simulate, can be one of:\n                        g   = Grover's Algorithm\n                        pe  = Phase Estimation\n                        s   = Toy Sudoku solver\n                    Defaults to 'g' if unset\n    -h/--help       Display this prompt\n    -g/--gui        Display the GUI (if supported).\n\nThe CLI options vary by choice of algorithm:\n\nGROVERS:\n    USAGE:\n    /opt/hostedtoolcache/Python/3.10.2/x64/bin/sphinx-build --algorithm g [FLAGS] nqbits\n    ARGS:\n        nqbits          The number of qbit states to simulate, must be >= 2.\n    FLAGS:\n        -t/--target     The target state, defaults to 0\n\nPHASE ESTIMATION:\n    USAGE:\n    /opt/hostedtoolcache/Python/3.10.2/x64/bin/sphinx-build --algorithm pe [FLAGS] nqbits\n    ARGS:\n        nqbits          The number of qbit states to simulate, must be >= 2.\n    FLAGS:\n        -p/--phase      The phase to use for the Phase Shift Gate (if using).\n                        defaults to 0.25.\n        -u/--unitary    The choice of unitary gate to simulate with, can be\n                        one of the following:\n                            * hadamard = Hadamard Gate\n                            * phase_shift = Phase Shift Gate (requires the -p flag)\n                        Defaults to 'hadamard' if unset\n        -e/--eigen      The choice of eigenvector to use in the simulation.\n                        If using the HADAMARD gate, can be one of:\n                            * +\n                            * -\n                            Default is +\n                        If using the PHASE SHIFT gate, can be one of:\n                            * 0\n                            * 1\n                            Default is 0\nSUDOKU:\n    USAGE:\n    /opt/hostedtoolcache/Python/3.10.2/x64/bin/sphinx-build --algorithm s\n    ARGS:\n        None\n    FLAGS:\n        None"

The CLI help text

qcp.cli.usage.usage()[source]

Prints the help text to stdout, and exits with error code 0.

Module contents