waves_dynamic

I made this just for fun (X) to understand some techniques that used in the implementation of :class:~typing.NamedTuple as known as :class:~collections.namedtuple.

:class:~qurry.qurrium.container.waves_dynamic.wave_container_maker is not implemented. We use :class:~qurry.qurrium.container.waves_static.WaveContainer instead.

Dynamic Wave Container - A experimental feature of Qurry (qurry.qurrium.container.waves_dynamic)

qurry.qurrium.container.waves_dynamic.DyanmicWaveContainerByDict

A Qurrium standard wave function container should be something dict-like structure, basically a typing.MutableMapping.

qurry.qurrium.container.waves_dynamic.add(self: MutableMapping[Hashable, QuantumCircuit], wave: QuantumCircuit, key: Hashable | None = None, replace: Literal[True, False, 'duplicate'] = True) Hashable[source]

Add new wave function to measure.

Parameters:
  • wave (QuantumCircuit) – The wave function or circuit to add.

  • key (Optional[Hashable], optional) – Given a specific key to add to the wave function or circuit, if key == None, then generate a number as key. Defaults to None.

  • replace (Literal[True, False, 'duplicate'], optional) – If the key is already in the wave function or circuit, then replace the old wave function or circuit when True, or duplicate the wave function or circuit when ‘duplicate’. Defaults to True.

Returns:

Key of given wave function in .waves.

Return type:

Optional[Hashable]

qurry.qurrium.container.waves_dynamic.call(self, wave: list[Hashable]) list[QuantumCircuit][source]
qurry.qurrium.container.waves_dynamic.call(self, wave: Hashable) QuantumCircuit

Export wave function as QuantumCircuit.

Parameters:

wave (Union[list[Hashable], Hashable]) – The key of wave in ‘dict’ .waves.

Returns:

The circuit of wave function.

Return type:

Union[list[QuantumCircuit], QuantumCircuit]

qurry.qurrium.container.waves_dynamic.copy_circuit(self, wave: list[Hashable] | Hashable) list[QuantumCircuit] | QuantumCircuit[source]

Export a copy of wave function as QuantumCircuit.

Parameters:

wave (Union[list[Hashable], Hashable]) – The key of wave in ‘dict’ .waves.

Returns:

The copy circuit of wave function.

Return type:

Union[list[QuantumCircuit], QuantumCircuit]

qurry.qurrium.container.waves_dynamic.gate(self, wave: list[Hashable] | Hashable) list[Gate] | Gate[source]

Export wave function as Gate.

Parameters:

wave (Union[list[Hashable], Hashable]) – The key of wave in ‘dict’ .waves.

Returns:

The gate of wave function.

Return type:

Union[list[Gate], Gate]

qurry.qurrium.container.waves_dynamic.get_wave(self, wave: list[Hashable], run_by: Literal['copy', 'call'] | None) list[QuantumCircuit][source]
qurry.qurrium.container.waves_dynamic.get_wave(self, wave: list[Hashable], run_by: Literal['gate']) list[Gate]
qurry.qurrium.container.waves_dynamic.get_wave(self, wave: list[Hashable], run_by: Literal['operator']) list[Operator]
qurry.qurrium.container.waves_dynamic.get_wave(self, wave: list[Hashable], run_by: Literal['instruction']) list[Instruction]
qurry.qurrium.container.waves_dynamic.get_wave(self, wave: Hashable, run_by: Literal['copy', 'call'] | None) QuantumCircuit
qurry.qurrium.container.waves_dynamic.get_wave(self, wave: Hashable, run_by: Literal['gate']) Gate
qurry.qurrium.container.waves_dynamic.get_wave(self, wave: Hashable, run_by: Literal['operator']) Operator
qurry.qurrium.container.waves_dynamic.get_wave(self, wave: Hashable, run_by: Literal['instruction']) Instruction

Parse wave Circuit into Instruction as Gate or Operator on QuantumCircuit.

Parameters:
  • wave (Optional[Hashable], optional) – The key of wave in ‘fict’ .waves. Defaults to None.

  • run_by (Optional[str], optional) – Export as Gate, Operator, Instruction or a copy when input is None. Defaults to None.

Raises:
Returns:

Union[

list[Union[Gate, Operator, Instruction, QuantumCircuit]], Union[Gate, Operator, Instruction, QuantumCircuit]

]: The result of the wave as Gate or Operator.

qurry.qurrium.container.waves_dynamic.has(self, wavename: Hashable) bool[source]

Is there a wave with specific name.

Parameters:

wavename (Hashable) – Name of wave which is used in .waves

Returns:

Exist or not.

Return type:

bool

qurry.qurrium.container.waves_dynamic.instruction(self, wave: list[Hashable] | Hashable) list[Instruction] | Instruction[source]

Export wave function as Instruction.

Parameters:

wave (Union[list[Hashable], Hashable]) – The key of wave in ‘dict’ .waves.

Returns:

The instruction of wave function.

Return type:

Union[list[Instruction], Instruction]

qurry.qurrium.container.waves_dynamic.operator(self, wave: list[Hashable] | Hashable) list[Operator] | Operator[source]

Export wave function as Operator.

Parameters:

wave (Union[list[Hashable], Hashable]) – The key of wave in ‘dict’ .waves.

Returns:

The operator of wave function.

Return type:

Union[list[Operator], Operator]

qurry.qurrium.container.waves_dynamic.process(self, circuits: list[QuantumCircuit | Hashable]) list[tuple[Hashable, QuantumCircuit]][source]

Process the circuits for Qurrium.

Parameters:

circuits (list[Union[QuantumCircuit, Hashable]]) – The circuits.

Raises:
  • KeyError – If the wave not found in the container.

  • ValueError – If the circuit is invalid.

qurry.qurrium.container.waves_dynamic.remove(self, key: Hashable)[source]

Remove wave function from measure.

Parameters:

key (Hashable) – The key of wave function or circuit.

qurry.qurrium.container.waves_dynamic.wave_container_maker(typename: str = 'WaveContainer', base_type: ~typing.Type[~typing.MutableMapping[~collections.abc.Hashable, ~qiskit.circuit.quantumcircuit.QuantumCircuit]] = <class 'dict'>) Type[MutableMapping][source]

A customized dictionary for storing waves.

Parameters:
  • typename (str, optional) – The name of the new type. Defaults to “WaveContainer”.

  • base_type (Type[MutableMapping[Hashable, QuantumCircuit]], optional) – The base type of the new type. Defaults to dict.

Returns:

The new type of wave container.

Return type:

Type[MutableMapping]