tensorflow/quantum

[Design] Add ability to reason about Circuit structure

Open

#292 opened on Jul 10, 2020

View on GitHub
 (8 comments) (0 reactions) (0 assignees)Python (653 forks)github user discovery
area/circuitsarea/cirqhelp wantedkind/feature-requestskill-level/expert

Repository metrics

Stars
 (2,145 stars)
PR merge metrics
 (PR metrics pending)

Description

It would be a very useful feature to be able to reason about "Circuit structures". Supporting this feature would mean that we would roughly need to be able create an op to do the following:


my_circuit = cirq.Circuit(cirq.H(q0), cirq.CNOT(q0, q1), cirq.Y(q1) ** beta)
circuit_tensor = tfq.convert_to_tensor([my_circuit])
structure_grid = tfq.circuit_structure(circuit_tensor)

print(structure_grid)
# [[...], ...]  some kind of meaningful 2d description of the circuit. 
# Should maybe be something like [batch_size, ragged on n_qubits, ragged on depth, n_channels] 
# Maybe an additional output to track symbols as well ?

My current thinking is that we do something like this: have the following inputs:

(optional) gate_alphabet where gate_alphabet[gate] = a unique integer value
(optional) symbol_alphabet[symbol_name] = a unique integer value different from any in gate_alphabet
circuits[i] = a serialized cirq.Circuit`
symbol_names = a list of all symbols found in all the circuits in circuits

Outputs:

encoding[i][j][k] = gate_alphabet[operation from circuits[i] at moment j at qubit index k] 

params[i][j][k][l] = symbol_alphabet[parameter l from operation from circuits[i] at moment j at qubit index k]
    or the value of l if it isn't a symbol.

What do people think ?

Going to leave open for discussion with @vprusso and others.

Contributor guide