Hi @neiljdo Added a new custom method to the BaseAnsatz class called custom, which implements BaseAnsatz.custom function, where anything can go inside that custom function, even custom gate definitions. I still think there needs to be modifications in this implementation, so far I modified the following:
class BasenAnsatz: To add a custom function for creating and using custom quantum gates within the BaseAnsatz class, which can then be utilized by any subclass such as CircuitAnsatz, you would define a method in BaseAnsatz for handling the custom gate logic. This method would ideally accept parameters for the gate's unitary matrix and the qubits it acts upon. Subclasses can then leverage this method to incorporate custom gates into their circuits.
Note: The code aims to provide a flexible framework for defining and applying custom quantum gates within quantum circuits. By allowing the user to specify a unitary matrix, any conceivable quantum operation can be implemented, provided it adheres to the unitary constraint.
class CircuitAnsatz: When defining specific ansatzes in subclasses, we can now utilize the add_custom_gate method to include custom gates as part of the circuit construction.
class CustomGate: To complete the integration of custom gates within the Diagram class, we need to implement the logic for inserting a CustomGate into the diagram's structure. This involves creating a new layer or incorporating the custom gate into an existing layer.
class Diagram / Diagram Structure: The implementation appends the custom gate as a new layer at the end of the diagram. Depending on the needs, we might want to insert the custom gate at a specific position or merge it with existing layers.
def create_layer_for_custom_gate:
Dynamic Layer Composition: This method dynamically constructs a new layer, considering the qubits the custom gate acts upon. It initializes the layer with identity operations (Id(qubit)) for all qubits and then replaces the relevant positions with the custom gate.
Handling of left and right Types: The left type is determined based on the diagram's existing structure, while the right type is adjusted to accommodate the maximum qubit index involved with the custom gate. This ensures the layer fits seamlessly into the diagram.
Layer Insertion: The new layer is appended to the end of the diagram. For more complex scenarios, such as inserting the layer at a specific position or integrating it with existing layers, additional logic would be required.
I still think there needs to be some kind of modifications to this implementation, this could also be seen as a proof of a method. But any kind of review would be a great help!
Hi @neiljdo Added a new custom method to the
BaseAnsatz
class called custom, which implementsBaseAnsatz.custom
function, where anything can go inside that custom function, even custom gate definitions. I still think there needs to be modifications in this implementation, so far I modified the following:class BasenAnsatz
: To add a custom function for creating and using custom quantum gates within theBaseAnsatz
class, which can then be utilized by any subclass such asCircuitAnsatz
, you would define a method inBaseAnsatz
for handling the custom gate logic. This method would ideally accept parameters for the gate's unitary matrix and the qubits it acts upon. Subclasses can then leverage this method to incorporate custom gates into their circuits.CircuitAnsatz
: When defining specific ansatzes in subclasses, we can now utilize theadd_custom_gate
method to include custom gates as part of the circuit construction.CustomGate
: To complete the integration of custom gates within the Diagram class, we need to implement the logic for inserting aCustomGate
into the diagram's structure. This involves creating a new layer or incorporating the custom gate into an existing layer.def create_layer_for_custom_gate
:Dynamic Layer Composition: This method dynamically constructs a new layer, considering the qubits the custom gate acts upon. It initializes the layer with identity operations (Id(qubit)) for all qubits and then replaces the relevant positions with the custom gate.
Handling of left and right Types: The left type is determined based on the diagram's existing structure, while the right type is adjusted to accommodate the maximum qubit index involved with the custom gate. This ensures the layer fits seamlessly into the diagram.
Layer Insertion: The new layer is appended to the end of the diagram. For more complex scenarios, such as inserting the layer at a specific position or integrating it with existing layers, additional logic would be required.
I still think there needs to be some kind of modifications to this implementation, this could also be seen as a proof of a method. But any kind of review would be a great help!