Design of quantum optical experiments with logic artificial intelligence

Logic Artificial Intelligence (AI) is a subfield of AI where variables can take two defined arguments, True or False, and are arranged in clauses that follow the rules of formal logic. Several problems that span from physical systems to mathematical conjectures can be encoded into these clauses and solved by checking their satisfiability (SAT). In contrast to machine learning approaches where the results can be approximations or local minima, Logic AI delivers formal and mathematically exact solutions to those problems. In this work, we propose the use of logic AI for the design of optical quantum experiments. We show how to map into a SAT problem the experimental preparation of an arbitrary quantum state and propose a logic-based algorithm, called Klaus, to find an interpretable representation of the photonic setup that generates it. We compare the performance of Klaus with the state-of-the-art algorithm for this purpose based on continuous optimization. We also combine both logic and numeric strategies to find that the use of logic AI significantly improves the resolution of this problem, paving the path to developing more formal-based approaches in the context of quantum physics experiments.


Introduction
The emergence of artificial intelligence (AI) has led to the proposal of alternative ways to tackle hard non-analytical problems. The AI canonical approach comes in the form of inductive generalizations through the use of big data, the wellknown and established machine learning (ML) field. Although ML grounds rely on mathematical theorems related to continuous function representation, its probabilistic nature usually does not yield performance guarantees, even less understanding about why it works (or not) in a particular problem. Despite the progress in unraveling the learning paths of ML algorithms, ML sibling, logic AI [1,2,3], has the intrinsic potential of providing the validity and consistency of the answers we seek.
Logic AI is a subfield of AI that uses symbolic representation in the form of Boolean variables to extract formal deductions. In its basic form, it consists of encoding a set of rules into Boolean instances which validity can be checked with, for instance, satisfiability (SAT) solvers. The recent advances in SAT solvers have allowed the automatic resolution of extremely complex problems involving thousands of variables [4]. Long-standing conjectures such as the Boolean Pythagorean triples problem [5], the Keller's conjecture (unresolved for 90 years) [6], among others [7,8,9] have been solved using logic AI providing, in some cases, intricate, long [10] but correct deduction steps.
In a quantum mechanical context, the use of logic AI has been slightly explored so far. A few examples propose a logic encoding and a SAT solver as an equivalent quantum circuit checker [11], to find the mapping between a quantum circuit and a particular chip topology [12] or to reduce the gate count [13]. There are also works that find Boolean representations of quantum circuits [14]. These proposals use logic as a checker or optimizer. Here, we exploit logic AI for the design of quantum experiments.
In this work, we propose a logic-based algorithm capable of designing a realistic quantum experiment. To be precise, our goal is to find a feasible photonic setup that generates an arbitrary quantum state. We benchmark our approach by comparing its performance with the best algorithm up to date, which is based on continuous numerical optimization, Theseus [15]. To that aim, we will take advantage of the graphtheoretical representation that these setups can take, which can also be used for other quantum experiments such as gate-based quantum circuits, unitary operations generation or to design quantum error corrected photonic circuits [16].
The structure of this paper is as follows. In the next section, we summarize the graph representation of optical setups and explain how to formulate a state preparation problem. In section 3, we show how to map the design problem into a set of propositional logic clauses. Section 4 introduces the main algorithm, Klaus, that uses the logical instances presented in the previous section to find the minimal graph that corresponds to the optimal setup. In 5, we benchmark Klaus and compare it with both the state-of-the-art algorithm Theseus and a hybrid algorithm proposal. Finally, we conclude and point to numerous exciting extensions of logical AI in quantum physics.

