Comments (9)
It is true that empty_circuit = input_circuit[0:0]
doesn't copy num_shots
. But I also noticed that circuit_sum= input_circuit + input_circuit
doesn't copy num_shots
to circuit_sum
!
So I wonder if this is a bug or a feature.
An empty circuit in PyQuil can be correctly created in this way
empty_circuit = input_circuit.copy_everything_except_instructions()
however, even in this case, num_shots
would be lost as soon as we start making simple operations (e.g., additions).
from mitiq.
I think it's a good point. Moreover the same problem probably exists also for PyQuil circuits (e.g. num_shots
can be a property of a circuit).
I agree with your solution, otherwise a simple alternative is also this one:
empty_circuit = input_circuit[0:0]
which creates an empty circuit with the same properties of the input and should work for both Cirq and PyQuil circuits.
from mitiq.
Good point about pyQuil circuits and properties.
I tested
empty_circuit = input_circuit[0:0]
and it didn't copy over the shots.
I'll update the name of this issue to reflect the importance for pyQuil as well.
from mitiq.
I will make a PR (#11 ) to improve the creation of empty circuits in PyQuil using copy_everything_except_instructions()
. I am also adding some tests associated to this issue.
The problem with num_shots
and similar properties remains. But I am quite sure that this is a bug of PyQuil. See, e.g., the __add__
and __getitem__
method of the Program
class where it is evident that properties are not retained (https://github.com/rigetti/pyquil/blob/master/pyquil/quil.py).
from mitiq.
@andreamari does the issue appear specific to num_shots instructions? If so, perhaps dedicated code should exist to pop off this instruction?
Alternatively, we could code for with the assumption that the user does not choose numshots for things to be mitigated. When you run a given Program through mitigation it isn't clear what the numshots should do as the Mitigator will have discretion to choose optimal amounts of shots to take etc
from mitiq.
Of the two approaches I just suggested. I think I prefer stripping num_shots from an input program and emitting a warning to the user that it is being ignored.
from mitiq.
It is not just self.num_shots
, there are also other properties like: self._defined_gates
and self.native_quil_metadata
, which are lost when using the +
operator or slicing a circuit [ ]
.
I think I got what is the solution: one should only append instructions (or circuit slices) with the inst
method or equivalently with +=
. In this way all the properties of the input circuit are preserved. In other words: a = a + b
is bad, while a += b
should correctly preserve the properties of a
.
from mitiq.
ah gotcha. This is an unexpected idiosyncrasy indeed. Does that mean that replacing all a=a+b
with a+=b
will fix the issue? If so, it is likely time for a pull request :)
from mitiq.
This issue is now solved by #11 .
from mitiq.
Related Issues (20)
- Add Python 3.12 support
- Numpy 2.0 will have breaking changes HOT 3
- Warning raised during docs build HOT 3
- Add a linter for `docs/` HOT 5
- Add information about converting to and from non-Mitiq supported circuits HOT 2
- Make LRE compatible with non-cirq circuits
- Broken Qiskit logo in the readme HOT 1
- Include Discussions on README.md
- API-doc has run-on sentences HOT 2
- Flaky test in `rem/tests/test_inverse_confusion_matrix.py` HOT 7
- Complete «Apply PT» section in Pauli Twirling user guide HOT 1
- update to latest Changelog version HOT 1
- Create two-stage API for ZNE HOT 5
- Flaky test in `mitiq/zne/tests/test_zne.py` HOT 1
- Add functionality to generate confusion matrix on backend
- REM functionality dependent on typehinting
- Failure in `mitiq/zne/tests/test_inference.py::test_plot_data[PolyFactory]` HOT 1
- `add_noise_to_two_qubit_gates` functionality is limited HOT 1
- Update Pauli Twirling user guide
- Organize tutorials HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mitiq.