qxmt.ansatze.base module#
- class qxmt.ansatze.base.BaseAnsatz(device)
Bases:
ABC
Base class for quantum circuit ansatzes.
This abstract base class defines the interface for quantum circuit ansatzes. It provides common functionality for circuit visualization and execution.
- Parameters:
device (BaseDevice) – Quantum device to use for the ansatz.
Note
Subclasses must implement the circuit method to define the quantum circuit.
- abstractmethod circuit(*args, **kwargs)
Define the quantum circuit for the ansatz.
This method must be implemented by subclasses to define the quantum circuit structure and operations.
- Parameters:
*args – Variable length argument list.
**kwargs – Arbitrary keyword arguments.
- Return type:
None
Note
The implementation should define the quantum circuit using the device’s operations.
- draw(params, format='default', logger=<Logger qxmt.ansatze.base (INFO)>, **kwargs)
Draw the quantum circuit using the platform’s draw function.
This method visualizes the quantum circuit in either text or graphical format.
- Parameters:
params (ndarray) – Parameters for the circuit.
format (str) – Format of the drawing. Choose between “default” (text) or “mpl” (matplotlib). Defaults to “default”.
logger (Logger) – Logger object for output. Defaults to module-level logger.
**kwargs (Any) – Additional arguments for the drawing function.
- Raises:
NotImplementedError – If the platform is not supported.
ValueError – If the format is invalid.
- Return type:
None
Note
For matplotlib format, the figure will be displayed using plt.show().
- class qxmt.ansatze.base.BaseVQEAnsatz(device, hamiltonian)
Bases:
BaseAnsatz
Base class for Variational Quantum Eigensolver (VQE) ansatzes.
This abstract base class extends BaseAnsatz to provide functionality specific to VQE calculations, including Hamiltonian validation and expectation value measurement.
- Parameters:
device (BaseDevice) – Quantum device to use for the ansatz.
hamiltonian (BaseHamiltonian) – Hamiltonian to use for the VQE calculation.
Note
Subclasses must implement the circuit method to define the variational circuit.
- abstractmethod circuit(params)
Define the variational circuit for the VQE ansatz.
This method must be implemented by subclasses to define the variational circuit.
- Parameters:
params (ndarray) – Parameters for the variational circuit.
- Return type:
None
Note
The implementation should define a parameterized quantum circuit that can be optimized to find the ground state of the Hamiltonian.