Graph-based representation for quantum optics
A few years ago, a previously hidden bridge between quantum optical experiments and graph theory was discovered [18,19,20] and has since been generalized as a highly efficient automated design algorithm for new quantum experiments [21]. The underlying principle is that every quantum experiment can be described by an edgecolored weighted graph, and every graph stands for a quantum optical setup. In particular, every vertex of these graphs stands for a photon path (or a detector), every edge stands for a correlated photon path, the color represents the mode number and the complex edge weight stands for the amplitude of the photon pair. Such graphs can represent quantum states generated and transformed using linear optics, non-linear pair creation crystals, heralding and auxiliary photons, single-photon sources, photon number (non-)resolving detectors and others.
The quantum state emerging from the experimental setup can directly be computed from the properties of the graph. A very commonly used technique in quantum optics conditions is the experimental result on the simultaneous detection of exactly one photon in each of the detectors [22]. In the graph, this situation corresponds to a subset of edges that contain every vertex exactly once. This property of a graph is called a perfect matching (PM). The final quantum state under this condition is then a coherent superposition of all PMs in the graph. A more detailed analysis of the equivalence between graph PMs and quantum states is presented in App. B.
Given one of these graph representations, it will contain one or more PMs, each of them composed of different subsets of edges of different colors. As stated above, each of these edges represents a photon pair creation in the path (represented by the vertices) that they join. Each of these photons will have a mode represented by the color of the edge. This leads to the inherited vertex coloring of the PM, i.e. we assign a color to each vertex corresponding to the color of the incident edge. The vertex coloring determines the basis element created in superposition with the other PMs vertex colorings. The amplitude of the basis element is determined by the weight of the PM, i.e. the product of the weights of the edges. Different PMs can lead to the same vertex coloring but not necessarily the same PM weight. Thus, to compute the total amplitude of the basis element generated, one needs to sum all PM weights that generate that element, i.e. to compute the weight of the vertex coloring. Since these weights can take complex values, they can cancel each other, thus having a set of PM with a given vertex coloring does not directly imply that the corresponding basis element is generated, as this interference may occur.
Let's illustrate how can we set the quantum state preparation problem using an example of these graph representations. The formal defini-a) Basis state generated: |000011 , vertex coloring: ab w 00 cd w 11 ef + w 00 ac w 00 bd w 11 ef + w 00 ad w 00 bc w 11 ef = 0 b) Basis state generated: |000000 , vertex coloring: w 00 ab w 00 cd w 00 ef + w 00 ac w 00 bd w 00 ef + w 00 ad w 00 bc w 00 ef + · · · = 0 c) Basis state generated: |001122 , vertex coloring: w 00 ae w 11 bd w 22 cf + w 01 ab w 22 cf w 10 de + w 01 ad w 10 be w 22 cf + · · · = 0 1 Figure 1: PMs equations examples for the generation of the GHZ(6, 3) state. a) Two-colored PMs like the ones that generate the basis state |000011 can be canceled with each other by adjusting the weights of the edges. There are three PMs for each two-colored combination assuming monocolored edges. b) To generate the basis state |000000 one needs to obtain a non-zero solution of the equation that sums the 15 PMs that generate that basis element. c) For monocolored edges, the three-colored PMs are unique, which imposes that they must be zero. This imposes a very strong constraint that we will exploit later on for the logic encoding. d) However, if we assume bicolored edges, there are 15 PMs for each color combination, including the three-colored ones. Thus it reduces the strength of the previous constraint. From these graphs, we can construct the photonic experimental setup following the mapping proposed in Ref. [17]. For instance, each edge corresponds to an SPDC that generates a photon pair with the corresponding mode (color) in each path (letter).
tions of this problem are provided in App. C.
To generate a particular state, the weights of each vertex coloring that correspond to the basis states must match the state amplitudes, and the rest of the vertex coloring weights must be zero. Imagine that our goal is to generate the GHZ state of n = 6 parties and d = 3 dimensions, i.e., there are three possible different colors available (the 0, 1, and 2 modes). This state has three basis elements, each with amplitude 1/ √ 3: (1) The general goal is the following: at least one of the contributions for the three basis elements must exist in the graph, while all other terms should vanish. Fig.1a shows an example of a cancellation that must take place to cancel the generation of the basis state |000011 , not present in the GHZ state. Fig.1b, on the other hand, shows that the combination of PM with a unique coloring (in the figure, red) must be different from zero, in particular, it should be 1/ √ 3. Notice that if we only assume monochromatic edges, there is only one PM for each tri-colored vertex coloring and, thus, the only possible solution is forcing this PM to be zero (Fig.1c). However, if we allow bichromatic edges, there could be more tri-colored PM, allowing cancellations as in the bi-colored cases (Fig.1d).
A mathematical conjecture has been proposed that states physically that it is not possible to generate a high-dimensional GHZ state with 6 or more photons with perfect quality and finite count rates without additional resources (such as auxiliary photons). Mathematically, this is equivalent to the question of whether there exists a weighted graph with at least three different vertex colorings of one color each [23,24], e.g. for n = 6 a graph with PMs with all paths either blue, green or red and any other vertex coloring canceled out. The special case for positive weights was solved in 2017 by Ilya Bogdanov [25,18], but the case for negative and complex weights is open and contains the exciting possibility of using intricate quantum interference effects as a resource in quantum state preparation and transformation in quantum optics. The question can be translated into a set of d n coupled nonlinear equations with n(n−1) 2 d 2 complex variables [26]. The algebraic question is whether there exist solutions to this equation system for n ≥ 6 and d ≥ 3 and complex finite weights. The conjecture reduces to the simple statement that the equation system has no solution.
The emergence of obstructions such as the one shown in Fig.1c suggests that combinatorics may play an important role in the generation of quantum states using this methodology. It is precisely the combinatorial nature of this problem that we will exploit with the help of a logic-based algorithm.

