Skip to content

1. Mapping a target state to a generating circuit

In this tutorial, we use the TimeReversedSolver to map from a target quantum state, to a circuit which generates it. Similar to the last tutorial, we use a four-photon linear cluster state as our example state, and will measure the infidelity of the state generated by the discovered circuit. First we import all the relevant classes and dependencies.

from graphiq.backends.stabilizer.compiler import StabilizerCompiler
from graphiq.state import QuantumState
from graphiq.metrics import Infidelity, CircuitDepth
from graphiq.solvers.time_reversed_solver import TimeReversedSolver

import networkx as nx
compiler = StabilizerCompiler()
graph = nx.Graph([(0, 1), (1, 2), (2, 3)])
target = QuantumState(graph, rep_type="graph")
metric = Infidelity(target)

Next, we pass the target, metric, and compiler objects to the solver and call the .solve() function which runs the main mapping algorithm.

solver = TimeReversedSolver(
    target=target,
    metric=metric,
    compiler=compiler,
)
solver.solve()
score, circuit = solver.result
print(f"The fidelity between the target and generated states is {1 - score}")
depth = CircuitDepth()
print(f"Circuit depth is {depth.evaluate(state=None, circuit=circuit)}")
circuit.draw_circuit();
The fidelity between the target and generated states is 1.0
Circuit depth is 9

No description has been provided for this image

We see that the circuit structure is identical to the example shown in the previous tutorial, and correctly generates the target cluster state!