You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TensorCircuit-NG supports symbolic circuit simulation via ``tc.SymbolCircuit`` and SymPy.
748
+
This allows developers to build circuits with symbolic parameters, derive closed-form algebraic expressions for quantum states, expectation values, or amplitudes, and then lambdify or compile them for fast execution on various backends.
749
+
750
+
**Basic Usage**
751
+
752
+
To build a symbolic circuit, we can instantiate ``tc.SymbolCircuit`` and define symbols using SymPy:
753
+
754
+
.. code-block:: python
755
+
756
+
import sympy
757
+
import tensorcircuit as tc
758
+
759
+
# Define symbolic parameters
760
+
theta = sympy.Symbol("theta", real=True)
761
+
phi = sympy.Symbol("phi", real=True)
762
+
763
+
# Create a symbolic circuit
764
+
sc = tc.SymbolCircuit(2)
765
+
sc.h(0)
766
+
sc.rx(0, theta=theta)
767
+
sc.ry(1, theta=phi)
768
+
sc.cnot(0, 1)
769
+
770
+
# Retrieve free symbols
771
+
print(sc.free_symbols()) # {theta, phi}
772
+
773
+
**Evaluating Symbolic Expectation Values**
774
+
775
+
We can evaluate symbolic expectation values, which returns algebraic SymPy expressions:
776
+
777
+
.. code-block:: python
778
+
779
+
# Obtain symbolic expectation value of Z_0
780
+
exp_z0 = sc.expectation_ps(z=[0])
781
+
print(exp_z0) # Algebraic expression in terms of theta
782
+
783
+
**Converting to a Concrete Circuit**
784
+
785
+
To evaluate the circuit at specific parameter values, we can map the symbols to concrete numerical values and convert it to a regular ``tc.Circuit``:
786
+
787
+
.. code-block:: python
788
+
789
+
# Bind concrete values to symbols
790
+
c = sc.to_circuit({theta: 0.5, phi: 0.1})
791
+
792
+
# Evaluate the concrete state or expectation values
793
+
print(c.state())
794
+
print(c.expectation_ps(z=[0]))
795
+
796
+
**Qiskit Parameterized Circuit Translation**
797
+
798
+
We can translate a ``SymbolCircuit`` into a Qiskit ``QuantumCircuit``, which preserves Qiskit ``Parameter`` objects for further analysis or hardware deployment:
We can convert symbolic expressions to highly optimized backend-native functions (like JAX) using ``sympy.lambdify``, which can then be composed with ``jit``, ``grad``, or ``vmap``:
809
+
810
+
.. code-block:: python
811
+
812
+
import sympy
813
+
import jax.numpy as jnp
814
+
import tensorcircuit as tc
815
+
816
+
tc.set_backend("jax")
817
+
818
+
theta = sympy.Symbol("theta", real=True)
819
+
sc = tc.SymbolCircuit(1)
820
+
sc.rx(0, theta=theta)
821
+
exp = sc.expectation_ps(z=[0])
822
+
823
+
# Convert SymPy expression to JAX-compatible function
824
+
# Note: Use modules=[jnp, "math"] instead of string "jax.numpy"
For an end-to-end example implementing symbolic QAOA, please refer to the script `qaoa_symbolic.py <https://github.com/tensorcircuit/tensorcircuit-ng/blob/master/examples/qaoa_symbolic.py>`_.
Copy file name to clipboardExpand all lines: docs/source/agentic.rst
+19Lines changed: 19 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -69,6 +69,25 @@ Recommended Workflow
69
69
70
70
By integrating extreme performance with an autonomous, intent-driven AI workflow, TensorCircuit-NG empowers researchers to transition from manual coding to automated scientific discovery.
71
71
72
+
Initial Prompt for Empty Workspace Setup
73
+
----------------------------------------
74
+
75
+
When starting in a completely empty folder/workspace with an AI agent, you can copy and paste the following initial prompt to bootstrap the agent.
76
+
This instructs the agent to clone the repository, read coding guidelines/skills, and execute tasks accordingly:
77
+
78
+
.. code-block:: markdown
79
+
80
+
You are an AI coding assistant. Please follow these steps to set up our project workspace and solve my requests:
81
+
82
+
1. Run `git clone https://github.com/tensorcircuit/tensorcircuit-ng.git .` to download the repository in this empty folder.
83
+
2. Read `AGENTS.md` at the root of the repository to understand the coding standards.
84
+
3. Review the available agentic workflow scripts and skill files under `.agents/skills/` to see if a specialized workflow is suitable for the current task.
85
+
4. Reference existing implementations in `examples/` and test cases in `tests/` to write differentiable, and JIT-friendly code.
86
+
5. Respond to my later requests, write code, and execute experiments/tests to analyse the results.
87
+
88
+
Let me know when the initialization is complete and ask for my requests.
0 commit comments