Logic and SAT
In a Boolean algebra, the variables, called literals, can take two Boolean values: True-False or 0-1. The available operations on these literals are disjunctions ∨ (OR), conjunctions ∧ (AND) and negationsx (¬ or NOT). Given a Boolean formula, the satisfiability (SAT) problem consist of finding a literals assignment that satisfies it, i.e. outputs True or 1.
In the following subsections, we will encode the state preparation problem described in the previous section into a set of Boolean expressions whose satisfiability will give us a solution to the problem.

Logic encoding
We will explore the combinatorial nature of this graph problem to construct a set of logical clauses that can deliver a definite solution.
In this problem, the literals will be each of the edges of the graph e αβ ij , where (i, j) are the vertices joined by the edge (with i < j) and (α, β) are the inherited modes of the vertices, respectively. They will take the value True if they are present and False if they do not. Notice that we do not take into account that each edge can have a complex weight and thus there can be cancellations between PMs with the same vertex coloring. Even though we do not encode the entire information and possibilities of the graph, we still get highly complex and powerful obstructions that we can use constructively in conjunction with SAT solvers. This is by no means a restriction of representation. Negative and complex numbers can be represented by boolean variables effortlessly. As a simple example, we introduce another bit representing the sign of the number s and the value bit v, such that numbers −1, 0, 1 for 11 b , 00 b , 01. All boolean operations can be adjusted accordingly. Of course, in this way, we can also introduce more complex number systems such as fractions or complex numbers, but this is out of the scope of the current manuscript.
The logic clause to define a graph PM consist of replacing the PM weights by their corresponding (Boolean) edges and the products of the weights by ∧. If one of the edges is False (there is no edge), the clause is False, and, therefore, we do not have that PM. The formal derivation of these clauses is presented in App.D. In the following paragraphs, we will show how this logic works using examples.
Let's start with a four-vertex graph example with six edges with the same color (mode 0) {e 00 ab , e 00 cd , e 00 ac , e 00 bd , e 00 ad , e 00 bc }. The logic clause that states the existence of the three PM P 1 , P 2 and where (0, 0, 0, 0) represents the inherited vertex coloring (all photons are in mode 0). If only one of the edges in these PMs is False, that PM does not exist.
We require that at least one PM exist for each vertex coloring that appears in the target state. Following the previous example, if the state |0000 appears in the target state, then at least one of the previous PMs must be True: The above clause evaluates to True if at least one of the subclauses b is True.
If there are other basis elements in the target state, then all clauses of the form of B must evaluate to True. An example is shown in the top part of Fig.2. The target state is the GHZ state of n = 4 and d = 2. There are two vertex colorings in the target state, the one corresponding to the |0000 basis element and the |1111 element, where the |0 and |1 states are represented in red and blue colors, respectively. Each PM is composed by two edges and, assuming the full-connected graph, there are three possible combinations: Since we want to generate a monocolored basis state, all edges have the same color on both ends. To obtain the two basis elements, at least one of the blue PMs and one of ab ∧ e 11 cd ∨ e 11 ad ∧ e 11 bc ∨ e 11 ac ∧ e 11 bd ∧ e 00 ab ∧ e 00 cd ∨ e 00 ad ∧ e 00 bc ∨ e 00 ac ∧ e 00  These weights also carry another degree of freedom, the color, which has as many dimensions d as the state. The bar on top of a Boolean variable or expression corresponds to the negation of its value. Each PM is composed by the conjunction (∧) of all edges that compose it, so all edges must evaluate to True to have that PM. For those basis elements that appear in the target state, the logic instance corresponds to the disjunction (∨) of all PMs; to evaluate to True, at least one of the PMs must exist, i.e. evaluate to True. This logic is represented in the top part of the figure, where the total expression must evaluate to True to obtain the superposition |0000 + |1111 . For those basis elements that are not in the target state, we can construct some obstructions. If all PMs except one evaluates to False, the remaining one has to be False as well. Other cases, like only one of them being False, can allow interference between the True PMs, a property not encoded in the logic. In the example (bottom part of the figure), the state |0011 must not appear, so the total expression must evaluate to True, as its negation will be added to the total set of clauses to be evaluated by the SAT solver.
the red PMs have to evaluate to True. This is represented with the clause The remaining vertex colorings that do not appear in the target state must be False. However, as we mentioned before, the existence of more than one PM with a given coloring might be possible since there could induce a cancellation between the weighted PMs. The logic encoding that we propose cannot encode these cancellations, but we can include extreme cases independent of the weight values. We can have all PMs of a particular coloring and still obtain a cancellation between them, but if all PMs except one do not exist (they are False), the remaining one cannot exist either (should be False as well) because it cannot be canceled with anyone else. Figure 2 bottom shows the clause for those PMs that generate the basis element |0011 , which does not appear in the GHZ state.
Let's analyze it piece by piece. The first part of the clause reads If the three PMs exist (are True), this expression is True. If only two of them are True, the expression is still True. These two cases illustrate the fact that there could be cancellations between the PMs, so keeping them can be a solution once we search for the weights. If the first two PMs are False, the third one has to be False as well in order to keep the expression True. We must add the other two possibilities, i.e. that the other pairs of PMs are False, so the remaining one is forced to be False as well. This is why, the total clause shown in Fig. 2 bottom contains three subclauses, to account for the permutations of PMs.
Altogether, the global set of clauses that encode the possible solutions for the generation of a particular state using graph PMs is a conjunction of clauses of type S, the ones that guarantee the existence of at least one PM for each target state basis element, and clauses of type C, a set of constraints on the PMs that should not appear in the final graph: Given a set of edges, if K =False we can con-clude it is not possible to obtain the target state. However, K =True does not guarantee the generation of this state due to the possible interference between PMs is not encoded in the clauses. For this reason, solutions such as the complete graph (all possible edges are True) output K =True, although heuristic optimization algorithms such as Theseus [15] show that some states are not representable by graphs. For this reason, we mix these optimization strategies with Klaus to obtain and guarantee physical and interpretable solutions.

