Skip to content

Commit 40bbd50

Browse files
committed
Done the instruction for the first part of the assignment
1 parent d3ada89 commit 40bbd50

File tree

1 file changed

+60
-1
lines changed

1 file changed

+60
-1
lines changed

readme.md

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,71 @@ def eliminate_equivalents(
239239
> - **Important**: use `yield` instead of returning a list. This way, the synthesizer can stop early if it finds a successful program before exhausting the search space.
240240
> - The `cache` is your friend: store previously computed outputs there to save time when the same program shows up again.
241241
242+
242243
### 🔨 Part 1(c). Bottom-up Synthesizing Shapes
243244

244-
Now is the time to take all that we have already and iteratively synthesize shapes.
245+
Now it’s time to put everything together! You’ve implemented **growing** shapes and **eliminating duplicates**—the final step is to iteratively **synthesize a shape that matches all the examples**.
246+
247+
Head to the function `synthesize()` in `BottomUpSynthesizer` under the file `enumerative_synthesis.py`:
248+
249+
```python
250+
def synthesize(self, examples: List[Any], max_iterations: int = 5) -> T:
251+
```
252+
253+
The **bottom-up synthesis loop** works like this:
254+
255+
1. **Start with terminals**
256+
257+
* Generate the set of all terminal programs (`generate_terminals()`) and store them.
258+
259+
2. **Iterate up to `max_iterations` times**:
260+
261+
* **Grow**: expand the program set one level deeper using `grow()`.
262+
* **Eliminate equivalents**: prune duplicates with `eliminate_equivalents()`.
263+
* **Check for success**: after pruning, see if any program satisfies all examples using `is_correct()`.
264+
* If yes → 🎉 return that program immediately.
265+
* Otherwise → continue expanding.
245266

267+
If no solution is found after `max_iterations`, you may `raise ValueError` (which is already provided).
246268

269+
> 💡 Hints & Tips
270+
>
271+
> * Use the helper functions! Don’t reinvent wheels—`generate_terminals`, `grow`, `eliminate_equivalents`, and `is_correct` are there to help.
272+
> * Manage your **cache** carefully—without caching signatures, performance will tank as you repeatedly re-evaluate the same programs.
273+
> * When calling `eliminate_equivalents`, remember that the **test inputs** are just the `(x, y)` coordinates from the examples.
274+
275+
### 🎁 Wrapping Up Part 1
276+
277+
Once you’ve implemented all three core functions:
278+
279+
* `grow()` in `shape_synthesizer.py`
280+
* `eliminate_equivalents()` in `enumerative_synthesis.py`
281+
* `synthesize()` in `enumerative_synthesis.py`
282+
283+
…it’s time to test your synthesizer:
284+
285+
```bash
286+
python test_part1.py
287+
```
288+
289+
If all goes well, you’ll see your synthesizer solving the test cases one by one.
290+
291+
For reference, our solution takes about **30 seconds** to pass all test cases on a MacBook Pro with an Apple M1 Pro chip and Python 3.13.0:
292+
293+
```bash
294+
(.venv) ziyang@macbookpro assignment-1> python --version
295+
Python 3.13.0
296+
(.venv) ziyang@macbookpro assignment-1> time python test_part1.py
297+
...
298+
Testing: random_test_10
299+
✅ random_test_10: PASSED
300+
________________________________________________________
301+
Executed in 28.47 secs fish external
302+
usr time 27.63 secs 169.00 micros 27.63 secs
303+
sys time 0.59 secs 748.00 micros 0.59 secs
304+
```
247305

306+
✨ Congratulations—you’ve just built your first **bottom-up program synthesizer**!
248307

249308
# Part 2: Bottom-up Synthesis for Strings
250309

0 commit comments

Comments
 (0)