Closed alexandrupaler closed 5 years ago
There is no such thing at the moment.
However, if you are using Python 3.3 or higher, one way you could have something similar would be to use implicit Python namespaces.
https://setuptools.readthedocs.io/en/latest/setuptools.html#find-namespace-packages
Thank you. In order to implement a kind of extension system, in ProjQUBE I used a higher namespace that includes a replica of the projectq namespace (e.g. projqube.projectq.cengines
)
Using this higher namespace approach, I managed to have engines and decompositions interact almost seamless with ProjectQ.
It was a bit more difficult to understand how to automatically include our gate decompositions . We solved that in https://github.com/quantumresource/projqube/blob/4d3957f1df4cac98c4b8774571f32d3761af8d7a/projqube/projectq/setups/surface_codes/lattice_surgery.py#L11 where the AutoReplacer from restrictedgateset is changed
Would this semi-plugin (extension) system be somehow officially supported by ProjectQ? I mean having some kind of setup_extension.py file that includes a method to reconfigure the entire ProjectQ framework with gate decompositions and other global stuff.
PS: the above comment is mine
Given that you only want to add compiler engines and decompositions (possibly alter the default list of decompositions), I do not think that we would need to implement a plugin system into ProjectQ (see my comments at the end of this post).
That being said, if there is traction in the community for such a feature, we are always open for discussion and would then look into implementing a plugin system.
It was a bit more difficult to understand how to automatically include our gate decompositions . We solved that in https://github.com/quantumresource/projqube/blob/4d3957f1df4cac98c4b8774571f32d3761af8d7a/projqube/projectq/setups/surface_codes/lattice_surgery.py#L11 where the AutoReplacer from restrictedgateset is changed
This is a bit hacky but would work: you actually just need to redefine the projectq.setups.restrictedgateset.get_engine_list
which is fairly easy in python:
import projectq.setups.restrictedgateset
def get_engine_list(one_qubit_gates="any",
two_qubit_gates=(CNOT,),
other_gates=()):
# Do what you want
projectq.setups.restrictedgateset.get_engine_list = get_engine_list
You would then need to make sure that users load your package first (ie. before projectq
) so that you can make this replacement transparently for the user. One other possible solution, would be an extension of my comment below: you would provide a proxy class for MainEngine
and then within the constructor you could detect the restricted gate set and make the changes there.
Would this semi-plugin (extension) system be somehow officially supported by ProjectQ? I mean having some kind of setup_extension.py file that includes a method to reconfigure the entire ProjectQ framework with gate decompositions and other global stuff.
For gate decompositions, you could simply provide a get_engine_list
function and have users do something like:
eng = MainEngine(engine_list = projqube.setups.default.get_engine_list())
or if that is too much of a mouthful to write, you could define a new proxy class MainEngine
in in the projqube module with the correct defaults.
Thank you.
Is it possible to develop code for ProjectQ as a plugin? Meaning that the new code should not be pushed to the main repo, but all the separate files be integrated in the different folders? Are there examples in this direction?