Monochromatic edge obstructions
The logical clauses presented in the previous section are general for both monochromatic and bichromatic edges. However, for graphs with only monochromatic edges, the problem simplifies substantially as the number of possible vertex coloring is much more constrained, therefore the logical approach is more powerful. One example is the one shown in Fig.1c, where for the case of n = 6 vertices tricolored vertex colorings are formed with unique PM. The same argument extends to more than three colors. In general, for a graph of n vertices and monochromatic edges, vertex colorings composed by d = n/2 colors are unique. This fact implies that the condition of these vertex colorings is composed of a single clause: either that PM is True (if that coloring appears in the target state) or is False (if it does not). In the first case, it fixes the "trueness" of all edges that form that PM. In the second case, it imposes that at least one of the edges must be zero. In either case, it could trigger a chain reaction on the rest of the clauses. We test this approach to check if there exists a graph with monochromatic edges that generate the GHZ state of n > 4 parties and d ≥ n/2 local dimensions. We check if the set of clauses K from Eq.(6) is satisfiable, i.e. if there exists a solution for the literals that evaluates to True. We use the SAT solver from Mathematica language (which corresponds to MiniSAT in Mathematica 11). We obtained K =False for n up to 8 and d = n/2 colors. For bigger systems, the amount of RAM required was out of range for our current computational capabilities. With these results we formulate the following conjecture to be added to other graph edge coloring conjectures such as the ones presented in Ref. [24]: Conjecture. It is not possible to generate a graph G with n > 4 vertices and monochromatic edges each with one of d ≥ n/2 possible colors, such that it contains single-colored PMs for each of these d colors while no PMs with other vertex colorings are generated (or the amount of these PMs does not allow cancellations).
In the language of quantum state generation with photonic setups: it is not possible to generate exactly a GHZ state of n > 4 parties and d ≥ n/2 dimensions (and n = 4 and d > 3) using this graph approach without additional quantum resources (such as auxiliary photons).

