tensorflow / tensorflow/quantum

[Design] Add ability to reason about Circuit structure

Open
#292 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area/circuits area/cirq help wanted kind/feature-request skill-level/expert
Dominant language
Python
Stars
2.2k
Forks
665
PR merge metrics
No merged PRs in 30d

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the issue's tfq.convert_to_tensor example and the proposed tfq.circuit_structure entry point, then review the serialized Cirq circuit inputs and the suggested gate and symbol alphabets. Done requires an agreed representation for the encoding and params outputs, including how circuit structure, symbols, qubits, and depth are represented.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.