diff --git a/README.md b/README.md index 9a11c68..90e1244 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,8 @@ python -m pygridsynth [options] ### Options -- `--dps`: Sets the calculation precision (default: `128`). +- `--dps`: Sets the working precision of the calculation. If `--dps` is not given, then the working precision will + be calculated from `epsilon`. - `--dtimeout`, `-dt`: Sets the timeout for solving diophantine equations in milliseconds (default: `200`). - `--ftimeout`, `-ft`: Sets the timeout for factorization in milliseconds (default: `50`). - `--verbose`, `-v`: Enables detailed output. @@ -50,7 +51,7 @@ python -m pygridsynth [options] ### Example Execution ```bash -python -m pygridsynth 0.5 1e-50 --dps 256 --verbose --time +python -m pygridsynth 0.5 1e-50 --verbose --time ``` This command will: @@ -89,4 +90,4 @@ This project is licensed under the GNU General Public License v3 or later. - Neil J. Ross and Peter Selinger. Optimal ancilla-free Clifford+T approximation of z-rotations, 2016. - Peter Selinger. Efficient Clifford+T approximation of single-qubit operators, 2014. - Peter Selinger and Neil J. Ross. Exact and approximate synthesis of quantum circuits. https://www.mathstat.dal.ca/~selinger/newsynth/, 2018. -- Vadym Kliuchnikov, Dmitri Maslov, and Michele Mosca. Fast and efficient exact synthesis of single qubit unitaries generated by Clifford and T gates, 2013. \ No newline at end of file +- Vadym Kliuchnikov, Dmitri Maslov, and Michele Mosca. Fast and efficient exact synthesis of single qubit unitaries generated by Clifford and T gates, 2013. diff --git a/pygridsynth/__main__.py b/pygridsynth/__main__.py index 0995c75..ce1168b 100644 --- a/pygridsynth/__main__.py +++ b/pygridsynth/__main__.py @@ -9,7 +9,7 @@ def main(): parser.add_argument('theta', type=str) parser.add_argument('epsilon', type=str) - parser.add_argument('--dps', type=int, default=128) + parser.add_argument('--dps', type=int, default=None) parser.add_argument('--dtimeout', '-dt', type=int, default=200) parser.add_argument('--ftimeout', '-ft', type=int, default=50) parser.add_argument('--verbose', '-v', action='store_true') @@ -17,10 +17,15 @@ def main(): parser.add_argument('--showgraph', '-g', action='store_true') args = parser.parse_args() + epsilon1 = mpmath.mpmathify(args.epsilon) + dps_of_result = -mpmath.log10(epsilon1) + # Use the same heuristic as Haskell gridsynth for setting dps + if args.dps is None: + args.dps = 15 + 2.5 * dps_of_result mpmath.mp.dps = args.dps + epsilon = mpmath.mpmathify(f"{args.epsilon}") mpmath.mp.pretty = True - theta = mpmath.mpmathify(args.theta) - epsilon = mpmath.mpmathify(args.epsilon) + theta = mpmath.mpmathify(f"{args.theta}") gates = gridsynth_gates(theta=theta, epsilon=epsilon, verbose=args.verbose, measure_time=args.time,