Klaus algorithm
SAT solvers look for a solution that is satisfiable no matter the number of True literals that it includes (looking for a particular solution will take exponential time), thus some of the solutions obtained may be cumbersome to interpret by humans. For instance, high-dense graphs with many True edges are allowed solutions of K making it difficult to map them into a physical setup or to interpret the result to gain some understanding of how these states are physically generated. Moreover, the logic clauses do not provide the weights of the graph that generate the correct state amplitudes, so we need at least one extra step in our algorithm to compute these weights. We propose a heuristic algorithm based on propositional logic named Klaus that aims to find a simplification of the satisfiable solutions of the logical clauses K and to find the state amplitudes of the generated state. Figure 3 shows the schematic representation of the Klaus algorithm. It starts with the fully connected graph, randomly selects one edge, and sets it to False. Then, it checks if K is satisfiable using a SAT solver. If K =True, it means that edge was unnecessary to achieve the target state, so it "deletes" it, i.e., sets it to False permanently. If K =False, it means the edge was indispensable to generating the state, so it has to be True. The process is repeated by selecting randomly another edge, assigning it to False, and checking again if K is satisfiable. The loop continues until all edges are checked and set to False (deleted) or True (kept). We end up with a much-reduced list of edges that, according to K, can generate the target state. However, we still   (6)) is satisfiable using a SAT solver. If the SAT solver outputs True, the edge selected is apparently not required to generate the target state, so we can delete it, i.e., set it to False permanently. On the other side, if SAT is False, it means that an edge is required to generate the state, so it has to be True. The algorithm repeats the process of picking the other edges until all of them are classified as False or True. As a result, we obtain a significantly sparsed graph. The final step consists of obtaining the graph weights that generate the required amplitudes to obtain the target state. This is done by numerically minimizing the infidelity of the graph obtained when replacing the edges with their corresponding weights.
need to check if the final solution can generate the state by finding the corresponding weights. The last step of the Klaus algorithm consists of minimizing the infidelity of the resulting graph to find the weights of its edges.
Many possible solutions may satisfy the K clauses. Moreover, the smallest the graph, the faster the SAT solver, which accelerates the algorithm as it evolves. We can completely trust the logical clauses if they evaluate to False (implying that it is impossible to generate the state with that set of edges). However, the True solutions must still pass the possible interference test between the surviving PMs with the same vertex coloring. It could be the case that a final solution output by Klaus cannot generate the target state because the requiring cancellations cannot occur. This is because all graph PMs constitute a highly coupled system of equations. In some cases, some edges turned out to be indispensable once we minimize the infidelity, so if Klaus has deleted them, then it is not possible to generate the state afterward. In our benchmarks (pre-sented in the next section), we found these cases to be unlikely but they open the path to better understanding the combinatorial nature of this problem and to finding new obstruction clauses to include in our logic instances. We leave the investigation of these constraints for future work.

Benchmarks
We test and compare the Klaus algorithm with Theseus [15], a purely numerical strategy, to find the minimal graphs that generate a given state. Theseus starts with the fully connected graph and minimizes the infidelity with respect to the target state. In the original proposal, after this minimization, it selects the smallest weight, deletes it (i.e., sets it to zero), and repeats the minimization process until no more weights can be deleted without compromising the infidelity. We found that this approach can be improved significantly by deleting more than one edge at once. In particular, after each minimization, we delete all edges with weights smaller than a certain threshold.
Although this improved version of Theseus is much faster than the original one, it is not sensitive to those cases where only a subset of weights with similar values can be deleted. Therefore, there is no way to certify that more edges can be removed than trying to delete them one by one, as in the original proposal. Since the goal of these algorithms is to provide a minimal solution, it is necessary to include a final step in Theseus that checks if there is an even smaller solution.
We try to certify the minimal solution of Theseus following two strategies. Both strategies check if it is possible to remove more edges by proceeding one by one. The first strategy, which we call Theseus optimization (TheseusOpt), is performed by following the original Theseus approach, i.e., deleting one edge, minimizing the infidelity, and keeping it if it gets compromised or deleting it definitively otherwise. In the second strategy, called Klaus optimization (KlausOpt), we use Klaus instead, i.e., checking if K is still satisfiable when we delete one by one the remaining edges and minimizing the infidelity only at the very end of the algorithm.
We start our benchmarks by checking the performance of these four algorithms (Klaus, Theseus, TheseusOpt, and KlausOpt) with the generation of target states from which we know there exists a graph [20]. We check the computational time that they need and the number of edges of the solution. Since all these algorithms have a heuristic component (the selection of random edges to delete), we run them 25 independent times for each target state to obtain an average performance.
The test states have different entanglement properties quantified by the Schmidt Rank Vector (SRV) [27], a different number of parties n, and a different number of basis elements. In particular, we look for the graphs for the GHZ(n,d) states GHZ(4,3) and GHZ (6,2), and states with SRV equal to (5,4,4), (6,4,4), (6,5,4) and (9,5,5). The wave functions of these states are written explicitly in App. E. The SRV states are composed of three parties. Thus, we will find the graphs of the heralded state, in particular |ψ = |ψ |0 , where |ψ is the real target state.
Besides checking if Klaus and Theseus can find states that can be generated from graphs, we also test those states that cannot be exactly constructed this way. These states will be the GHZ (6,3) and two states with SRV equal to (5,4,4) and (6,4,4) different from the above ones. For these states, however, we can obtain approximate solutions by setting those forbidden vertex colorings weights close to zero. Notice that these solutions are forbidden by the logic clauses in Klaus, so we expect that Klaus will have more difficulties finding them. Figure 4 shows the average performance and its standard deviation over 25 independent runs of the four algorithms for the aforementioned target states. The plots show the number of edges of the minimal solution, the fidelity with respect to the target state, and the total computational time (on a 2.4 GHz CPU with 16 GB of RAM). Besides the pure algorithmic optimization time, the computational time for Klaus and KlausOpt includes the generation of the logical clauses.
We can appreciate how Klaus is, on average, faster than Theseus for those states with no exact graph solution and comparable in general. Klaus finds the minimal solution for those states that can be represented with graphs. However, for those without a graph representation, Klaus obtains solutions with more edges and worse fidelities. We expect this behavior since the logical instances may forbid the aforementioned approximate solutions that Theseus can find. The sometimes big standard deviations are a consequence of the heuristic nature of these algorithms, specially Theseus when it gets trapped in local minima. In any case, KlausOpt is significantly better than TheseusOpt in terms of the number of edges of the final solution and especially the computational time required, establishing a clear advantage of using the SAT solver instead of multiple numerical minimizations.

