acqdp icon indicating copy to clipboard operation
acqdp copied to clipboard

No documentation for "circuit_file" in example

Open zhoupingjay opened this issue 4 years ago • 6 comments

The "circuit_simulation" example expects an input "circuit_file", but there is no documentation about how to construct this file. Could you please add some document and/or samples for this?

zhoupingjay avatar Dec 31 '20 20:12 zhoupingjay

The circuit simulation example reads an input file in the "qsim format" described in https://github.com/quantumlib/qsim/blob/master/docs/input_format.md, although we haven't implemented all those gates, but only h, cz, t, x_1_2, y_1_2, hz_1_2, is, rz, and fs.

We call this format the "GRCS format" because it is the same circuit format used in https://github.com/sboixo/GRCS. It also appears in the public dataset of the Nature paper by Google that claims quantum supremacy.

Maybe we should add a docstring for the GRCS function that explains this file format.

fangzh-umich avatar Jan 06 '21 02:01 fangzh-umich

Hi, I tried writing a simplest circuit using the "qsim" format:

1
0 x 0
1 h 0

It only contains one qubit, using one X gate and one H gate. I then ran the circuit with circuit_simulation example:

python3 examples/circuit_simulation.py hello_acqdp.txt

But I got error from the example:

Traceback (most recent call last):
  File "/Users/zhouping/GitHub/acqdp/examples/circuit_simulation.py", line 122, in <module>
    c = GRCS(args.circuit_file, simplify=False)
  File "/Users/zhouping/GitHub/acqdp/examples/circuit_simulation.py", line 67, in GRCS
    int(x) for x in words[2:2 + size_table[words[1].lower()]])
KeyError: 'x'

zhoupingjay avatar Jan 11 '21 02:01 zhoupingjay

A relative comment: The qsim format is deprecated. Is it possible to import circuit from Cirq's JSON format?

zhoupingjay avatar Jan 11 '21 02:01 zhoupingjay

Another related question: How do I add measurements to the circuit, e.g. something like what I did this notebook: https://github.com/zhoupingjay/quantum/blob/main/2-bit-Deutsch-Problem.ipynb

circuit.append([cirq.measure(q0), cirq.measure(q1)],
                  strategy=cirq.InsertStrategy.NEW_THEN_INLINE)

zhoupingjay avatar Jan 11 '21 02:01 zhoupingjay

As mentioned above, we did not implement all the gates supported by the "qsim" format, but only the ones used in Google's random circuits. The GRCS function is intended as a demonstration of how one could convert other circuit formats to our format, not a fully functional converter.

Maybe we could try to implement importing circuits from Cirq's JSON format if you could link to a complete format specification.

fangzh-umich avatar Jan 11 '21 05:01 fangzh-umich

Measurements are a bit complicated. If you want to calculate the amplitude (or the probability) of a specific measurement result, you can use ZeroMeas or OneMeas. If you want to calculate the amplitude for all (computational basis) measurement results, you should just omit the measurement at all: The way the conversion from circuits to tensor networks work, all "open" qubits are implicitly "measured" in the computational basis. Other scenarios may require more creative solutions; see our QEC demo for some examples.

fangzh-umich avatar Jan 11 '21 05:01 fangzh-umich