Discussion and conclusions
We have shown how logic AI can contribute to the discovery of novel quantum optical setups and experiments. We introduce a Boolean encoding of the graph representation of these setups and present a mapping from the state preparation problem to a k−SAT. With this approach, we can check the conjecture that it is not possible to generate a GHZ state of n parties and d ≥ n/2 dimensions using these experiments. Then, we design a logic-heuristic algorithm, Klaus, which We take a set of target states that can be generated by graphs and some that cannot (indicated with a * in the plot). We compare the number of edges of the minimal graph solution, the fidelity with respect to the target state, and the total computational time. Since all these algorithms are heuristic, we run each of them 25 times and compute the average and standard deviation of their results. On average, Klaus succeeds in both finding the minimal solution and in spending less computational time on average than the other algorithms. However, it fails to find approximate solutions to those states that cannot be generated by graphs. We expect this result from a propositional logic algorithm, where the clauses K will be False for those approximate solutions. KlausOpt algorithm is significantly better than TheseusOpt, showing the advantage of using a hybrid numerical-logical approach in contrast to purely numeric strategies.
starting from the complete graph, finds the minimal representation that corresponds to the gener-ation of the target state. We benchmark Klaus with the state-of-the-art algorithm Theseus [15], based on numerical optimization. Klaus is on average comparable in execution time or faster than Theseus and it finds the minimal graphs for the different test states. We also show how Theseus, a continuous optimization algorithm, can be improved with the assistance of Klaus, a logicbased algorithm.
At the very end, Klaus has to numerically minimize a loss function consisting of the infidelity between the remaining graph and the target state. However, the process of deleting edges from the fully connected graph simplifies that minimization substantially. There are several potential advantages of using Klaus in contrast to fully-numerical approaches such as the Theseus algorithm: i) if K =False we know for sure that the graph cannot be exactly generated, while a non-successful purely numerical minimization may imply that we got trapped in local minima; ii) the final minimization step involves a small subset of weights, increasing the probability of a successful optimization, in contrast with Theseus, where a minimization involving all weights is performed at the very beginning of algorithm; iii) SAT solvers have improved in the last years, becoming a powerful tool in computation that can solve huge problems involving thousands of literals. It makes them a very convenient tool for problems that grow exponentially with the number of parties involved.
The experimental preparation of quantum states is a key feature in the quantum technologies era. Quantum computing paradigms such as measurement-based quantum computation [28] rely on the initial optimal preparation of highly entangled states. Some quantum machine learning algorithms require the encoding of arbitrary data into the amplitudes of a general quantum state [29], including those early proposals that solve a system of linear equations [30]. Besides these state preparation applications, the power of the graph representation introduced in [15] can also be extended to general quantum operations and quantum circuit design that lead to novel ways to construct, for instance, multilevel multiphotonic experiments [31,32], whether integrated [33,34] or in bulk optics [35,33,36]. Although a fully-programmable quantum computer can theoretically prepare any state or perform any unitary operation, not all hardware implementations have direct access to all of the required quantum gates. In this context, providing alternative representations and algorithms based on them will prove valuable in the coming years. Another impactful application of SAT solvers in this context would be the search for limits on success probabilities for quantum state generation or quantum transformations, for instance, those resource states used in quantum computing paradigms such as fusionbased quantum computation [16]. This feat will require handling probabilities (or fractions) suitably as logical clauses.
Although current SAT solvers are extremely efficient and capable of dealing with thousands of literals and clauses, it is worth noting the efforts of quantum and quantum-inspired approaches to solve classical satisfiability problems. In particular, a quantum computing paradigm such as quantum annealing [37,38] is especially suitable to map classical logical clauses into a quantum Hamiltonian and obtain the solution by adiabatically preparing its ground state. Digital quantum computations can also be programmed to prepare these ground states, even in near-term quantum devices [39,40]. Moreover, quantuminspired classical techniques such as tensor networks can also be applied to solve SAT problems [41].
Logic AI, a paradigm proposed in the 50s, is experiencing its expansion in recent years, with the improvements in SAT solvers. Traditionally, it has been mainly used in circuit design, but its applications go beyond that. The increasing interest in understanding concepts such as how a machine learns or how to tackle hard mathematical conjectures has recently promoted this AI subfield. The use of formal reasoning can form fascinating synergies with other approaches. As an example, one can introduce a logic-based piece in a standard ML loss function [42]. Within this work, we present one of the aforementioned synergies by entangling a purely numerical algorithm with a logical one and extend the applicability of logic AI to the design of quantum experiments.

Code availability
The Mathematica notebook with Klaus algorithm can be found at https://github.com/ AlbaCL/Klaus.

Conjunction
x y x ∧ y Disjunctive Normal Form (DNF). Disjunction of clauses formed by conjunction of literals.

Boolean Algebra
Conditioning. Set x =True: removex literals and clauses with x. e.g.
Resolution. Combine clauses with x andx to remove x.
Unit resolution (UR). Unit clauses simplify the expression.
Unit propagation (UP). UR until a literal is removed from all clauses.
Boolean Satisfiability Problem k -clause. Clause (CNF or DNF) formed by k literals.
k -SAT. Is there an assignment of values to the literals such that a Boolean formula composed by k-clauses evaluates to True?

Inefficient
Avoid exploring UNSAT UP to simplify the tree DPLL with causal graphs (O(2 n ) with n literals) branches to find conflicts 1 Figure 5: Opening the logic black box. SAT solvers are extremely sophisticated algorithms capable of dealing with thousands of variables and clauses. They are based on Boolean algebra which variables (called literals) can take two definite values, True-False or 0-1. SAT solvers find the values of these literals that satisfy a Boolean formula (normally written in CNF). If it does not exist a solution, we say the clauses are unsatisfiable (UNSAT). SAT problems are NP-complete, which means it does not exist efficient algorithm that solves them but once the solution is provided, it can be easily verified. However, it is possible to design highly efficient algorithms that go much beyond the naive binary-tree search.

A Boolean algebra and satisfiability
In a Boolean algebra, the variables, called literals, can take two Boolean values: True-False or 0-1. The available operations on these literals are disjunctions ∨ (OR), conjunctions ∧ (AND) and negationsx (¬ or NOT). A Boolean formula includes its literals and the operations between them. It is usually more practical to translate a Boolean formula into one of its canonical forms: conjunctive normal form (CNF) or disjunctive normal form (DNF). A CNF expression is a conjunction of clauses, each composed of a disjunction of literals. Similarly, a DNF expression is the opposite of a CNF, a disjunction of clauses, where each of them is composed by the conjunction of its literals.
Given a Boolean formula, the satisfiability (SAT) problem consist of finding a literals assignment that satisfies it, i.e. outputs True or 1. The complexity of a SAT problem depends on the structure of its canonical forms, CNF or DNF. This is why the first step toward solving a SAT consists of rewriting In any case, we can discard those states containing zero or more than 2 photons since we condition the state on the simultaneous photon detection events in all detectors Let's see how these manipulations can be analyzed using the graph PMs instead of a four-path photonic example.
Take the left graph from Fig.6. It corresponds with two SPDC that create photons in the |0 mode in paths a, b, c and d. The state that arrives at the photon detectors is where we avoided the annihilation operators since they are discarded when acting on the vacuum state.
Since we are interested in those photonic states that involve one photon per path, the surviving term is the |0000 state with amplitude g 2 . Now, let's take the center graph from Fig.6. After the 0-mode SPDC, we apply 1-mode SPDC on the same pairs of paths. As a result: Thus, in those states that contain one photon each, the state generated becomes Finally, let's consider the right graph from Fig.6. The second row of SPDC is applied on different pairs of paths than the first one. Thus: This time, the surviving terms are two. g 2 (|0000 + |1111 ). So, we can draw three conclusions from this analysis: 1. Each graph PM generates a basis element corresponding to the modes (colors) incident to the paths (vertices).
2. The final superposition state corresponds to adding all graph PMs.
3. The edge weight corresponds to some power of the SPDC coupling g. The exponent corresponds to n/2 where n are the total paths.

C Formal definitions of graph representation of optical experiments
Let us formulate the graph-based representation of optical experiments in a more formal way (for a more detailed mathematical description, check Ref. [24]). Given a graph with n vertices and a set of undirected edges E, a perfect matching (PM, in plural PMs) corresponds to a set of edges e ∈ E such that each vertex is matched with exactly one edge. For weighted graphs, i.e., for graphs where each edge has an associated weight w ∈ C, the total weight of a PM corresponds to the product of the weights that forms it. We can add more degrees of freedom by associating another property to the edges: color. We assume that each edge of G contains up to two
colors (bi-chromatic graphs). A bi-chromatic edge with a color pair (α, β) will join two vertices (i, j), giving color α to vertex i and color β to vertex j. Then, each edge contains five properties: the two vertices it joins, the corresponding colors that deliver to each vertex, and its complex weight.
We label each edge with e αβ ij , where (i, j) with i < j are the vertex pair and (α, β) are the corresponding colors. Similarly, the weights of each edge will be labelled as w αβ ij ∈ C. Thus, a PM P and its associated weight w P are defined as where c is the color combination inherited by the vertices. For an example, take the first graph from 1a. The n = 6 graph with edges E = {e 00 ab , e 00 cd , e 11 ef } form one PM P with weight w P (c) = w 00 ab w 00 cd w 11 ef and c = (0, 0, 0, 0, 1, 1). A general graph may contain several PMs. In particular, a complete graph with n vertices contains (2n − 1)!! = (2n − 1)!/(2 n−1 (n − 1)!) PMs. If each edge of the graph has the extra color degrees of freedom, the number of PMs increases to d n (2n − 1)!!, where d is the number of different colors. Therefore, there could be more than one PM with the same inherited vertex coloring, i.e. the same color combination inherited by the vertices from the bi-colored edges that touch them. As explained before, each color vertex combination corresponds to the generation of a basis state. Thus, to obtain the total basis state amplitude, we need to sum up the weights of all PMs that generate it. The weight of a vertex coloring c of a graph is where M is the set of perfect matching of G with the same coloring c and w p are the corresponding PM weights of each P ∈ M. Coming back to the previous example, if we add to the list of edges the edges e 00 ac and e 00 bd , the resultant graph contains E = {e 00 ab , e 00 cd , e 11 ef , e 00 ac , e 00 bd } and thus it generates a second PM, the second one shown in Fig.1a. That PM has the same vertex coloring as the previous one, c = (0, 0, 0, 0, 1, 1). Thus, the weight of that vertex coloring is W (c) = w P (c) = w 00 ab w 00 cd w 11 ef + w 00 ac w 00 bd w 11 ef .

D Logic clauses construction
where e αβ ij are the graph edges (and the Boolean literals), i < j are the graph vertices and c coloring will be defined by the particular colors α and β associated with each edge in canonical order.
We require that at least one PM exist for each vertex coloring that appears in the target state. Thus, the collection of clauses that encode this logical statement becomes where M is the set of PMs with c vertex coloring and B c is False only if all PMs are False, and True otherwise. As required, we need at least one PM with vertex coloring c to generate the state with that coloring. In total, we need that this property is fulfilled for each of the vertex colorings that appear in the target state that we want to generate. Thus, the total logical clause for the target state elements becomes S = c∈C B(c) = c∈C P ∈Mc {i,j}∈P where C is the set of vertex coloring that appear in the target state and M c are the set of PMs for each of these colorings.
To encode the obstructions to those basis elements that do not appear in the target state, we use the following logic: if all PMs except one that generates those basis elements are False, the remaining one has to be False as well. However, other possibilities, e.g. two or more are True, are allowed since there can be cancellations between the weights of these PMs. For each of these forbidden basis elements, we encode this logical statement in the following way: where M are the set of PMs with vertex coloring c. Take a subset of all PMs with the same vertex coloring consisting of all PMs except one. If all PMs of this subset is False, its conjunction will be False. Therefore, to C(c) =True, the remaining PM must evaluate to False as well. For example, imagine we have three PMs with a vertex coloring c that must not appear in the target state, namely P M 1 , P M 2 and P M 3 . If P M 2 = P M 3 =False, then P M 2 ∨ P M 3 =False. As a consequence, P M 1 =False, so P M 1 =True in order to obtain C(c) =True.
Considering all basis elements that do not appear in the target state, the obstruction clause becomes where O is the set of vertex colorings that do not appear in the state. This clause evaluates to True only when all subclauses are fulfilled, i.e. each C(c) =True.
We also try to generate the GHZ(6,3), which we know is not representable by an exact graph, We run the algorithms benchmarks 25 times for each target state and present the average performance in the main article. Figures 7 and 8 show the results of each of these runs.